@typexim/web-sdk 0.0.7 → 0.0.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.
Files changed (45) hide show
  1. package/README.md +2 -1
  2. package/dist/types/enums/sdk.d.ts +0 -1
  3. package/dist/types/modules/ChatSDK.d.ts +3 -2
  4. package/dist/types/modules/ReConnectWebsocket.d.ts +3 -0
  5. package/dist/types/modules/TabSessionCoordinator.d.ts +9 -5
  6. package/dist/types/utils/websocket.d.ts +4 -0
  7. package/dist/web-sdk.esm.js +1 -1
  8. package/dist/web-sdk.js +1 -1
  9. package/dist-test/enums/business.js +139 -0
  10. package/dist-test/enums/index.js +2 -0
  11. package/dist-test/enums/sdk.js +24 -0
  12. package/dist-test/events.js +50 -0
  13. package/dist-test/index.js +26 -0
  14. package/dist-test/interfaces/business.js +1 -0
  15. package/dist-test/interfaces/index.js +3 -0
  16. package/dist-test/interfaces/pushMessage.js +1 -0
  17. package/dist-test/interfaces/sdk/api.js +1 -0
  18. package/dist-test/interfaces/sdk/common.js +1 -0
  19. package/dist-test/interfaces/sdk/index.js +2 -0
  20. package/dist-test/modules/Base.js +70 -0
  21. package/dist-test/modules/BusinessWebsocket.js +68 -0
  22. package/dist-test/modules/ChatSDK.js +698 -0
  23. package/dist-test/modules/FeedCache.js +211 -0
  24. package/dist-test/modules/HttpClient.js +104 -0
  25. package/dist-test/modules/Logger.js +73 -0
  26. package/dist-test/modules/PushMessageProcessor.js +437 -0
  27. package/dist-test/modules/ReConnectWebsocket.js +223 -0
  28. package/dist-test/modules/Storage.js +27 -0
  29. package/dist-test/modules/TabSessionCoordinator.js +289 -0
  30. package/dist-test/modules/Version.js +20 -0
  31. package/dist-test/utils/date.js +4 -0
  32. package/dist-test/utils/http.js +13 -0
  33. package/dist-test/utils/makeSign.js +79 -0
  34. package/dist-test/utils/message.js +146 -0
  35. package/dist-test/utils/misc.js +13 -0
  36. package/dist-test/utils/promise.js +10 -0
  37. package/dist-test/utils/sleep.js +3 -0
  38. package/dist-test/utils/websocket.js +24 -0
  39. package/package.json +1 -1
  40. package/test/{chat-sdk-restore-login.test.mjs → chat-sdk-independent-login.test.mjs} +50 -62
  41. package/test/chat-sdk-session-restore.test.mjs +331 -0
  42. package/test/tab-session-coordinator.test.mjs +65 -64
  43. package/test/websocket-url.test.mjs +24 -0
  44. package/dist/types/modules/SingletonLock.d.ts +0 -12
  45. package/test/singleton-lock.test.mjs +0 -75
@@ -1,75 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { test } from 'node:test';
3
-
4
- import SingletonLock from '../dist-test/modules/SingletonLock.js';
5
-
6
- function installMockLocks(sequence) {
7
- let callIndex = 0;
8
- Object.defineProperty(globalThis, 'navigator', {
9
- configurable: true,
10
- value: {
11
- locks: {
12
- request: (_name, _options, callback) => {
13
- const available = sequence[Math.min(callIndex, sequence.length - 1)];
14
- callIndex += 1;
15
- Promise.resolve().then(() => callback(available ? {} : null));
16
- },
17
- },
18
- },
19
- });
20
- }
21
-
22
- function installNavigator(value) {
23
- Object.defineProperty(globalThis, 'navigator', {
24
- configurable: true,
25
- value,
26
- });
27
- }
28
-
29
- test('requestLock retries until an old tab releases the singleton lock', async () => {
30
- installMockLocks([false, false, true]);
31
-
32
- const lock = new SingletonLock();
33
- const obtained = await lock.requestLock({
34
- retryIntervalMs: 1,
35
- timeoutMs: 50,
36
- });
37
-
38
- assert.equal(obtained, true);
39
- });
40
-
41
- test('requestLock gives up when the old tab does not release in time', async () => {
42
- installMockLocks([false]);
43
-
44
- const lock = new SingletonLock();
45
- const obtained = await lock.requestLock({
46
- retryIntervalMs: 1,
47
- timeoutMs: 5,
48
- });
49
-
50
- assert.equal(obtained, false);
51
- });
52
-
53
- test('requestLock fails closed when Web Locks is unavailable', async () => {
54
- installNavigator({});
55
-
56
- const lock = new SingletonLock();
57
- const obtained = await lock.requestLock();
58
-
59
- assert.equal(obtained, false);
60
- });
61
-
62
- test('requestLock fails closed when Web Locks throws', async () => {
63
- installNavigator({
64
- locks: {
65
- request: () => {
66
- throw new Error('locks unavailable');
67
- },
68
- },
69
- });
70
-
71
- const lock = new SingletonLock();
72
- const obtained = await lock.requestLock();
73
-
74
- assert.equal(obtained, false);
75
- });