@backstage/plugin-user-settings-backend 0.2.27-next.1 → 0.2.27-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @backstage/plugin-user-settings-backend
|
|
2
2
|
|
|
3
|
+
## 0.2.27-next.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/backend-defaults@0.5.3-next.2
|
|
9
|
+
- @backstage/plugin-auth-node@0.5.4-next.2
|
|
10
|
+
- @backstage/backend-plugin-api@1.0.2-next.2
|
|
11
|
+
- @backstage/config@1.2.0
|
|
12
|
+
- @backstage/errors@1.2.4
|
|
13
|
+
- @backstage/types@1.1.1
|
|
14
|
+
- @backstage/plugin-signals-node@0.1.14-next.2
|
|
15
|
+
- @backstage/plugin-user-settings-common@0.0.1
|
|
16
|
+
|
|
3
17
|
## 0.2.27-next.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/alpha/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseUserSettingsStore.cjs.js","sources":["../../src/database/DatabaseUserSettingsStore.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 resolvePackagePath,\n DatabaseService,\n} from '@backstage/backend-plugin-api';\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: DatabaseService;\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"],"names":["resolvePackagePath","NotFoundError"],"mappings":";;;;;AAyBA,MAAM,aAAgB,GAAAA,mCAAA;AAAA,EACpB,yCAAA;AAAA,EACA
|
|
1
|
+
{"version":3,"file":"DatabaseUserSettingsStore.cjs.js","sources":["../../src/database/DatabaseUserSettingsStore.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 resolvePackagePath,\n DatabaseService,\n} from '@backstage/backend-plugin-api';\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: DatabaseService;\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"],"names":["resolvePackagePath","NotFoundError"],"mappings":";;;;;AAyBA,MAAM,aAAgB,GAAAA,mCAAA;AAAA,EACpB,yCAAA;AAAA,EACA;AACF,CAAA;AAiBO,MAAM,yBAAuD,CAAA;AAAA,EAgB1D,YAA6B,EAAU,EAAA;AAAV,IAAA,IAAA,CAAA,EAAA,GAAA,EAAA;AAAA;AAAW,EAfhD,aAAa,OAAO,OAEmB,EAAA;AACrC,IAAM,MAAA,EAAE,UAAa,GAAA,OAAA;AACrB,IAAM,MAAA,MAAA,GAAS,MAAM,QAAA,CAAS,SAAU,EAAA;AAExC,IAAI,IAAA,CAAC,QAAS,CAAA,UAAA,EAAY,IAAM,EAAA;AAC9B,MAAM,MAAA,MAAA,CAAO,QAAQ,MAAO,CAAA;AAAA,QAC1B,SAAW,EAAA;AAAA,OACZ,CAAA;AAAA;AAGH,IAAO,OAAA,IAAI,0BAA0B,MAAM,CAAA;AAAA;AAC7C,EAIA,MAAM,IAAI,OAIe,EAAA;AACvB,IAAA,MAAM,OAAO,MAAM,IAAA,CAAK,EAAyB,CAAA,eAAe,EAC7D,KAAM,CAAA;AAAA,MACL,iBAAiB,OAAQ,CAAA,aAAA;AAAA,MACzB,QAAQ,OAAQ,CAAA,MAAA;AAAA,MAChB,KAAK,OAAQ,CAAA;A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":"deprecated.cjs.js","sources":["../src/deprecated.ts"],"sourcesContent":["/*\n * Copyright 2024 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 express from 'express';\nimport { DatabaseService } from '@backstage/backend-plugin-api';\nimport { SignalsService } from '@backstage/plugin-signals-node';\n\nimport { createRouter as internalCreateRouter } from './service';\nimport { IdentityApi } from '@backstage/plugin-auth-node';\n\n/**\n * Type for the options passed to the \"createRouter\" function.\n *\n * @public\n * @deprecated This type is only exported for legacy reasons and will be removed in the future.\n */\nexport type RouterOptions = {\n database: DatabaseService;\n identity: IdentityApi;\n signals?: SignalsService;\n};\n\n/**\n * Create the user settings backend routes.\n *\n * @public\n * @deprecated This function is only exported for legacy reasons and will be removed in the future.\n * Please {@link https://backstage.io/docs/backend-system/building-backends/migrating | migrate } to use the new backend system and follow these {@link https://github.com/backstage/backstage/tree/master/plugins/user-settings-backend#new-backend | instructions } to install the user settings backend plugin.\n */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n return await internalCreateRouter(options);\n}\n"],"names":["internalCreateRouter"],"mappings":";;;;AA0CA,eAAsB,aACpB,OACyB,EAAA;AACzB,EAAO,OAAA,MAAMA,oBAAqB,OAAO,CAAA
|
|
1
|
+
{"version":3,"file":"deprecated.cjs.js","sources":["../src/deprecated.ts"],"sourcesContent":["/*\n * Copyright 2024 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 express from 'express';\nimport { DatabaseService } from '@backstage/backend-plugin-api';\nimport { SignalsService } from '@backstage/plugin-signals-node';\n\nimport { createRouter as internalCreateRouter } from './service';\nimport { IdentityApi } from '@backstage/plugin-auth-node';\n\n/**\n * Type for the options passed to the \"createRouter\" function.\n *\n * @public\n * @deprecated This type is only exported for legacy reasons and will be removed in the future.\n */\nexport type RouterOptions = {\n database: DatabaseService;\n identity: IdentityApi;\n signals?: SignalsService;\n};\n\n/**\n * Create the user settings backend routes.\n *\n * @public\n * @deprecated This function is only exported for legacy reasons and will be removed in the future.\n * Please {@link https://backstage.io/docs/backend-system/building-backends/migrating | migrate } to use the new backend system and follow these {@link https://github.com/backstage/backstage/tree/master/plugins/user-settings-backend#new-backend | instructions } to install the user settings backend plugin.\n */\nexport async function createRouter(\n options: RouterOptions,\n): Promise<express.Router> {\n return await internalCreateRouter(options);\n}\n"],"names":["internalCreateRouter"],"mappings":";;;;AA0CA,eAAsB,aACpB,OACyB,EAAA;AACzB,EAAO,OAAA,MAAMA,oBAAqB,OAAO,CAAA;AAC3C;;;;"}
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.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 {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouterInternal } from './service/router';\nimport { signalsServiceRef } from '@backstage/plugin-signals-node';\nimport { DatabaseUserSettingsStore } from './database/DatabaseUserSettingsStore';\n\n/**\n * The user settings backend plugin.\n *\n * @public\n */\nexport default createBackendPlugin({\n pluginId: 'user-settings',\n register(env) {\n env.registerInit({\n deps: {\n database: coreServices.database,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n signals: signalsServiceRef,\n },\n async init({ database, httpAuth, httpRouter, signals }) {\n const userSettingsStore = await DatabaseUserSettingsStore.create({\n database,\n });\n httpRouter.use(\n await createRouterInternal({ userSettingsStore, httpAuth, signals }),\n );\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","signalsServiceRef","DatabaseUserSettingsStore","createRouterInternal"],"mappings":";;;;;;;;;AA6BA,cAAeA,oCAAoB,CAAA;AAAA,EACjC,QAAU,EAAA,eAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,UAAUC,6BAAa,CAAA,QAAA;AAAA,QACvB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,YAAYA,6BAAa,CAAA,UAAA;AAAA,QACzB,OAAS,EAAAC
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["../src/plugin.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 {\n coreServices,\n createBackendPlugin,\n} from '@backstage/backend-plugin-api';\nimport { createRouterInternal } from './service/router';\nimport { signalsServiceRef } from '@backstage/plugin-signals-node';\nimport { DatabaseUserSettingsStore } from './database/DatabaseUserSettingsStore';\n\n/**\n * The user settings backend plugin.\n *\n * @public\n */\nexport default createBackendPlugin({\n pluginId: 'user-settings',\n register(env) {\n env.registerInit({\n deps: {\n database: coreServices.database,\n httpAuth: coreServices.httpAuth,\n httpRouter: coreServices.httpRouter,\n signals: signalsServiceRef,\n },\n async init({ database, httpAuth, httpRouter, signals }) {\n const userSettingsStore = await DatabaseUserSettingsStore.create({\n database,\n });\n httpRouter.use(\n await createRouterInternal({ userSettingsStore, httpAuth, signals }),\n );\n },\n });\n },\n});\n"],"names":["createBackendPlugin","coreServices","signalsServiceRef","DatabaseUserSettingsStore","createRouterInternal"],"mappings":";;;;;;;;;AA6BA,cAAeA,oCAAoB,CAAA;AAAA,EACjC,QAAU,EAAA,eAAA;AAAA,EACV,SAAS,GAAK,EAAA;AACZ,IAAA,GAAA,CAAI,YAAa,CAAA;AAAA,MACf,IAAM,EAAA;AAAA,QACJ,UAAUC,6BAAa,CAAA,QAAA;AAAA,QACvB,UAAUA,6BAAa,CAAA,QAAA;AAAA,QACvB,YAAYA,6BAAa,CAAA,UAAA;AAAA,QACzB,OAAS,EAAAC;AAAA,OACX;AAAA,MACA,MAAM,IAAK,CAAA,EAAE,UAAU,QAAU,EAAA,UAAA,EAAY,SAAW,EAAA;AACtD,QAAM,MAAA,iBAAA,GAAoB,MAAMC,mDAAA,CAA0B,MAAO,CAAA;AAAA,UAC/D;AAAA,SACD,CAAA;AACD,QAAW,UAAA,CAAA,GAAA;AAAA,UACT,MAAMC,2BAAqB,CAAA,EAAE,iBAAmB,EAAA,QAAA,EAAU,SAAS;AAAA,SACrE;AAAA;AACF,KACD,CAAA;AAAA;AAEL,CAAC,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.cjs.js","sources":["../../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 { 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';\nimport { SignalsService } from '@backstage/plugin-signals-node';\nimport { UserSettingsSignal } from '@backstage/plugin-user-settings-common';\nimport {\n DatabaseService,\n HttpAuthService,\n} from '@backstage/backend-plugin-api';\n\n/**\n * @public\n */\nexport interface RouterOptions {\n database: DatabaseService;\n identity: IdentityApi;\n signals?: SignalsService;\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 signals: options.signals,\n });\n}\n\nexport async function createRouterInternal(\n options:\n | {\n identity: IdentityApi;\n userSettingsStore: UserSettingsStore;\n signals?: SignalsService;\n }\n | {\n httpAuth: HttpAuthService;\n userSettingsStore: UserSettingsStore;\n signals?: SignalsService;\n },\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 if ('httpAuth' in options) {\n const credentials = await options.httpAuth.credentials(req, {\n allow: ['user'],\n });\n return credentials.principal.userEntityRef;\n }\n\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 if (options.signals) {\n await options.signals.publish<UserSettingsSignal>({\n recipients: { type: 'user', entityRef: userEntityRef },\n channel: `user-settings`,\n message: { type: 'key-changed', key },\n });\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 if (options.signals) {\n await options.signals.publish<UserSettingsSignal>({\n recipients: { type: 'user', entityRef: userEntityRef },\n channel: 'user-settings',\n message: { type: 'key-deleted', key },\n });\n }\n\n res.status(204).end();\n });\n\n return router;\n}\n"],"names":["DatabaseUserSettingsStore","Router","express","AuthenticationError","InputError"],"mappings":";;;;;;;;;;;;AA2CA,eAAsB,aACpB,OACyB,EAAA;AACzB,EAAM,MAAA,iBAAA,GAAoB,MAAMA,mDAAA,CAA0B,MAAO,CAAA;AAAA,IAC/D,UAAU,OAAQ,CAAA
|
|
1
|
+
{"version":3,"file":"router.cjs.js","sources":["../../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 { 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';\nimport { SignalsService } from '@backstage/plugin-signals-node';\nimport { UserSettingsSignal } from '@backstage/plugin-user-settings-common';\nimport {\n DatabaseService,\n HttpAuthService,\n} from '@backstage/backend-plugin-api';\n\n/**\n * @public\n */\nexport interface RouterOptions {\n database: DatabaseService;\n identity: IdentityApi;\n signals?: SignalsService;\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 signals: options.signals,\n });\n}\n\nexport async function createRouterInternal(\n options:\n | {\n identity: IdentityApi;\n userSettingsStore: UserSettingsStore;\n signals?: SignalsService;\n }\n | {\n httpAuth: HttpAuthService;\n userSettingsStore: UserSettingsStore;\n signals?: SignalsService;\n },\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 if ('httpAuth' in options) {\n const credentials = await options.httpAuth.credentials(req, {\n allow: ['user'],\n });\n return credentials.principal.userEntityRef;\n }\n\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 if (options.signals) {\n await options.signals.publish<UserSettingsSignal>({\n recipients: { type: 'user', entityRef: userEntityRef },\n channel: `user-settings`,\n message: { type: 'key-changed', key },\n });\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 if (options.signals) {\n await options.signals.publish<UserSettingsSignal>({\n recipients: { type: 'user', entityRef: userEntityRef },\n channel: 'user-settings',\n message: { type: 'key-deleted', key },\n });\n }\n\n res.status(204).end();\n });\n\n return router;\n}\n"],"names":["DatabaseUserSettingsStore","Router","express","AuthenticationError","InputError"],"mappings":";;;;;;;;;;;;AA2CA,eAAsB,aACpB,OACyB,EAAA;AACzB,EAAM,MAAA,iBAAA,GAAoB,MAAMA,mDAAA,CAA0B,MAAO,CAAA;AAAA,IAC/D,UAAU,OAAQ,CAAA;AAAA,GACnB,CAAA;AAED,EAAA,OAAO,MAAM,oBAAqB,CAAA;AAAA,IAChC,iBAAA;AAAA,IACA,UAAU,OAAQ,CAAA,QAAA;AAAA,IAClB,SAAS,OAAQ,CAAA;AAAA,GAClB,CAAA;AACH;AAEA,eAAsB,qBACpB,OAWyB,EAAA;AACzB,EAAA,MAAM,SAASC,uBAAO,EAAA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AAQ,WAAW,aAAc,EAAA;AAAA,QACrD,OAAS,EAAA,eAAA;AAAA,QACT,OAAS,EAAA,EAAE,IAAM,EAAA,aAAA,EAAe,GAAI;AAAA,OACrC,CAAA;AAAA;AAGH,IAAI,GAAA,CAAA,MAAA,CAAO,GAAG,CAAA,CAAE,GAAI,EAAA;AAAA,GACrB,CAAA;AAED,EAAO,OAAA,MAAA;AACT;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-user-settings-backend",
|
|
3
|
-
"version": "0.2.27-next.
|
|
3
|
+
"version": "0.2.27-next.2",
|
|
4
4
|
"description": "The Backstage backend plugin to manage user settings",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "backend-plugin",
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
"test": "backstage-cli package test"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@backstage/backend-defaults": "0.5.3-next.
|
|
57
|
-
"@backstage/backend-plugin-api": "1.0.2-next.
|
|
56
|
+
"@backstage/backend-defaults": "0.5.3-next.2",
|
|
57
|
+
"@backstage/backend-plugin-api": "1.0.2-next.2",
|
|
58
58
|
"@backstage/config": "1.2.0",
|
|
59
59
|
"@backstage/errors": "1.2.4",
|
|
60
|
-
"@backstage/plugin-auth-node": "0.5.4-next.
|
|
61
|
-
"@backstage/plugin-signals-node": "0.1.14-next.
|
|
60
|
+
"@backstage/plugin-auth-node": "0.5.4-next.2",
|
|
61
|
+
"@backstage/plugin-signals-node": "0.1.14-next.2",
|
|
62
62
|
"@backstage/plugin-user-settings-common": "0.0.1",
|
|
63
63
|
"@backstage/types": "1.1.1",
|
|
64
64
|
"@types/express": "^4.17.6",
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"yn": "^4.0.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@backstage/backend-defaults": "0.5.3-next.
|
|
72
|
-
"@backstage/backend-test-utils": "1.0
|
|
73
|
-
"@backstage/cli": "0.29.0-next.
|
|
71
|
+
"@backstage/backend-defaults": "0.5.3-next.2",
|
|
72
|
+
"@backstage/backend-test-utils": "1.1.0-next.2",
|
|
73
|
+
"@backstage/cli": "0.29.0-next.2",
|
|
74
74
|
"@types/supertest": "^2.0.8",
|
|
75
75
|
"supertest": "^7.0.0"
|
|
76
76
|
}
|