@backstage/plugin-notifications-node 0.0.4 → 0.1.0-next.1
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 +19 -15
- package/dist/index.cjs.js +14 -22
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -7
- package/package.json +11 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
# @backstage/plugin-notifications-node
|
|
2
2
|
|
|
3
|
-
## 0.0.
|
|
3
|
+
## 0.1.0-next.1
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- a790a3d: Move notification origin resolving to backend with new auth
|
|
7
8
|
- Updated dependencies
|
|
8
|
-
- @backstage/
|
|
9
|
-
- @backstage/plugin-signals-node@0.0.
|
|
10
|
-
- @backstage/backend-
|
|
9
|
+
- @backstage/plugin-notifications-common@0.0.2-next.1
|
|
10
|
+
- @backstage/plugin-signals-node@0.1.0-next.1
|
|
11
|
+
- @backstage/backend-common@0.21.4-next.1
|
|
12
|
+
- @backstage/backend-plugin-api@0.6.14-next.1
|
|
13
|
+
- @backstage/catalog-client@1.6.1-next.0
|
|
14
|
+
- @backstage/catalog-model@1.4.5-next.0
|
|
11
15
|
|
|
12
|
-
## 0.0.
|
|
16
|
+
## 0.1.0-next.0
|
|
13
17
|
|
|
14
|
-
###
|
|
15
|
-
|
|
16
|
-
- Updated dependencies
|
|
17
|
-
- @backstage/backend-common@0.21.2
|
|
18
|
-
- @backstage/plugin-signals-node@0.0.3
|
|
19
|
-
- @backstage/backend-plugin-api@0.6.12
|
|
18
|
+
### Minor Changes
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
- 84af361: Migrated to using the new auth services.
|
|
22
21
|
|
|
23
22
|
### Patch Changes
|
|
24
23
|
|
|
24
|
+
- 0fb419b: Updated dependency `uuid` to `^9.0.0`.
|
|
25
|
+
Updated dependency `@types/uuid` to `^9.0.0`.
|
|
25
26
|
- Updated dependencies
|
|
26
|
-
- @backstage/backend-common@0.21.
|
|
27
|
-
- @backstage/plugin-
|
|
28
|
-
- @backstage/
|
|
27
|
+
- @backstage/backend-common@0.21.3-next.0
|
|
28
|
+
- @backstage/backend-plugin-api@0.6.13-next.0
|
|
29
|
+
- @backstage/plugin-signals-node@0.0.4-next.0
|
|
30
|
+
- @backstage/plugin-notifications-common@0.0.2-next.0
|
|
31
|
+
- @backstage/catalog-client@1.6.1-next.0
|
|
32
|
+
- @backstage/catalog-model@1.4.5-next.0
|
|
29
33
|
|
|
30
34
|
## 0.0.1
|
|
31
35
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -5,29 +5,23 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
6
|
|
|
7
7
|
class DefaultNotificationService {
|
|
8
|
-
constructor(discovery,
|
|
8
|
+
constructor(discovery, auth) {
|
|
9
9
|
this.discovery = discovery;
|
|
10
|
-
this.
|
|
11
|
-
this.pluginId = pluginId;
|
|
10
|
+
this.auth = auth;
|
|
12
11
|
}
|
|
13
|
-
static create({
|
|
14
|
-
|
|
15
|
-
discovery,
|
|
16
|
-
pluginId
|
|
17
|
-
}) {
|
|
18
|
-
return new DefaultNotificationService(discovery, tokenManager, pluginId);
|
|
12
|
+
static create(options) {
|
|
13
|
+
return new DefaultNotificationService(options.discovery, options.auth);
|
|
19
14
|
}
|
|
20
15
|
async send(notification) {
|
|
21
16
|
try {
|
|
22
17
|
const baseUrl = await this.discovery.getBaseUrl("notifications");
|
|
23
|
-
const { token } = await this.
|
|
18
|
+
const { token } = await this.auth.getPluginRequestToken({
|
|
19
|
+
onBehalfOf: await this.auth.getOwnServiceCredentials(),
|
|
20
|
+
targetPluginId: "notifications"
|
|
21
|
+
});
|
|
24
22
|
const response = await fetch(`${baseUrl}/`, {
|
|
25
23
|
method: "POST",
|
|
26
|
-
body: JSON.stringify(
|
|
27
|
-
...notification,
|
|
28
|
-
// TODO: Should retrieve this in the backend from service auth instead
|
|
29
|
-
origin: `plugin-${this.pluginId}`
|
|
30
|
-
}),
|
|
24
|
+
body: JSON.stringify(notification),
|
|
31
25
|
headers: {
|
|
32
26
|
"Content-Type": "application/json",
|
|
33
27
|
Accept: "application/json",
|
|
@@ -49,15 +43,13 @@ const notificationService = backendPluginApi.createServiceRef({
|
|
|
49
43
|
defaultFactory: async (service) => backendPluginApi.createServiceFactory({
|
|
50
44
|
service,
|
|
51
45
|
deps: {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
pluginMetadata: backendPluginApi.coreServices.pluginMetadata
|
|
46
|
+
auth: backendPluginApi.coreServices.auth,
|
|
47
|
+
discovery: backendPluginApi.coreServices.discovery
|
|
55
48
|
},
|
|
56
|
-
factory({
|
|
49
|
+
factory({ auth, discovery }) {
|
|
57
50
|
return DefaultNotificationService.create({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
pluginId: pluginMetadata.getId()
|
|
51
|
+
auth,
|
|
52
|
+
discovery
|
|
61
53
|
});
|
|
62
54
|
}
|
|
63
55
|
})
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/service/DefaultNotificationService.ts","../src/lib.ts","../src/extensions.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 */\nimport {
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/service/DefaultNotificationService.ts","../src/lib.ts","../src/extensions.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 { NotificationService } from './NotificationService';\nimport { AuthService, DiscoveryService } from '@backstage/backend-plugin-api';\nimport { NotificationPayload } from '@backstage/plugin-notifications-common';\n\n/** @public */\nexport type NotificationServiceOptions = {\n auth: AuthService;\n discovery: DiscoveryService;\n};\n\n/** @public */\nexport type NotificationRecipients = {\n type: 'entity';\n entityRef: string | string[];\n};\n\n// TODO: Support for broadcast messages\n// | { type: 'broadcast' };\n\n/** @public */\nexport type NotificationSendOptions = {\n recipients: NotificationRecipients;\n payload: NotificationPayload;\n};\n\n/** @public */\nexport class DefaultNotificationService implements NotificationService {\n private constructor(\n private readonly discovery: DiscoveryService,\n private readonly auth: AuthService,\n ) {}\n\n static create(\n options: NotificationServiceOptions,\n ): DefaultNotificationService {\n return new DefaultNotificationService(options.discovery, options.auth);\n }\n\n async send(notification: NotificationSendOptions): Promise<void> {\n try {\n const baseUrl = await this.discovery.getBaseUrl('notifications');\n const { token } = await this.auth.getPluginRequestToken({\n onBehalfOf: await this.auth.getOwnServiceCredentials(),\n targetPluginId: 'notifications',\n });\n\n const response = await fetch(`${baseUrl}/`, {\n method: 'POST',\n body: JSON.stringify(notification),\n headers: {\n 'Content-Type': 'application/json',\n Accept: 'application/json',\n Authorization: `Bearer ${token}`,\n },\n });\n\n if (!response.ok) {\n throw new Error(`Request failed with status ${response.status}`);\n }\n } catch (error) {\n // TODO: Should not throw in optimal case, see BEP\n throw new Error(`Failed to send notifications: ${error}`);\n }\n }\n}\n","/*\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 */\nimport {\n coreServices,\n createServiceFactory,\n createServiceRef,\n} from '@backstage/backend-plugin-api';\nimport { DefaultNotificationService } from './service';\nimport { NotificationService } from './service/NotificationService';\n\n/** @public */\nexport const notificationService = createServiceRef<NotificationService>({\n id: 'notifications.service',\n scope: 'plugin',\n defaultFactory: async service =>\n createServiceFactory({\n service,\n deps: {\n auth: coreServices.auth,\n discovery: coreServices.discovery,\n },\n factory({ auth, discovery }) {\n return DefaultNotificationService.create({\n auth,\n discovery,\n });\n },\n }),\n});\n","/*\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 */\nimport { createExtensionPoint } from '@backstage/backend-plugin-api';\nimport { Notification } from '@backstage/plugin-notifications-common';\n\n/**\n * @public\n */\nexport interface NotificationProcessor {\n /**\n * Decorate notification before sending it\n *\n * @param notification - The notification to decorate\n * @returns The same notification or a modified version of it\n */\n decorate?(notification: Notification): Promise<Notification>;\n\n /**\n * Send notification using this processor.\n *\n * @param notification - The notification to send\n */\n send?(notification: Notification): Promise<void>;\n}\n\n/**\n * @public\n */\nexport interface NotificationsProcessingExtensionPoint {\n addProcessor(\n ...processors: Array<NotificationProcessor | Array<NotificationProcessor>>\n ): void;\n}\n\n/**\n * @public\n */\nexport const notificationsProcessingExtensionPoint =\n createExtensionPoint<NotificationsProcessingExtensionPoint>({\n id: 'notifications.processing',\n });\n"],"names":["createServiceRef","createServiceFactory","coreServices","createExtensionPoint"],"mappings":";;;;;;AA0CO,MAAM,0BAA0D,CAAA;AAAA,EAC7D,WAAA,CACW,WACA,IACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA,CAAA;AACA,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA,CAAA;AAAA,GAChB;AAAA,EAEH,OAAO,OACL,OAC4B,EAAA;AAC5B,IAAA,OAAO,IAAI,0BAAA,CAA2B,OAAQ,CAAA,SAAA,EAAW,QAAQ,IAAI,CAAA,CAAA;AAAA,GACvE;AAAA,EAEA,MAAM,KAAK,YAAsD,EAAA;AAC/D,IAAI,IAAA;AACF,MAAA,MAAM,OAAU,GAAA,MAAM,IAAK,CAAA,SAAA,CAAU,WAAW,eAAe,CAAA,CAAA;AAC/D,MAAA,MAAM,EAAE,KAAM,EAAA,GAAI,MAAM,IAAA,CAAK,KAAK,qBAAsB,CAAA;AAAA,QACtD,UAAY,EAAA,MAAM,IAAK,CAAA,IAAA,CAAK,wBAAyB,EAAA;AAAA,QACrD,cAAgB,EAAA,eAAA;AAAA,OACjB,CAAA,CAAA;AAED,MAAA,MAAM,QAAW,GAAA,MAAM,KAAM,CAAA,CAAA,EAAG,OAAO,CAAK,CAAA,CAAA,EAAA;AAAA,QAC1C,MAAQ,EAAA,MAAA;AAAA,QACR,IAAA,EAAM,IAAK,CAAA,SAAA,CAAU,YAAY,CAAA;AAAA,QACjC,OAAS,EAAA;AAAA,UACP,cAAgB,EAAA,kBAAA;AAAA,UAChB,MAAQ,EAAA,kBAAA;AAAA,UACR,aAAA,EAAe,UAAU,KAAK,CAAA,CAAA;AAAA,SAChC;AAAA,OACD,CAAA,CAAA;AAED,MAAI,IAAA,CAAC,SAAS,EAAI,EAAA;AAChB,QAAA,MAAM,IAAI,KAAA,CAAM,CAA8B,2BAAA,EAAA,QAAA,CAAS,MAAM,CAAE,CAAA,CAAA,CAAA;AAAA,OACjE;AAAA,aACO,KAAO,EAAA;AAEd,MAAA,MAAM,IAAI,KAAA,CAAM,CAAiC,8BAAA,EAAA,KAAK,CAAE,CAAA,CAAA,CAAA;AAAA,KAC1D;AAAA,GACF;AACF;;ACxDO,MAAM,sBAAsBA,iCAAsC,CAAA;AAAA,EACvE,EAAI,EAAA,uBAAA;AAAA,EACJ,KAAO,EAAA,QAAA;AAAA,EACP,cAAA,EAAgB,OAAM,OAAA,KACpBC,qCAAqB,CAAA;AAAA,IACnB,OAAA;AAAA,IACA,IAAM,EAAA;AAAA,MACJ,MAAMC,6BAAa,CAAA,IAAA;AAAA,MACnB,WAAWA,6BAAa,CAAA,SAAA;AAAA,KAC1B;AAAA,IACA,OAAQ,CAAA,EAAE,IAAM,EAAA,SAAA,EAAa,EAAA;AAC3B,MAAA,OAAO,2BAA2B,MAAO,CAAA;AAAA,QACvC,IAAA;AAAA,QACA,SAAA;AAAA,OACD,CAAA,CAAA;AAAA,KACH;AAAA,GACD,CAAA;AACL,CAAC;;ACSM,MAAM,wCACXC,qCAA4D,CAAA;AAAA,EAC1D,EAAI,EAAA,0BAAA;AACN,CAAC;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { TokenManager } from '@backstage/backend-common';
|
|
2
1
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
3
|
-
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
|
2
|
+
import { AuthService, DiscoveryService } from '@backstage/backend-plugin-api';
|
|
4
3
|
import { NotificationPayload, Notification } from '@backstage/plugin-notifications-common';
|
|
5
4
|
|
|
6
5
|
/** @public */
|
|
@@ -10,9 +9,8 @@ interface NotificationService {
|
|
|
10
9
|
|
|
11
10
|
/** @public */
|
|
12
11
|
type NotificationServiceOptions = {
|
|
12
|
+
auth: AuthService;
|
|
13
13
|
discovery: DiscoveryService;
|
|
14
|
-
tokenManager: TokenManager;
|
|
15
|
-
pluginId: string;
|
|
16
14
|
};
|
|
17
15
|
/** @public */
|
|
18
16
|
type NotificationRecipients = {
|
|
@@ -27,10 +25,9 @@ type NotificationSendOptions = {
|
|
|
27
25
|
/** @public */
|
|
28
26
|
declare class DefaultNotificationService implements NotificationService {
|
|
29
27
|
private readonly discovery;
|
|
30
|
-
private readonly
|
|
31
|
-
private readonly pluginId;
|
|
28
|
+
private readonly auth;
|
|
32
29
|
private constructor();
|
|
33
|
-
static create(
|
|
30
|
+
static create(options: NotificationServiceOptions): DefaultNotificationService;
|
|
34
31
|
send(notification: NotificationSendOptions): Promise<void>;
|
|
35
32
|
}
|
|
36
33
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/plugin-notifications-node",
|
|
3
3
|
"description": "Node.js library for the notifications plugin",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.1.0-next.1",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
@@ -27,21 +27,22 @@
|
|
|
27
27
|
"postpack": "backstage-cli package postpack"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@backstage/
|
|
31
|
-
"@backstage/
|
|
30
|
+
"@backstage/backend-test-utils": "^0.3.4-next.1",
|
|
31
|
+
"@backstage/cli": "^0.25.3-next.1",
|
|
32
|
+
"@backstage/test-utils": "^1.5.1-next.1",
|
|
32
33
|
"msw": "^1.0.0"
|
|
33
34
|
},
|
|
34
35
|
"files": [
|
|
35
36
|
"dist"
|
|
36
37
|
],
|
|
37
38
|
"dependencies": {
|
|
38
|
-
"@backstage/backend-common": "^0.21.
|
|
39
|
-
"@backstage/backend-plugin-api": "^0.6.
|
|
40
|
-
"@backstage/catalog-client": "^1.6.0",
|
|
41
|
-
"@backstage/catalog-model": "^1.4.
|
|
42
|
-
"@backstage/plugin-notifications-common": "^0.0.1",
|
|
43
|
-
"@backstage/plugin-signals-node": "^0.0.
|
|
39
|
+
"@backstage/backend-common": "^0.21.4-next.1",
|
|
40
|
+
"@backstage/backend-plugin-api": "^0.6.14-next.1",
|
|
41
|
+
"@backstage/catalog-client": "^1.6.1-next.0",
|
|
42
|
+
"@backstage/catalog-model": "^1.4.5-next.0",
|
|
43
|
+
"@backstage/plugin-notifications-common": "^0.0.2-next.1",
|
|
44
|
+
"@backstage/plugin-signals-node": "^0.1.0-next.1",
|
|
44
45
|
"knex": "^3.0.0",
|
|
45
|
-
"uuid": "^
|
|
46
|
+
"uuid": "^9.0.0"
|
|
46
47
|
}
|
|
47
48
|
}
|