@novasamatech/host-chat 0.8.7 → 0.8.8

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,100 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { CoinagePaymentContent, DataChannelAnswerContent, DataChannelClosedContent, DataChannelIceCandidateContent, DataChannelOfferContent, MessageContent, } from './message.js';
3
+ describe('DataChannel content codecs', () => {
4
+ it('DataChannelOfferContent round-trips with AUDIO_CALL purpose', () => {
5
+ const original = {
6
+ sdp: new TextEncoder().encode('v=0\r\no=- 4611...\r\n'),
7
+ purpose: 'AUDIO_CALL',
8
+ };
9
+ const decoded = DataChannelOfferContent.dec(DataChannelOfferContent.enc(original));
10
+ expect(decoded.purpose).toBe('AUDIO_CALL');
11
+ expect(decoded.sdp).toEqual(original.sdp);
12
+ });
13
+ it('DataChannelAnswerContent round-trips', () => {
14
+ const original = { offerMessageId: 'offer-1', sdp: new Uint8Array([0xaa, 0xbb, 0xcc]) };
15
+ const decoded = DataChannelAnswerContent.dec(DataChannelAnswerContent.enc(original));
16
+ expect(decoded).toEqual(original);
17
+ });
18
+ it('DataChannelIceCandidateContent round-trips', () => {
19
+ const original = { offerMessageId: 'offer-1', sdp: new Uint8Array([0xde, 0xad, 0xbe, 0xef]) };
20
+ const decoded = DataChannelIceCandidateContent.dec(DataChannelIceCandidateContent.enc(original));
21
+ expect(decoded).toEqual(original);
22
+ });
23
+ it('DataChannelClosedContent round-trips', () => {
24
+ const original = { offerMessageId: 'offer-1' };
25
+ const decoded = DataChannelClosedContent.dec(DataChannelClosedContent.enc(original));
26
+ expect(decoded).toEqual(original);
27
+ });
28
+ });
29
+ describe('CoinagePaymentContent', () => {
30
+ it('round-trips with a small Balance and a couple of coin keys', () => {
31
+ // scale-ts `compact` decodes to `number` for values ≤ 2^30 and `bigint`
32
+ // for larger ones; normalise to BigInt before asserting.
33
+ const original = {
34
+ totalValue: 1_234_567,
35
+ coinKeys: [new Uint8Array(32).fill(0x11), new Uint8Array(32).fill(0x22)],
36
+ };
37
+ const decoded = CoinagePaymentContent.dec(CoinagePaymentContent.enc(original));
38
+ expect(BigInt(decoded.totalValue)).toBe(1234567n);
39
+ expect(decoded.coinKeys).toHaveLength(2);
40
+ expect(decoded.coinKeys[0]).toEqual(original.coinKeys[0]);
41
+ expect(decoded.coinKeys[1]).toEqual(original.coinKeys[1]);
42
+ });
43
+ it('round-trips a large Balance (forces bigint path)', () => {
44
+ const huge = 2n ** 100n;
45
+ const original = {
46
+ totalValue: huge,
47
+ coinKeys: [new Uint8Array(32).fill(0x33)],
48
+ };
49
+ const decoded = CoinagePaymentContent.dec(CoinagePaymentContent.enc(original));
50
+ expect(BigInt(decoded.totalValue)).toBe(huge);
51
+ });
52
+ it('round-trips with an empty coin-keys list', () => {
53
+ const original = { totalValue: 0, coinKeys: [] };
54
+ const decoded = CoinagePaymentContent.dec(CoinagePaymentContent.enc(original));
55
+ expect(BigInt(decoded.totalValue)).toBe(0n);
56
+ expect(decoded.coinKeys).toEqual([]);
57
+ });
58
+ });
59
+ describe('MessageContent enum discriminants', () => {
60
+ it('coinagePayment lands on discriminant 16 and round-trips inside MessageContent', () => {
61
+ const value = {
62
+ tag: 'coinagePayment',
63
+ value: { totalValue: 42, coinKeys: [new Uint8Array(32).fill(0xab)] },
64
+ };
65
+ const encoded = MessageContent.enc(value);
66
+ expect(encoded[0]).toBe(16);
67
+ const decoded = MessageContent.dec(encoded);
68
+ expect(decoded.tag).toBe('coinagePayment');
69
+ if (decoded.tag !== 'coinagePayment')
70
+ throw new Error('unreachable');
71
+ expect(BigInt(decoded.value.totalValue)).toBe(42n);
72
+ expect(decoded.value.coinKeys[0]).toEqual(value.value.coinKeys[0]);
73
+ });
74
+ it('dataChannelClosed lands on discriminant 11 and round-trips inside MessageContent', () => {
75
+ const value = {
76
+ tag: 'dataChannelClosed',
77
+ value: { offerMessageId: 'offer-x' },
78
+ };
79
+ const encoded = MessageContent.enc(value);
80
+ expect(encoded[0]).toBe(11);
81
+ const decoded = MessageContent.dec(encoded);
82
+ expect(decoded.tag).toBe('dataChannelClosed');
83
+ if (decoded.tag !== 'dataChannelClosed')
84
+ throw new Error('unreachable');
85
+ expect(decoded.value.offerMessageId).toBe('offer-x');
86
+ });
87
+ it('dataChannelOffer lands on discriminant 8 and round-trips inside MessageContent', () => {
88
+ const value = {
89
+ tag: 'dataChannelOffer',
90
+ value: { sdp: new Uint8Array([1, 2, 3]), purpose: 'VIDEO_CALL' },
91
+ };
92
+ const encoded = MessageContent.enc(value);
93
+ expect(encoded[0]).toBe(8);
94
+ const decoded = MessageContent.dec(encoded);
95
+ if (decoded.tag !== 'dataChannelOffer')
96
+ throw new Error('unreachable');
97
+ expect(decoded.value.purpose).toBe('VIDEO_CALL');
98
+ expect(decoded.value.sdp).toEqual(value.value.sdp);
99
+ });
100
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/host-chat",
3
3
  "type": "module",
4
- "version": "0.8.7",
4
+ "version": "0.8.8",
5
5
  "description": "Host statement store chat integration",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -40,9 +40,9 @@
40
40
  "README.md"
41
41
  ],
42
42
  "dependencies": {
43
- "@novasamatech/scale": "0.8.7",
44
- "@novasamatech/statement-store": "0.8.7",
45
- "@novasamatech/storage-adapter": "0.8.7",
43
+ "@novasamatech/scale": "0.8.8",
44
+ "@novasamatech/statement-store": "0.8.8",
45
+ "@novasamatech/storage-adapter": "0.8.8",
46
46
  "nanoid": "5.1.11",
47
47
  "neverthrow": "^8.2.0"
48
48
  },