@backstage/plugin-signals-node 0.0.0-nightly-20240118021622
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 +14 -0
- package/README.md +86 -0
- package/dist/index.cjs.js +59 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/package.json +42 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @backstage/plugin-signals-node
|
|
2
|
+
|
|
3
|
+
## 0.0.0-nightly-20240118021622
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 047bead: Add support to subscribe and publish messages through signals plugins
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @backstage/backend-common@0.0.0-nightly-20240118021622
|
|
10
|
+
- @backstage/config@1.1.1
|
|
11
|
+
- @backstage/plugin-auth-node@0.0.0-nightly-20240118021622
|
|
12
|
+
- @backstage/backend-plugin-api@0.0.0-nightly-20240118021622
|
|
13
|
+
- @backstage/types@1.1.1
|
|
14
|
+
- @backstage/plugin-events-node@0.0.0-nightly-20240118021622
|
package/README.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# @backstage/plugin-signals-node
|
|
2
|
+
|
|
3
|
+
Welcome to the Node.js library package for the signals plugin!
|
|
4
|
+
|
|
5
|
+
Signals plugin allows backend plugins to publish messages to frontend plugins.
|
|
6
|
+
|
|
7
|
+
## Getting started
|
|
8
|
+
|
|
9
|
+
Add SignalService to your plugin environment in `packages/backend/src/types.ts`:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { SignalService } from '@backstage/plugin-signals-node';
|
|
13
|
+
|
|
14
|
+
export type PluginEnvironment = {
|
|
15
|
+
// ...
|
|
16
|
+
signalService: SignalService;
|
|
17
|
+
};
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Add it also to your `makeCreateEnv` to allow access from the other plugins:
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { SignalService } from '@backstage/plugin-signals-node';
|
|
24
|
+
import { DefaultEventBroker } from '@backstage/plugin-events-backend';
|
|
25
|
+
|
|
26
|
+
function makeCreateEnv(config: Config) {
|
|
27
|
+
// ...
|
|
28
|
+
|
|
29
|
+
const eventBroker = new DefaultEventBroker(root.child({ type: 'plugin' }));
|
|
30
|
+
const signalService = DefaultSignalService.create({
|
|
31
|
+
eventBroker,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return (plugin: string): PluginEnvironment => {
|
|
35
|
+
const logger = root.child({ type: 'plugin', plugin });
|
|
36
|
+
return {
|
|
37
|
+
logger,
|
|
38
|
+
eventBroker,
|
|
39
|
+
signalService,
|
|
40
|
+
// ...
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
To allow connections from the frontend, you should also install the `@backstage/plugin-signals-backend`.
|
|
47
|
+
|
|
48
|
+
## Using the service
|
|
49
|
+
|
|
50
|
+
Once you have both of the backend plugins installed, you can utilize the signal service by calling the
|
|
51
|
+
`publish` method. This will publish the message to all subscribers in the frontend. To send message to
|
|
52
|
+
all subscribers, you can use `null` as `recipients` parameter.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
// Periodic sending example
|
|
56
|
+
setInterval(async () => {
|
|
57
|
+
await signalService.publish({
|
|
58
|
+
recipients: null,
|
|
59
|
+
channel: 'my_plugin',
|
|
60
|
+
message: {
|
|
61
|
+
message: 'hello world',
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}, 5000);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
To receive this message in the frontend, check the documentation of `@backstage/plugin-signals` and
|
|
68
|
+
`@backstage/plugin-signals-react`.
|
|
69
|
+
|
|
70
|
+
## Using event broker directly
|
|
71
|
+
|
|
72
|
+
Other way to send signals is to utilize the `EventBroker` directly. This requires that the payload is correct for it
|
|
73
|
+
to work:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
eventBroker.publish({
|
|
77
|
+
topic: 'signals',
|
|
78
|
+
eventPayload: {
|
|
79
|
+
recipients: ['user:default/user1'],
|
|
80
|
+
message: {
|
|
81
|
+
message: 'hello world',
|
|
82
|
+
},
|
|
83
|
+
channel: 'my_plugin',
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
```
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var backendPluginApi = require('@backstage/backend-plugin-api');
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __publicField = (obj, key, value) => {
|
|
10
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
13
|
+
class DefaultSignalService {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
// TODO: Remove this to be optional when events-backend has eventBroker as service
|
|
16
|
+
__publicField(this, "eventBroker");
|
|
17
|
+
({ eventBroker: this.eventBroker } = options);
|
|
18
|
+
}
|
|
19
|
+
static create(options) {
|
|
20
|
+
return new DefaultSignalService(options);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Publishes a message to user refs to specific topic
|
|
24
|
+
* @param recipients - string or array of user ref strings to publish message to
|
|
25
|
+
* @param topic - message topic
|
|
26
|
+
* @param message - message to publish
|
|
27
|
+
*/
|
|
28
|
+
async publish(signal) {
|
|
29
|
+
var _a;
|
|
30
|
+
const { recipients, channel, message } = signal;
|
|
31
|
+
await ((_a = this.eventBroker) == null ? void 0 : _a.publish({
|
|
32
|
+
topic: "signals",
|
|
33
|
+
eventPayload: {
|
|
34
|
+
recipients,
|
|
35
|
+
message,
|
|
36
|
+
channel
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const signalService = backendPluginApi.createServiceRef({
|
|
43
|
+
id: "signals.service",
|
|
44
|
+
scope: "plugin",
|
|
45
|
+
defaultFactory: async (service) => backendPluginApi.createServiceFactory({
|
|
46
|
+
service,
|
|
47
|
+
deps: {
|
|
48
|
+
// TODO: EventBroker. It is optional for now but it's actually required so waiting for the new backend system
|
|
49
|
+
// for the events-backend for this to work.
|
|
50
|
+
},
|
|
51
|
+
factory({}) {
|
|
52
|
+
return DefaultSignalService.create({});
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
exports.DefaultSignalService = DefaultSignalService;
|
|
58
|
+
exports.signalService = signalService;
|
|
59
|
+
//# sourceMappingURL=index.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../src/DefaultSignalService.ts","../src/lib.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 { EventBroker } from '@backstage/plugin-events-node';\nimport { SignalPayload, SignalServiceOptions } from './types';\nimport { SignalService } from './SignalService';\n\n/** @public */\nexport class DefaultSignalService implements SignalService {\n // TODO: Remove this to be optional when events-backend has eventBroker as service\n private eventBroker?: EventBroker;\n\n static create(options: SignalServiceOptions) {\n return new DefaultSignalService(options);\n }\n\n private constructor(options: SignalServiceOptions) {\n ({ eventBroker: this.eventBroker } = options);\n }\n\n /**\n * Publishes a message to user refs to specific topic\n * @param recipients - string or array of user ref strings to publish message to\n * @param topic - message topic\n * @param message - message to publish\n */\n async publish(signal: SignalPayload) {\n const { recipients, channel, message } = signal;\n await this.eventBroker?.publish({\n topic: 'signals',\n eventPayload: {\n recipients,\n message,\n channel,\n },\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 createServiceFactory,\n createServiceRef,\n} from '@backstage/backend-plugin-api';\nimport { DefaultSignalService } from './DefaultSignalService';\nimport { SignalService } from './SignalService';\n\n/** @public */\nexport const signalService = createServiceRef<SignalService>({\n id: 'signals.service',\n scope: 'plugin',\n defaultFactory: async service =>\n createServiceFactory({\n service,\n deps: {\n // TODO: EventBroker. It is optional for now but it's actually required so waiting for the new backend system\n // for the events-backend for this to work.\n },\n factory({}) {\n return DefaultSignalService.create({});\n },\n }),\n});\n"],"names":["createServiceRef","createServiceFactory"],"mappings":";;;;;;;;;;;;AAoBO,MAAM,oBAA8C,CAAA;AAAA,EAQjD,YAAY,OAA+B,EAAA;AANnD;AAAA,IAAQ,aAAA,CAAA,IAAA,EAAA,aAAA,CAAA,CAAA;AAON,IAAA,CAAC,EAAE,WAAA,EAAa,IAAK,CAAA,WAAA,EAAgB,GAAA,OAAA,EAAA;AAAA,GACvC;AAAA,EANA,OAAO,OAAO,OAA+B,EAAA;AAC3C,IAAO,OAAA,IAAI,qBAAqB,OAAO,CAAA,CAAA;AAAA,GACzC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,QAAQ,MAAuB,EAAA;AAtCvC,IAAA,IAAA,EAAA,CAAA;AAuCI,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,EAAY,GAAA,MAAA,CAAA;AACzC,IAAM,OAAA,CAAA,EAAA,GAAA,IAAA,CAAK,WAAL,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAkB,OAAQ,CAAA;AAAA,MAC9B,KAAO,EAAA,SAAA;AAAA,MACP,YAAc,EAAA;AAAA,QACZ,UAAA;AAAA,QACA,OAAA;AAAA,QACA,OAAA;AAAA,OACF;AAAA,KACF,CAAA,CAAA,CAAA;AAAA,GACF;AACF;;AC1BO,MAAM,gBAAgBA,iCAAgC,CAAA;AAAA,EAC3D,EAAI,EAAA,iBAAA;AAAA,EACJ,KAAO,EAAA,QAAA;AAAA,EACP,cAAA,EAAgB,OAAM,OAAA,KACpBC,qCAAqB,CAAA;AAAA,IACnB,OAAA;AAAA,IACA,IAAM,EAAA;AAAA;AAAA;AAAA,KAGN;AAAA,IACA,OAAA,CAAQ,EAAI,EAAA;AACV,MAAO,OAAA,oBAAA,CAAqB,MAAO,CAAA,EAAE,CAAA,CAAA;AAAA,KACvC;AAAA,GACD,CAAA;AACL,CAAC;;;;;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
2
|
+
import { EventBroker } from '@backstage/plugin-events-node';
|
|
3
|
+
import { JsonObject } from '@backstage/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
type SignalServiceOptions = {
|
|
9
|
+
eventBroker?: EventBroker;
|
|
10
|
+
};
|
|
11
|
+
/** @public */
|
|
12
|
+
type SignalPayload = {
|
|
13
|
+
recipients: string[] | null;
|
|
14
|
+
channel: string;
|
|
15
|
+
message: JsonObject;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** @public */
|
|
19
|
+
type SignalService = {
|
|
20
|
+
/**
|
|
21
|
+
* Publishes a message to user refs to specific topic
|
|
22
|
+
*/
|
|
23
|
+
publish(signal: SignalPayload): Promise<void>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** @public */
|
|
27
|
+
declare const signalService: _backstage_backend_plugin_api.ServiceRef<SignalService, "plugin">;
|
|
28
|
+
|
|
29
|
+
/** @public */
|
|
30
|
+
declare class DefaultSignalService implements SignalService {
|
|
31
|
+
private eventBroker?;
|
|
32
|
+
static create(options: SignalServiceOptions): DefaultSignalService;
|
|
33
|
+
private constructor();
|
|
34
|
+
/**
|
|
35
|
+
* Publishes a message to user refs to specific topic
|
|
36
|
+
* @param recipients - string or array of user ref strings to publish message to
|
|
37
|
+
* @param topic - message topic
|
|
38
|
+
* @param message - message to publish
|
|
39
|
+
*/
|
|
40
|
+
publish(signal: SignalPayload): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { DefaultSignalService, SignalPayload, SignalService, SignalServiceOptions, signalService };
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@backstage/plugin-signals-node",
|
|
3
|
+
"description": "Node.js library for the signals plugin",
|
|
4
|
+
"version": "0.0.0-nightly-20240118021622",
|
|
5
|
+
"main": "dist/index.cjs.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public",
|
|
10
|
+
"main": "dist/index.cjs.js",
|
|
11
|
+
"types": "dist/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"backstage": {
|
|
14
|
+
"role": "node-library"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "backstage-cli package build",
|
|
18
|
+
"lint": "backstage-cli package lint",
|
|
19
|
+
"test": "backstage-cli package test",
|
|
20
|
+
"clean": "backstage-cli package clean",
|
|
21
|
+
"prepack": "backstage-cli package prepack",
|
|
22
|
+
"postpack": "backstage-cli package postpack"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@backstage/cli": "^0.0.0-nightly-20240118021622",
|
|
26
|
+
"@types/express": "^4.17.21"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@backstage/backend-common": "^0.0.0-nightly-20240118021622",
|
|
33
|
+
"@backstage/backend-plugin-api": "^0.0.0-nightly-20240118021622",
|
|
34
|
+
"@backstage/config": "^1.1.1",
|
|
35
|
+
"@backstage/plugin-auth-node": "^0.0.0-nightly-20240118021622",
|
|
36
|
+
"@backstage/plugin-events-node": "^0.0.0-nightly-20240118021622",
|
|
37
|
+
"@backstage/types": "^1.1.1",
|
|
38
|
+
"express": "^4.17.1",
|
|
39
|
+
"uuid": "^8.0.0",
|
|
40
|
+
"ws": "^8.14.2"
|
|
41
|
+
}
|
|
42
|
+
}
|