@backstage/plugin-notifications-node 0.0.2 → 0.1.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -4
- package/dist/index.cjs.js +15 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +4 -5
- package/package.json +11 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
# @backstage/plugin-notifications-node
|
|
2
2
|
|
|
3
|
-
## 0.0.
|
|
3
|
+
## 0.1.0-next.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 84af361: Migrated to using the new auth services.
|
|
4
8
|
|
|
5
9
|
### Patch Changes
|
|
6
10
|
|
|
11
|
+
- 0fb419b: Updated dependency `uuid` to `^9.0.0`.
|
|
12
|
+
Updated dependency `@types/uuid` to `^9.0.0`.
|
|
7
13
|
- Updated dependencies
|
|
8
|
-
- @backstage/backend-common@0.21.
|
|
9
|
-
- @backstage/plugin-
|
|
10
|
-
- @backstage/
|
|
14
|
+
- @backstage/backend-common@0.21.3-next.0
|
|
15
|
+
- @backstage/backend-plugin-api@0.6.13-next.0
|
|
16
|
+
- @backstage/plugin-signals-node@0.0.4-next.0
|
|
17
|
+
- @backstage/plugin-notifications-common@0.0.2-next.0
|
|
18
|
+
- @backstage/catalog-client@1.6.1-next.0
|
|
19
|
+
- @backstage/catalog-model@1.4.5-next.0
|
|
11
20
|
|
|
12
21
|
## 0.0.1
|
|
13
22
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -5,22 +5,25 @@ 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, pluginId) {
|
|
9
9
|
this.discovery = discovery;
|
|
10
|
-
this.
|
|
10
|
+
this.auth = auth;
|
|
11
11
|
this.pluginId = pluginId;
|
|
12
12
|
}
|
|
13
|
-
static create({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
static create(options) {
|
|
14
|
+
return new DefaultNotificationService(
|
|
15
|
+
options.discovery,
|
|
16
|
+
options.auth,
|
|
17
|
+
options.pluginId
|
|
18
|
+
);
|
|
19
19
|
}
|
|
20
20
|
async send(notification) {
|
|
21
21
|
try {
|
|
22
22
|
const baseUrl = await this.discovery.getBaseUrl("notifications");
|
|
23
|
-
const { token } = await this.
|
|
23
|
+
const { token } = await this.auth.getPluginRequestToken({
|
|
24
|
+
onBehalfOf: await this.auth.getOwnServiceCredentials(),
|
|
25
|
+
targetPluginId: "notifications"
|
|
26
|
+
});
|
|
24
27
|
const response = await fetch(`${baseUrl}/`, {
|
|
25
28
|
method: "POST",
|
|
26
29
|
body: JSON.stringify({
|
|
@@ -49,14 +52,14 @@ const notificationService = backendPluginApi.createServiceRef({
|
|
|
49
52
|
defaultFactory: async (service) => backendPluginApi.createServiceFactory({
|
|
50
53
|
service,
|
|
51
54
|
deps: {
|
|
55
|
+
auth: backendPluginApi.coreServices.auth,
|
|
52
56
|
discovery: backendPluginApi.coreServices.discovery,
|
|
53
|
-
tokenManager: backendPluginApi.coreServices.tokenManager,
|
|
54
57
|
pluginMetadata: backendPluginApi.coreServices.pluginMetadata
|
|
55
58
|
},
|
|
56
|
-
factory({
|
|
59
|
+
factory({ auth, discovery, pluginMetadata }) {
|
|
57
60
|
return DefaultNotificationService.create({
|
|
61
|
+
auth,
|
|
58
62
|
discovery,
|
|
59
|
-
tokenManager,
|
|
60
63
|
pluginId: pluginMetadata.getId()
|
|
61
64
|
});
|
|
62
65
|
}
|
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 pluginId: string;\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 private readonly pluginId: string,\n ) {}\n\n static create(\n options: NotificationServiceOptions,\n ): DefaultNotificationService {\n return new DefaultNotificationService(\n options.discovery,\n options.auth,\n options.pluginId,\n );\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 const response = await fetch(`${baseUrl}/`, {\n method: 'POST',\n body: JSON.stringify({\n ...notification,\n // TODO: Should retrieve this in the backend from service auth instead\n origin: `plugin-${this.pluginId}`,\n }),\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 pluginMetadata: coreServices.pluginMetadata,\n },\n factory({ auth, discovery, pluginMetadata }) {\n return DefaultNotificationService.create({\n auth,\n discovery,\n pluginId: pluginMetadata.getId(),\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":";;;;;;AA2CO,MAAM,0BAA0D,CAAA;AAAA,EAC7D,WAAA,CACW,SACA,EAAA,IAAA,EACA,QACjB,EAAA;AAHiB,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA,CAAA;AACA,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA,CAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA,CAAA;AAAA,GAChB;AAAA,EAEH,OAAO,OACL,OAC4B,EAAA;AAC5B,IAAA,OAAO,IAAI,0BAAA;AAAA,MACT,OAAQ,CAAA,SAAA;AAAA,MACR,OAAQ,CAAA,IAAA;AAAA,MACR,OAAQ,CAAA,QAAA;AAAA,KACV,CAAA;AAAA,GACF;AAAA,EAEA,MAAM,KAAK,YAAsD,EAAA;AAC/D,IAAI,IAAA;AACF,MAAA,MAAM,OAAU,GAAA,MAAM,IAAK,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A,MACnB,WAAWA,6BAAa,CAAA,SAAA;AAAA,MACxB,gBAAgBA,6BAAa,CAAA,cAAA;AAAA,KAC/B;AAAA,IACA,OAAQ,CAAA,EAAE,IAAM,EAAA,SAAA,EAAW,gBAAkB,EAAA;AAC3C,MAAA,OAAO,2BAA2B,MAAO,CAAA;AAAA,QACvC,IAAA;AAAA,QACA,SAAA;AAAA,QACA,QAAA,EAAU,eAAe,KAAM,EAAA;AAAA,OAChC,CAAA,CAAA;AAAA,KACH;AAAA,GACD,CAAA;AACL,CAAC;;ACOM,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,8 +9,8 @@ interface NotificationService {
|
|
|
10
9
|
|
|
11
10
|
/** @public */
|
|
12
11
|
type NotificationServiceOptions = {
|
|
12
|
+
auth: AuthService;
|
|
13
13
|
discovery: DiscoveryService;
|
|
14
|
-
tokenManager: TokenManager;
|
|
15
14
|
pluginId: string;
|
|
16
15
|
};
|
|
17
16
|
/** @public */
|
|
@@ -27,10 +26,10 @@ type NotificationSendOptions = {
|
|
|
27
26
|
/** @public */
|
|
28
27
|
declare class DefaultNotificationService implements NotificationService {
|
|
29
28
|
private readonly discovery;
|
|
30
|
-
private readonly
|
|
29
|
+
private readonly auth;
|
|
31
30
|
private readonly pluginId;
|
|
32
31
|
private constructor();
|
|
33
|
-
static create(
|
|
32
|
+
static create(options: NotificationServiceOptions): DefaultNotificationService;
|
|
34
33
|
send(notification: NotificationSendOptions): Promise<void>;
|
|
35
34
|
}
|
|
36
35
|
|
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.0",
|
|
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.3-next.0",
|
|
31
|
+
"@backstage/cli": "^0.25.3-next.0",
|
|
32
|
+
"@backstage/test-utils": "^1.5.1-next.0",
|
|
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.
|
|
43
|
-
"@backstage/plugin-signals-node": "^0.0.
|
|
39
|
+
"@backstage/backend-common": "^0.21.3-next.0",
|
|
40
|
+
"@backstage/backend-plugin-api": "^0.6.13-next.0",
|
|
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.0",
|
|
44
|
+
"@backstage/plugin-signals-node": "^0.0.4-next.0",
|
|
44
45
|
"knex": "^3.0.0",
|
|
45
|
-
"uuid": "^
|
|
46
|
+
"uuid": "^9.0.0"
|
|
46
47
|
}
|
|
47
48
|
}
|