@prismatic-io/components-mqtt 0.0.0-stage → 0.0.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/README.md +64 -2
- package/dist/icon.png +0 -0
- package/dist/index.js +223 -0
- package/npm-dist/icon.png +0 -0
- package/npm-dist/index.cjs +160 -0
- package/npm-dist/index.d.cts +91 -0
- package/package.json +53 -4
|
Binary file
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
let _prismatic_io_spectral = require("@prismatic-io/spectral");
|
|
2
|
+
let mqtt = require("mqtt");
|
|
3
|
+
//#region src/inputs.ts
|
|
4
|
+
const message = (0, _prismatic_io_spectral.input)({
|
|
5
|
+
label: "Message",
|
|
6
|
+
example: "Message to Queue",
|
|
7
|
+
placeholder: "Message",
|
|
8
|
+
type: "string",
|
|
9
|
+
required: true,
|
|
10
|
+
comments: "Provide a string value to be sent to the MQTT topic.",
|
|
11
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
12
|
+
});
|
|
13
|
+
const topicName = (0, _prismatic_io_spectral.input)({
|
|
14
|
+
label: "Topic Name",
|
|
15
|
+
example: "myTopic",
|
|
16
|
+
type: "string",
|
|
17
|
+
required: true,
|
|
18
|
+
comments: "Provide a string value for the name of the MQTT topic.",
|
|
19
|
+
clean: _prismatic_io_spectral.util.types.toString
|
|
20
|
+
});
|
|
21
|
+
const connectionInput = (0, _prismatic_io_spectral.input)({
|
|
22
|
+
label: "Connection",
|
|
23
|
+
type: "connection",
|
|
24
|
+
required: true
|
|
25
|
+
});
|
|
26
|
+
var connections_default = [(0, _prismatic_io_spectral.connection)({
|
|
27
|
+
key: "mqtt",
|
|
28
|
+
display: {
|
|
29
|
+
label: "MQTT Connection",
|
|
30
|
+
description: "Authenticate requests to an MQTT server."
|
|
31
|
+
},
|
|
32
|
+
inputs: {
|
|
33
|
+
host: {
|
|
34
|
+
label: "Host",
|
|
35
|
+
placeholder: "Host",
|
|
36
|
+
type: "string",
|
|
37
|
+
required: true,
|
|
38
|
+
shown: true,
|
|
39
|
+
comments: "Provide the string value for the host of the MQTT server."
|
|
40
|
+
},
|
|
41
|
+
protocol: {
|
|
42
|
+
label: "Protocol",
|
|
43
|
+
type: "string",
|
|
44
|
+
required: true,
|
|
45
|
+
shown: true,
|
|
46
|
+
comments: "The protocol used to connect to the MQTT server.",
|
|
47
|
+
model: [
|
|
48
|
+
{
|
|
49
|
+
label: "TCP",
|
|
50
|
+
value: "tcp"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
label: "MQTT",
|
|
54
|
+
value: "mqtt"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
label: "MQTTS",
|
|
58
|
+
value: "mqtts"
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
},
|
|
62
|
+
port: {
|
|
63
|
+
label: "Port",
|
|
64
|
+
placeholder: "Port",
|
|
65
|
+
type: "string",
|
|
66
|
+
required: false,
|
|
67
|
+
shown: true,
|
|
68
|
+
comments: "The port of the MQTT server."
|
|
69
|
+
},
|
|
70
|
+
username: {
|
|
71
|
+
label: "Username",
|
|
72
|
+
placeholder: "Username",
|
|
73
|
+
type: "string",
|
|
74
|
+
required: false,
|
|
75
|
+
shown: true
|
|
76
|
+
},
|
|
77
|
+
password: {
|
|
78
|
+
label: "Password",
|
|
79
|
+
placeholder: "Password",
|
|
80
|
+
type: "password",
|
|
81
|
+
required: false,
|
|
82
|
+
shown: true
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
})];
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/utils.ts
|
|
88
|
+
const validateConnection = (connection) => {
|
|
89
|
+
if (!connections_default.map((c) => c.key).includes(connection.key)) throw new _prismatic_io_spectral.ConnectionError(connection, `Unsupported connection ${connection.key}.`);
|
|
90
|
+
};
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region src/client.ts
|
|
93
|
+
const createClient = async (connection, debug, logger) => {
|
|
94
|
+
validateConnection(connection);
|
|
95
|
+
const username = connection.fields.username ? _prismatic_io_spectral.util.types.toString(connection.fields.username) : void 0;
|
|
96
|
+
const password = connection.fields.password ? _prismatic_io_spectral.util.types.toString(connection.fields.password) : void 0;
|
|
97
|
+
const port = connection.fields.port ? _prismatic_io_spectral.util.types.toNumber(connection.fields.port) : void 0;
|
|
98
|
+
const host = _prismatic_io_spectral.util.types.toString(connection.fields.host);
|
|
99
|
+
try {
|
|
100
|
+
const client = await (0, mqtt.connectAsync)({
|
|
101
|
+
connectTimeout: 2e4,
|
|
102
|
+
username,
|
|
103
|
+
password,
|
|
104
|
+
protocol: _prismatic_io_spectral.util.types.toString(connection.fields.protocol),
|
|
105
|
+
port,
|
|
106
|
+
host
|
|
107
|
+
});
|
|
108
|
+
if (debug) {
|
|
109
|
+
client.on("connect", () => logger.debug("MQTT connected"));
|
|
110
|
+
client.on("reconnect", () => logger.debug("MQTT reconnecting"));
|
|
111
|
+
client.on("close", () => logger.debug("MQTT connection closed"));
|
|
112
|
+
client.on("error", (err) => logger.error("MQTT error:", err));
|
|
113
|
+
client.on("packetsend", (packet) => logger.debug("MQTT packet sent:", JSON.stringify(packet)));
|
|
114
|
+
client.on("packetreceive", (packet) => logger.debug("MQTT packet received:", JSON.stringify(packet)));
|
|
115
|
+
}
|
|
116
|
+
return client;
|
|
117
|
+
} catch (error) {
|
|
118
|
+
throw new _prismatic_io_spectral.ConnectionError(connection, `Can't connect to MQTT server: ${error}`);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/actions.ts
|
|
123
|
+
const publish = (0, _prismatic_io_spectral.action)({
|
|
124
|
+
display: {
|
|
125
|
+
label: "Publish Message",
|
|
126
|
+
description: "Publish a message to a MQTT topic."
|
|
127
|
+
},
|
|
128
|
+
examplePayload: { data: "Message published successfully." },
|
|
129
|
+
perform: async (context, { mqttConnection, topicName, message }) => {
|
|
130
|
+
const client = await createClient(mqttConnection, context.debug.enabled, context.logger);
|
|
131
|
+
await client.publishAsync(topicName, message);
|
|
132
|
+
await client.endAsync();
|
|
133
|
+
return { data: "Message published successfully." };
|
|
134
|
+
},
|
|
135
|
+
inputs: {
|
|
136
|
+
topicName,
|
|
137
|
+
message,
|
|
138
|
+
mqttConnection: connectionInput
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/index.ts
|
|
143
|
+
var src_default = (0, _prismatic_io_spectral.component)({
|
|
144
|
+
key: "mqtt",
|
|
145
|
+
documentationUrl: "https://prismatic.io/docs/components/mqtt/",
|
|
146
|
+
public: true,
|
|
147
|
+
display: {
|
|
148
|
+
label: "MQTT",
|
|
149
|
+
category: "Application Connectors",
|
|
150
|
+
description: "Interact with an MQTT Queue",
|
|
151
|
+
iconPath: "icon.png"
|
|
152
|
+
},
|
|
153
|
+
actions: { publish },
|
|
154
|
+
connections: connections_default
|
|
155
|
+
});
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region npm-dist/.entry.ts
|
|
158
|
+
var _entry_default = (0, _prismatic_io_spectral.callableComponent)(src_default);
|
|
159
|
+
//#endregion
|
|
160
|
+
module.exports = _entry_default;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
//#region npm-dist/.entry.d.ts
|
|
2
|
+
declare const _default: import("@prismatic-io/spectral").CallableComponent<{
|
|
3
|
+
key: "mqtt";
|
|
4
|
+
documentationUrl: "https://prismatic.io/docs/components/mqtt/";
|
|
5
|
+
public: true;
|
|
6
|
+
display: {
|
|
7
|
+
label: string;
|
|
8
|
+
category: "Application Connectors";
|
|
9
|
+
description: string;
|
|
10
|
+
iconPath: string;
|
|
11
|
+
};
|
|
12
|
+
actions: {
|
|
13
|
+
publish: import("@prismatic-io/spectral").ActionDefinition<{
|
|
14
|
+
topicName: {
|
|
15
|
+
label: string;
|
|
16
|
+
example: string;
|
|
17
|
+
type: "string";
|
|
18
|
+
required: true;
|
|
19
|
+
comments: string;
|
|
20
|
+
clean: (value: unknown, defaultValue?: string) => string;
|
|
21
|
+
};
|
|
22
|
+
message: {
|
|
23
|
+
label: string;
|
|
24
|
+
example: string;
|
|
25
|
+
placeholder: string;
|
|
26
|
+
type: "string";
|
|
27
|
+
required: true;
|
|
28
|
+
comments: string;
|
|
29
|
+
clean: (value: unknown, defaultValue?: string) => string;
|
|
30
|
+
};
|
|
31
|
+
mqttConnection: {
|
|
32
|
+
label: string;
|
|
33
|
+
type: "connection";
|
|
34
|
+
required: true;
|
|
35
|
+
};
|
|
36
|
+
}, import("@prismatic-io/spectral").ConfigVarResultCollection, boolean, {
|
|
37
|
+
data: string;
|
|
38
|
+
}>;
|
|
39
|
+
};
|
|
40
|
+
connections: import("@prismatic-io/spectral").KeyedConnection<{
|
|
41
|
+
key: "mqtt";
|
|
42
|
+
display: {
|
|
43
|
+
label: string;
|
|
44
|
+
description: string;
|
|
45
|
+
};
|
|
46
|
+
inputs: {
|
|
47
|
+
host: {
|
|
48
|
+
label: string;
|
|
49
|
+
placeholder: string;
|
|
50
|
+
type: "string";
|
|
51
|
+
required: true;
|
|
52
|
+
shown: true;
|
|
53
|
+
comments: string;
|
|
54
|
+
};
|
|
55
|
+
protocol: {
|
|
56
|
+
label: string;
|
|
57
|
+
type: "string";
|
|
58
|
+
required: true;
|
|
59
|
+
shown: true;
|
|
60
|
+
comments: string;
|
|
61
|
+
model: {
|
|
62
|
+
label: string;
|
|
63
|
+
value: string;
|
|
64
|
+
}[];
|
|
65
|
+
};
|
|
66
|
+
port: {
|
|
67
|
+
label: string;
|
|
68
|
+
placeholder: string;
|
|
69
|
+
type: "string";
|
|
70
|
+
required: false;
|
|
71
|
+
shown: true;
|
|
72
|
+
comments: string;
|
|
73
|
+
};
|
|
74
|
+
username: {
|
|
75
|
+
label: string;
|
|
76
|
+
placeholder: string;
|
|
77
|
+
type: "string";
|
|
78
|
+
required: false;
|
|
79
|
+
shown: true;
|
|
80
|
+
};
|
|
81
|
+
password: {
|
|
82
|
+
label: string;
|
|
83
|
+
placeholder: string;
|
|
84
|
+
type: "password";
|
|
85
|
+
required: false;
|
|
86
|
+
shown: true;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
}, "mqtt">[];
|
|
90
|
+
}>;
|
|
91
|
+
export = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismatic-io/components-mqtt",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./npm-dist/index.cjs",
|
|
5
|
+
"types": "./npm-dist/index.d.cts",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./npm-dist/index.d.cts",
|
|
9
|
+
"default": "./npm-dist/index.cjs"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"description": "Interact with an MQTT Queue",
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/prismatic-io/components.git",
|
|
17
|
+
"directory": "components/mqtt"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"npm-dist",
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"prismatic": {
|
|
27
|
+
"component": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"lint": "biome lint --write .",
|
|
31
|
+
"format": "biome format --write .",
|
|
32
|
+
"build": "npm run format && npm run lint && tsdown",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"generate:manifest": "npm run build && npx @prismatic-io/spectral component-manifest",
|
|
35
|
+
"generate:manifest:dev": "npm run build && npx @prismatic-io/spectral component-manifest --skip-signature-verify",
|
|
36
|
+
"test": "echo 'no tests'",
|
|
37
|
+
"prepare": "npm run build",
|
|
38
|
+
"publish:platform": "npm run build && prism components:publish"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@prismatic-io/spectral": "^10.39.1"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"mqtt": "^5.7.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@biomejs/biome": "2.6.5",
|
|
48
|
+
"@types/node": "^26.6.4",
|
|
49
|
+
"tsdown": "0.22.3",
|
|
50
|
+
"typescript": "6.0.3",
|
|
51
|
+
"vitest": "4.1.9",
|
|
52
|
+
"@prismatic-io/spectral": "^10.39.1",
|
|
53
|
+
"build-config": "file:../../packages/build-config"
|
|
54
|
+
}
|
|
55
|
+
}
|