relayx-webjs 1.0.0 → 1.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/CHANGELOG.md CHANGED
@@ -1,6 +1,3 @@
1
- V1.0.8
2
- - History API fetch() to consume()
3
-
4
- V1.0.7
5
- - History API added
6
- - README updated to explain history API usage
1
+ V1.0.1
2
+ - Wildcard topics for pub / sub
3
+ - Message replay on reconnection
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "relayx-webjs",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A powerful library for integrating real-time communication into your webapps, powered by the Relay Network.",
5
5
  "main": "realtime/realtime.js",
6
6
  "type": "module",
@@ -734,7 +734,9 @@ export class Realtime {
734
734
  var arrayCheck = ![CONNECTED, DISCONNECTED, RECONNECT, this.#RECONNECTED,
735
735
  this.#RECONNECTING, this.#RECONN_FAIL, MESSAGE_RESEND, SERVER_DISCONNECT].includes(topic);
736
736
 
737
- var spaceStarCheck = !topic.includes(" ") && !topic.includes("*") && !topic.includes(".");
737
+ const TOPIC_REGEX = /^(?!\$)[A-Za-z0-9_,.*>\$-]+$/;
738
+
739
+ var spaceStarCheck = !topic.includes(" ") && TOPIC_REGEX.test(topic);
738
740
 
739
741
  return arrayCheck && spaceStarCheck;
740
742
  }else{
package/tests/test.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Realtime, CONNECTED, RECONNECT, DISCONNECTED, MESSAGE_RESEND } from "../realtime/realtime.js";
2
- import axios from "axios";
3
2
  import { test, before, after } from 'node:test';
4
3
  import assert from 'node:assert';
5
4
 
@@ -8,8 +7,8 @@ let realTimeEnabled;
8
7
  before(async () => {
9
8
  // Start server for testing. Run local server!!
10
9
  realTimeEnabled = new Realtime({
11
- api_key: process.env.user_key,
12
- secret: process.env.secret
10
+ api_key: process.env.AUTH_JWT,
11
+ secret: process.env.AUTH_SECRET
13
12
  });
14
13
  await realTimeEnabled.init(false, {
15
14
  debug: true
@@ -55,8 +54,8 @@ test("No creds in constructor", async () => {
55
54
 
56
55
  test('init() function test', async () => {
57
56
  var realtime = new Realtime({
58
- api_key: process.env.user_key,
59
- secret: process.env.secret
57
+ api_key: process.env.AUTH_JWT,
58
+ secret: process.env.AUTH_SECRET
60
59
  });
61
60
  await realtime.init(true);
62
61
 
@@ -148,8 +147,8 @@ test("Retry method test", async () => {
148
147
 
149
148
  test("get publish retry count test based in init()", async () => {
150
149
  var realtime = new Realtime({
151
- api_key: process.env.user_key,
152
- secret: process.env.secret
150
+ api_key: process.env.AUTH_JWT,
151
+ secret: process.env.AUTH_SECRET
153
152
  });
154
153
 
155
154
  await realtime.init({
@@ -271,8 +270,8 @@ test("Testing publish(topic, data) with invalid inputs", async () => {
271
270
 
272
271
  test("on() test", async () => {
273
272
  var realtime = new Realtime({
274
- api_key: process.env.user_key,
275
- secret: process.env.secret
273
+ api_key: process.env.AUTH_JWT,
274
+ secret: process.env.AUTH_SECRET
276
275
  });
277
276
 
278
277
  await assert.rejects(async () => {
@@ -349,8 +348,8 @@ test("on() test", async () => {
349
348
 
350
349
  test("off() test", async () => {
351
350
  var realtime = new Realtime({
352
- api_key: process.env.user_key,
353
- secret: process.env.secret
351
+ api_key: process.env.AUTH_JWT,
352
+ secret: process.env.AUTH_SECRET
354
353
  });
355
354
 
356
355
  await assert.rejects(async () => {
@@ -397,8 +396,8 @@ test("off() test", async () => {
397
396
 
398
397
  test("Get stream name test", () => {
399
398
  var realtime = new Realtime({
400
- api_key: process.env.user_key,
401
- secret: process.env.secret
399
+ api_key: process.env.AUTH_JWT,
400
+ secret: process.env.AUTH_SECRET
402
401
  });
403
402
 
404
403
  realtime.namespace = "spacex-dragon-program"
@@ -449,7 +448,76 @@ test("Test isTopicValidMethod()", () => {
449
448
  assert.strictEqual(valid, false);
450
449
  });
451
450
 
452
- var unreservedValidTopics = ["hello", "test-room", "heyyyyy", "room-connect"];
451
+ unreservedInvalidTopics = [
452
+ '$internal', // starts with $
453
+ 'hello world', // space
454
+ 'topic/', // slash
455
+ 'name?', // ?
456
+ 'foo#bar', // #
457
+ 'bar.baz!', // !
458
+ ' space', // leading space
459
+ 'tab\tchar', // tab
460
+ 'line\nbreak', // newline
461
+ 'comma ,', // space + comma
462
+ '', // empty string
463
+ 'bad|pipe', // |
464
+ 'semi;colon', // ;
465
+ 'colon:here', // :
466
+ "quote's", // '
467
+ '"doublequote"', // "
468
+ 'brackets[]', // []
469
+ 'brace{}', // {}
470
+ 'paren()', // ()
471
+ 'plus+sign', // +
472
+ 'eq=val', // =
473
+ 'gt>lt<', // < mixed with >
474
+ 'percent%', // %
475
+ 'caret^', // ^
476
+ 'ampersand&', // &
477
+ 'back\\slash', // backslash
478
+ '中文字符', // non‑ASCII
479
+ '👍emoji', // emoji
480
+ 'foo\rbar', // carriage return
481
+ 'end ' // trailing space
482
+ ];
483
+
484
+ unreservedInvalidTopics.forEach(topic => {
485
+ var valid = realTimeEnabled.isTopicValid(topic);
486
+ assert.strictEqual(valid, false);
487
+ });
488
+
489
+ var unreservedValidTopics = [
490
+ 'Orders',
491
+ 'customer_123',
492
+ 'foo-bar',
493
+ 'a,b,c',
494
+ '*',
495
+ 'foo>*',
496
+ 'hello$world',
497
+ 'topic.123',
498
+ 'ABC_def-ghi',
499
+ 'data_stream_2025',
500
+ 'NODE*',
501
+ 'pubsub>events',
502
+ 'log,metric,error',
503
+ 'X123_Y456',
504
+ 'multi.step.topic',
505
+ 'batch-process',
506
+ 'sensor1_data',
507
+ 'finance$Q2',
508
+ 'alpha,beta,gamma',
509
+ 'Z9_Y8-X7',
510
+ 'config>*',
511
+ 'route-map',
512
+ 'STATS_2025-07',
513
+ 'msg_queue*',
514
+ 'update>patch',
515
+ 'pipeline_v2',
516
+ 'FOO$BAR$BAZ',
517
+ 'user.profile',
518
+ 'id_001-xyz',
519
+ 'event_queue>'
520
+ ];
453
521
 
454
522
  unreservedValidTopics.forEach(topic => {
455
523
  var valid = realTimeEnabled.isTopicValid(topic);