@redkern/node-red-redis 0.0.0-stage → 1.0.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 +24 -0
- package/LICENSE +188 -0
- package/README.md +283 -2
- package/SECURITY.md +11 -0
- package/examples/commands-and-pubsub.json +15 -0
- package/examples/streams-at-least-once.json +23 -0
- package/lib/completion.js +79 -0
- package/lib/control.js +59 -0
- package/lib/denylist.js +118 -0
- package/lib/dlq.js +49 -0
- package/lib/format.js +122 -0
- package/lib/inflight.js +131 -0
- package/lib/list-consumer.js +125 -0
- package/lib/metrics.js +85 -0
- package/lib/node-helpers.js +77 -0
- package/lib/palette.js +168 -0
- package/lib/slot.js +33 -0
- package/lib/stream-consumer.js +669 -0
- package/nodes/icons/redkern-redis-command.svg +4 -0
- package/nodes/icons/redkern-redis-list-in.svg +4 -0
- package/nodes/icons/redkern-redis-multi.svg +4 -0
- package/nodes/icons/redkern-redis-scan.svg +4 -0
- package/nodes/icons/redkern-redis-stream-ack.svg +4 -0
- package/nodes/icons/redkern-redis-stream-claim.svg +4 -0
- package/nodes/icons/redkern-redis-stream-control.svg +4 -0
- package/nodes/icons/redkern-redis-stream-gc.svg +4 -0
- package/nodes/icons/redkern-redis-stream-in.svg +4 -0
- package/nodes/icons/redkern-redis-stream-metrics.svg +4 -0
- package/nodes/icons/redkern-redis-stream-out.svg +4 -0
- package/nodes/icons/redkern-redis-subscribe.svg +4 -0
- package/nodes/icons/redkern-redis.svg +4 -0
- package/nodes/locales/en-US/redkern-redis.html +299 -0
- package/nodes/locales/en-US/redkern-redis.json +308 -0
- package/nodes/redkern-redis-command.js +49 -0
- package/nodes/redkern-redis-config.js +273 -0
- package/nodes/redkern-redis-list-in.js +88 -0
- package/nodes/redkern-redis-multi.js +75 -0
- package/nodes/redkern-redis-scan.js +105 -0
- package/nodes/redkern-redis-stream-ack.js +66 -0
- package/nodes/redkern-redis-stream-claim.js +60 -0
- package/nodes/redkern-redis-stream-control.js +35 -0
- package/nodes/redkern-redis-stream-gc.js +77 -0
- package/nodes/redkern-redis-stream-in.js +155 -0
- package/nodes/redkern-redis-stream-metrics.js +85 -0
- package/nodes/redkern-redis-stream-out.js +55 -0
- package/nodes/redkern-redis-subscribe.js +51 -0
- package/nodes/redkern-redis.html +1126 -0
- package/nodes/redkern-redis.js +31 -0
- package/package.json +76 -4
package/lib/metrics.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const CONTENT_TYPE = 'text/plain; version=0.0.4; charset=utf-8';
|
|
4
|
+
|
|
5
|
+
const DEFINITIONS = Object.freeze({
|
|
6
|
+
redkern_redis_connections: { type: 'gauge', help: 'Open Redis connections by role.' },
|
|
7
|
+
redkern_redis_delivered_total: { type: 'counter', help: 'Stream entries sent into flows by stream-in.' },
|
|
8
|
+
redkern_redis_redeliveries_total: { type: 'counter', help: 'Stream entries delivered more than once (recovery, reclaim, XAUTOCLAIM).' },
|
|
9
|
+
redkern_redis_acked_total: { type: 'counter', help: 'Stream entries acknowledged by stream-ack or auto ACK.' },
|
|
10
|
+
redkern_redis_dead_letter_total: { type: 'counter', help: 'Stream entries moved to the dead-letter stream.' },
|
|
11
|
+
redkern_redis_consumer_paused: { type: 'gauge', help: 'Whether a stream-in consumer is paused (1) or reading (0).' },
|
|
12
|
+
redkern_redis_consumer_inflight: { type: 'gauge', help: 'Entries sent by stream-in and not yet acknowledged.' },
|
|
13
|
+
redkern_redis_stream_pending: { type: 'gauge', help: 'Consumer group PEL size from the last stream-metrics sample.' },
|
|
14
|
+
redkern_redis_stream_lag: { type: 'gauge', help: 'Consumer group lag from the last stream-metrics sample.' },
|
|
15
|
+
redkern_redis_stream_dead_letter_length: { type: 'gauge', help: 'DLQ stream length from the last stream-metrics sample.' },
|
|
16
|
+
redkern_redis_stream_consumers: { type: 'gauge', help: 'Consumers in the group from the last stream-metrics sample.' }
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
function escapeLabel(value) {
|
|
20
|
+
return String(value).replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function labelKey(labels) {
|
|
24
|
+
const keys = Object.keys(labels).sort();
|
|
25
|
+
return keys.map((key) => `${key}="${escapeLabel(labels[key])}"`).join(',');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Palette-owned metric registry (RDS-STR-14). Rendered once per scrape in
|
|
30
|
+
* Prometheus text 0.0.4; values are plain numbers kept in memory.
|
|
31
|
+
*/
|
|
32
|
+
class MetricsRegistry {
|
|
33
|
+
constructor() {
|
|
34
|
+
/** @type {Map<string, Map<string, number>>} */
|
|
35
|
+
this.series = new Map();
|
|
36
|
+
/** @type {Set<() => void>} */
|
|
37
|
+
this.collectors = new Set();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
inc(name, labels = {}, value = 1) {
|
|
41
|
+
const series = this.family(name);
|
|
42
|
+
const key = labelKey(labels);
|
|
43
|
+
series.set(key, (series.get(key) || 0) + value);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
set(name, labels = {}, value = 0) {
|
|
47
|
+
this.family(name).set(labelKey(labels), Number(value) || 0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
delete(name, labels = {}) {
|
|
51
|
+
this.series.get(name)?.delete(labelKey(labels));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
family(name) {
|
|
55
|
+
if (!DEFINITIONS[name]) throw new TypeError(`Unknown metric ${name}`);
|
|
56
|
+
let series = this.series.get(name);
|
|
57
|
+
if (!series) {
|
|
58
|
+
series = new Map();
|
|
59
|
+
this.series.set(name, series);
|
|
60
|
+
}
|
|
61
|
+
return series;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Registers a function called before each render to refresh gauges. */
|
|
65
|
+
collect(fn) {
|
|
66
|
+
this.collectors.add(fn);
|
|
67
|
+
return () => this.collectors.delete(fn);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
render() {
|
|
71
|
+
for (const collector of this.collectors) {
|
|
72
|
+
try { collector(); } catch { /* a broken collector must not break the scrape */ }
|
|
73
|
+
}
|
|
74
|
+
const lines = [];
|
|
75
|
+
for (const [name, definition] of Object.entries(DEFINITIONS)) {
|
|
76
|
+
lines.push(`# HELP ${name} ${definition.help}`, `# TYPE ${name} ${definition.type}`);
|
|
77
|
+
const series = this.series.get(name);
|
|
78
|
+
if (!series) continue;
|
|
79
|
+
for (const [labels, value] of series) lines.push(labels ? `${name}{${labels}} ${value}` : `${name} ${value}`);
|
|
80
|
+
}
|
|
81
|
+
return `${lines.join('\n')}\n`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
module.exports = { MetricsRegistry, CONTENT_TYPE, DEFINITIONS };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const kit = require('@redkern/node-red-kit');
|
|
4
|
+
const { classifyRedisError } = require('@redkern/node-red-kit/redis');
|
|
5
|
+
|
|
6
|
+
/** Schema fields shared by nodes that run input through k.onInput (RDS-CMD-8). */
|
|
7
|
+
const INPUT_SCHEMA = Object.freeze({
|
|
8
|
+
concurrency: { type: 'int', min: 1, max: 10000, default: 64 },
|
|
9
|
+
maxQueue: { type: 'int', min: 0, max: 1000000, default: 10000 },
|
|
10
|
+
errorOutput: { type: 'bool', default: false }
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const START_QUEUE_TIMEOUT_MS = 30000;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Resolves the redkern-redis-config node referenced by `server`.
|
|
17
|
+
* @returns {any} the config node's `redkern` API
|
|
18
|
+
*/
|
|
19
|
+
function requireConfig(RED, serverId) {
|
|
20
|
+
const configNode = serverId ? RED.nodes.getNode(serverId) : null;
|
|
21
|
+
if (!configNode || !configNode.redkern) {
|
|
22
|
+
throw new kit.ConfigError([{ field: 'server', code: 'CONFIG_NODE_MISSING', message: 'Redis config node is not set or not deployed' }]);
|
|
23
|
+
}
|
|
24
|
+
if (configNode.redkern.issues.length) throw new kit.ConfigError(configNode.redkern.issues);
|
|
25
|
+
return configNode.redkern;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function classify(error) {
|
|
29
|
+
if (error?.name === 'ConfigError' || error?.code === 'CONFIG_INVALID') return 'config';
|
|
30
|
+
// An ACL without the needed command or key, or a key of another type, does
|
|
31
|
+
// not heal on retry by itself: red status, retries continue until fixed.
|
|
32
|
+
if (/^(NOPERM|WRONGTYPE)\b/.test(String(error?.message || ''))) return 'auth';
|
|
33
|
+
return classifyRedisError(error);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Registers the node with its config node and connects the shared client in
|
|
38
|
+
* onStart, retried by kit with backoff on transient failures.
|
|
39
|
+
* @returns {{ ready: Promise<boolean>, client: () => any, config: () => any }}
|
|
40
|
+
*/
|
|
41
|
+
function startShared(RED, k, node, serverId) {
|
|
42
|
+
let api;
|
|
43
|
+
let client;
|
|
44
|
+
let release;
|
|
45
|
+
const ready = k.onStart(async () => {
|
|
46
|
+
api = requireConfig(RED, serverId);
|
|
47
|
+
if (!release) {
|
|
48
|
+
release = api.register(node.id);
|
|
49
|
+
k.onClose(() => release());
|
|
50
|
+
}
|
|
51
|
+
client = await api.shared();
|
|
52
|
+
}, { classify });
|
|
53
|
+
return { ready, client: () => client, config: () => api };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Applies the native port layout: with errorOutput on, errors leave through
|
|
58
|
+
* the last output (KIT-LOG-4) and the node has one extra output.
|
|
59
|
+
*/
|
|
60
|
+
function inputOptions(parsed, outputs) {
|
|
61
|
+
const value = parsed.ok ? parsed.value : { concurrency: 1, maxQueue: 0, errorOutput: false };
|
|
62
|
+
return {
|
|
63
|
+
concurrency: value.concurrency,
|
|
64
|
+
maxQueue: value.maxQueue,
|
|
65
|
+
startQueueTimeoutMs: START_QUEUE_TIMEOUT_MS,
|
|
66
|
+
errorOutput: value.errorOutput,
|
|
67
|
+
outputCount: value.errorOutput ? outputs + 1 : outputs
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Sends to the first output when errorOutput adds an error port. */
|
|
72
|
+
function primary(send, errorOutput, msg) {
|
|
73
|
+
if (errorOutput) send([msg, null]);
|
|
74
|
+
else send(msg);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = { INPUT_SCHEMA, START_QUEUE_TIMEOUT_MS, requireConfig, classify, startShared, inputOptions, primary };
|
package/lib/palette.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const kit = require('@redkern/node-red-kit');
|
|
4
|
+
const { InflightRegistry } = require('./inflight.js');
|
|
5
|
+
const { MetricsRegistry, CONTENT_TYPE } = require('./metrics.js');
|
|
6
|
+
const { parseCommand, executeControl } = require('./control.js');
|
|
7
|
+
const { createCompletionTracker } = require('./completion.js');
|
|
8
|
+
|
|
9
|
+
const DOMAIN = 'redis';
|
|
10
|
+
const SETTINGS_TYPE = 'redkern-redis-config';
|
|
11
|
+
const INTERNAL_PORT = 9551;
|
|
12
|
+
|
|
13
|
+
function hasToken(RED, name) {
|
|
14
|
+
const fromEnv = kit.readEnv(`REDKERN_REDIS_${name.toUpperCase()}_TOKEN`);
|
|
15
|
+
if (typeof fromEnv === 'string' && fromEnv.trim() !== '') return true;
|
|
16
|
+
const fromSettings = RED.settings?.[`redkernRedisConfig${name[0].toUpperCase()}${name.slice(1)}Token`];
|
|
17
|
+
return typeof fromSettings === 'string' && fromSettings.trim() !== '';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Palette closure shared by every node file of this package (KIT-ARCH-2,
|
|
22
|
+
* RDS-STR-5):
|
|
23
|
+
* one kit context, the in-flight registry (RDS-STR-5), the metrics registry
|
|
24
|
+
* (RDS-STR-14), stream-in consumers for control, and the HTTP routes.
|
|
25
|
+
* @param {any} RED
|
|
26
|
+
*/
|
|
27
|
+
function createPalette(RED) {
|
|
28
|
+
let palette;
|
|
29
|
+
|
|
30
|
+
const registry = new InflightRegistry();
|
|
31
|
+
const metrics = new MetricsRegistry();
|
|
32
|
+
/** @type {Map<string, { nodeId: string, consumer: any, drainTimeoutMs: number }>} */
|
|
33
|
+
const consumers = new Map();
|
|
34
|
+
/** @type {Map<string, () => object>} */
|
|
35
|
+
const configs = new Map();
|
|
36
|
+
const metricsToken = hasToken(RED, 'metrics');
|
|
37
|
+
const drainToken = hasToken(RED, 'drain');
|
|
38
|
+
// KIT-HTTP-6: one internal listener is either loopback-only (all routes
|
|
39
|
+
// 'local', bound to 127.0.0.1) or token-only (bound to 0.0.0.0). Without the
|
|
40
|
+
// metrics route drain stays loopback-only without a token; with it drain
|
|
41
|
+
// needs its own token, REDKERN_REDIS_DRAIN_TOKEN.
|
|
42
|
+
const drainAuth = metricsToken ? (drainToken ? { token: 'drain' } : null) : 'local';
|
|
43
|
+
const secrets = {};
|
|
44
|
+
if (metricsToken) secrets.metrics = { required: true };
|
|
45
|
+
if (metricsToken && drainToken) secrets.drain = { required: true };
|
|
46
|
+
|
|
47
|
+
metrics.collect(() => {
|
|
48
|
+
const totals = { shared: 0, blocking: 0, subscriber: 0 };
|
|
49
|
+
for (const describe of configs.values()) {
|
|
50
|
+
const counts = describe().connections;
|
|
51
|
+
for (const role of Object.keys(totals)) totals[role] += counts[role] || 0;
|
|
52
|
+
}
|
|
53
|
+
for (const [role, value] of Object.entries(totals)) metrics.set('redkern_redis_connections', { role }, value);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const internalRoutes = [];
|
|
57
|
+
if (drainAuth) internalRoutes.push({
|
|
58
|
+
method: 'POST',
|
|
59
|
+
path: '/streams/drain',
|
|
60
|
+
auth: drainAuth,
|
|
61
|
+
handler: async (request, response, owners) => {
|
|
62
|
+
const body = request.body && typeof request.body === 'object' ? request.body : {};
|
|
63
|
+
const command = parseCommand({ ...body, action: 'drain' });
|
|
64
|
+
const consumersOnly = [...owners.values()].filter((owner) => owner && owner.consumer);
|
|
65
|
+
const result = await executeControl(consumersOnly, command);
|
|
66
|
+
response.status(result.drained ? 200 : 504).json(result);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
if (metricsToken) {
|
|
70
|
+
internalRoutes.push({
|
|
71
|
+
method: 'GET',
|
|
72
|
+
path: '/metrics',
|
|
73
|
+
auth: { token: 'metrics' },
|
|
74
|
+
handler: async (_request, response) => response.text(metrics.render(), CONTENT_TYPE)
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const rk = kit.init(RED, {
|
|
79
|
+
domain: DOMAIN,
|
|
80
|
+
settingsType: SETTINGS_TYPE,
|
|
81
|
+
secrets,
|
|
82
|
+
// Admin control can run drain, which waits up to drainTimeoutMs (30 min max).
|
|
83
|
+
handlerTimeoutMs: 31 * 60 * 1000,
|
|
84
|
+
metrics: { contentType: CONTENT_TYPE, metrics: () => metrics.render() },
|
|
85
|
+
internalServer: {
|
|
86
|
+
port: INTERNAL_PORT,
|
|
87
|
+
// The drain route only waits; give it room beyond the longest sane drain.
|
|
88
|
+
handlerTimeoutMs: 31 * 60 * 1000,
|
|
89
|
+
routes: internalRoutes
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (metricsToken && !drainToken) {
|
|
94
|
+
RED.log.warn('[redkern:redis] The internal port serves /metrics with a token, so the loopback drain route is off: set REDKERN_REDIS_DRAIN_TOKEN for preStop drain, or scrape metrics through the prometheus palette instead');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function controlError(error) {
|
|
98
|
+
if (error?.code?.startsWith('CONTROL_')) throw new kit.PublicError(400, error.message, { code: error.code });
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const statusRoute = rk.createRouteRegistry({
|
|
103
|
+
method: 'GET',
|
|
104
|
+
path: '/streams/status',
|
|
105
|
+
permission: rk.names.permRead,
|
|
106
|
+
handler: async (_request, response, active) => {
|
|
107
|
+
response.json(await executeControl(active.values(), { action: 'status' }));
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const controlRoute = rk.createRouteRegistry({
|
|
111
|
+
method: 'POST',
|
|
112
|
+
path: '/streams/control',
|
|
113
|
+
permission: rk.names.permWrite,
|
|
114
|
+
handler: async (request, response, active) => {
|
|
115
|
+
let command;
|
|
116
|
+
try { command = parseCommand(request.body); } catch (error) { controlError(error); }
|
|
117
|
+
response.json(await executeControl(active.values(), command));
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
const connectionsRoute = rk.createRouteRegistry({
|
|
121
|
+
method: 'GET',
|
|
122
|
+
path: '/connections',
|
|
123
|
+
permission: rk.names.permRead,
|
|
124
|
+
handler: async (request, response, active) => {
|
|
125
|
+
const id = typeof request.query?.id === 'string' ? request.query.id : undefined;
|
|
126
|
+
const list = [...active.entries()]
|
|
127
|
+
.filter(([configId]) => !id || configId === id)
|
|
128
|
+
.map(([configId, describe]) => ({ id: configId, ...describe() }));
|
|
129
|
+
response.json({ configs: list });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
palette = {
|
|
134
|
+
kit,
|
|
135
|
+
rk,
|
|
136
|
+
registry,
|
|
137
|
+
metrics,
|
|
138
|
+
metricsToken,
|
|
139
|
+
consumers,
|
|
140
|
+
configs,
|
|
141
|
+
completion: createCompletionTracker(RED),
|
|
142
|
+
/** Adds a stream-in consumer to node control and both admin routes. */
|
|
143
|
+
addConsumer(entry) {
|
|
144
|
+
consumers.set(entry.nodeId, entry);
|
|
145
|
+
statusRoute.add(entry.nodeId, entry);
|
|
146
|
+
controlRoute.add(entry.nodeId, entry);
|
|
147
|
+
return () => {
|
|
148
|
+
consumers.delete(entry.nodeId);
|
|
149
|
+
statusRoute.remove(entry.nodeId);
|
|
150
|
+
controlRoute.remove(entry.nodeId);
|
|
151
|
+
};
|
|
152
|
+
},
|
|
153
|
+
addConfig(id, describe) {
|
|
154
|
+
configs.set(id, describe);
|
|
155
|
+
connectionsRoute.add(id, describe);
|
|
156
|
+
return () => {
|
|
157
|
+
configs.delete(id);
|
|
158
|
+
connectionsRoute.remove(id);
|
|
159
|
+
};
|
|
160
|
+
},
|
|
161
|
+
executeControl(command) {
|
|
162
|
+
return executeControl(consumers.values(), parseCommand(command));
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
return palette;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
module.exports = { createPalette, DOMAIN, SETTINGS_TYPE, INTERNAL_PORT };
|
package/lib/slot.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const TABLE = new Uint16Array(256);
|
|
4
|
+
for (let index = 0; index < 256; index += 1) {
|
|
5
|
+
let crc = index << 8;
|
|
6
|
+
for (let bit = 0; bit < 8; bit += 1) {
|
|
7
|
+
crc = crc & 0x8000 ? ((crc << 1) ^ 0x1021) & 0xffff : (crc << 1) & 0xffff;
|
|
8
|
+
}
|
|
9
|
+
TABLE[index] = crc;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function crc16(buffer) {
|
|
13
|
+
let crc = 0;
|
|
14
|
+
for (const byte of buffer) crc = ((crc << 8) & 0xffff) ^ TABLE[((crc >> 8) ^ byte) & 0xff];
|
|
15
|
+
return crc;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Redis Cluster hash slot of a key, honouring {hash tags}.
|
|
20
|
+
* @param {string} key
|
|
21
|
+
* @returns {number}
|
|
22
|
+
*/
|
|
23
|
+
function keySlot(key) {
|
|
24
|
+
let value = String(key);
|
|
25
|
+
const start = value.indexOf('{');
|
|
26
|
+
if (start !== -1) {
|
|
27
|
+
const end = value.indexOf('}', start + 1);
|
|
28
|
+
if (end > start + 1) value = value.slice(start + 1, end);
|
|
29
|
+
}
|
|
30
|
+
return crc16(Buffer.from(value)) % 16384;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = { keySlot, crc16 };
|