@design.estate/dees-comms 1.0.30 → 1.0.31
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/{npmextra.json → .smartconfig.json} +39 -8
- package/dist_bundle/bundle.js +12 -16675
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/dees-comms.classes.deescomms.d.ts +1 -1
- package/dist_ts/dees-comms.classes.deescomms.js +4 -6
- package/package.json +10 -11
- package/readme.md +46 -35
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/dees-comms.classes.deescomms.ts +3 -4
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@design.estate/dees-comms',
|
|
6
|
-
version: '1.0.
|
|
6
|
+
version: '1.0.31',
|
|
7
7
|
description: 'A communications module for enabling DOM-based messaging and synchronization across browser tabs and workers.'
|
|
8
8
|
};
|
|
9
9
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSwyQkFBMkI7SUFDakMsT0FBTyxFQUFFLFFBQVE7SUFDakIsV0FBVyxFQUFFLCtHQUErRztDQUM3SCxDQUFBIn0=
|
|
@@ -4,7 +4,7 @@ import * as plugins from './dees-comms.plugins.js';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare class DeesComms {
|
|
6
6
|
private broadcastChannel;
|
|
7
|
-
typedrouter: plugins.typedrequest.TypedRouter
|
|
7
|
+
typedrouter: plugins.typedrequest.TypedRouter<plugins.typedrequestInterfaces.ITypedRequest>;
|
|
8
8
|
typedtarget: plugins.typedrequest.TypedTarget;
|
|
9
9
|
constructor();
|
|
10
10
|
/**
|
|
@@ -20,16 +20,14 @@ export class DeesComms {
|
|
|
20
20
|
});
|
|
21
21
|
this.broadcastChannel.onmessage = async (eventArg) => {
|
|
22
22
|
const message = eventArg.method ? eventArg : eventArg.data;
|
|
23
|
-
console.log(JSON.stringify(message));
|
|
24
23
|
// Skip hooks for broadcast-received messages to prevent infinite loops
|
|
25
24
|
// when traffic logging hooks are set up globally
|
|
26
|
-
const response = await this.typedrouter.routeAndAddResponse(message, {
|
|
25
|
+
const response = await this.typedrouter.routeAndAddResponse(message, {
|
|
26
|
+
skipHooks: true,
|
|
27
|
+
});
|
|
27
28
|
if (response && !response.error) {
|
|
28
29
|
this.postMessage(response);
|
|
29
30
|
}
|
|
30
|
-
else {
|
|
31
|
-
// console.log(response);
|
|
32
|
-
}
|
|
33
31
|
};
|
|
34
32
|
}
|
|
35
33
|
/**
|
|
@@ -52,4 +50,4 @@ export class DeesComms {
|
|
|
52
50
|
this.typedrouter.addTypedHandler(new plugins.typedrequest.TypedHandler(methodArg, handlerFunction));
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
53
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVlcy1jb21tcy5jbGFzc2VzLmRlZXNjb21tcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL2RlZXMtY29tbXMuY2xhc3Nlcy5kZWVzY29tbXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSx5QkFBeUIsQ0FBQztBQUVuRCxJQUFJLGdCQUFnQixHQUFHLFVBQVUsQ0FBQyxnQkFBZ0IsQ0FBQztBQUNuRCxJQUFJLENBQUMsZ0JBQWdCLEVBQUUsQ0FBQztJQUN0QixnQkFBZ0Is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QzdCLENBQUM7UUFDSCxDQUFDLENBQUM7SUFDSixDQUFDO0lBRUQ7O09BRUc7SUFDSSxrQkFBa0IsQ0FDdkIsVUFBdUI7UUFFdkIsTUFBTSxZQUFZLEdBQUcsSUFBSSxPQUFPLENBQUMsWUFBWSxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsV0FBVyxFQUFFLFVBQVUsQ0FBQyxDQUFDO1FBQ3pGLE9BQU8sWUFBWSxDQUFDO0lBQ3RCLENBQUM7SUFFRDs7T0FFRztJQUNJLEtBQUssQ0FBQyxXQUFXLENBQ3RCLFVBQWE7UUFFYixJQUFJLENBQUMsZ0JBQWdCLENBQUMsV0FBVyxDQUFDLFVBQVUsQ0FBQyxDQUFDO0lBQ2hELENBQUM7SUFFRDs7T0FFRztJQUNJLEtBQUssQ0FBQyxrQkFBa0IsQ0FDN0IsU0FBc0IsRUFDdEIsZUFBeUQ7UUFFekQsSUFBSSxDQUFDLFdBQVcsQ0FBQyxlQUFlLENBQzlCLElBQUksT0FBTyxDQUFDLFlBQVksQ0FBQyxZQUFZLENBQUksU0FBUyxFQUFFLGVBQWUsQ0FBQyxDQUNyRSxDQUFDO0lBQ0osQ0FBQztDQUNGIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@design.estate/dees-comms",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.31",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A communications module for enabling DOM-based messaging and synchronization across browser tabs and workers.",
|
|
6
6
|
"main": "dist_ts/index.js",
|
|
@@ -9,16 +9,15 @@
|
|
|
9
9
|
"author": "Lossless GmbH",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"@git.zone/tsbuild": "^
|
|
13
|
-
"@git.zone/tsbundle": "^2.
|
|
14
|
-
"@git.zone/tsrun": "^2.0.
|
|
15
|
-
"@git.zone/tstest": "^3.
|
|
16
|
-
"@
|
|
17
|
-
"@types/node": "^24.10.1"
|
|
12
|
+
"@git.zone/tsbuild": "^4.4.2",
|
|
13
|
+
"@git.zone/tsbundle": "^2.11.3",
|
|
14
|
+
"@git.zone/tsrun": "^2.0.6",
|
|
15
|
+
"@git.zone/tstest": "^3.6.7",
|
|
16
|
+
"@types/node": "^26.1.1"
|
|
18
17
|
},
|
|
19
18
|
"dependencies": {
|
|
20
|
-
"@api.global/typedrequest": "^3.
|
|
21
|
-
"@api.global/typedrequest-interfaces": "^
|
|
19
|
+
"@api.global/typedrequest": "^3.8.0",
|
|
20
|
+
"@api.global/typedrequest-interfaces": "^4.0.0",
|
|
22
21
|
"@push.rocks/smartdelay": "^3.0.5",
|
|
23
22
|
"broadcast-channel": "^7.2.0"
|
|
24
23
|
},
|
|
@@ -31,7 +30,7 @@
|
|
|
31
30
|
"dist_ts_web/**/*",
|
|
32
31
|
"assets/**/*",
|
|
33
32
|
"cli.js",
|
|
34
|
-
"
|
|
33
|
+
".smartconfig.json",
|
|
35
34
|
"readme.md"
|
|
36
35
|
],
|
|
37
36
|
"browserslist": [
|
|
@@ -51,6 +50,6 @@
|
|
|
51
50
|
],
|
|
52
51
|
"scripts": {
|
|
53
52
|
"test": "(tstest test/ --verbose)",
|
|
54
|
-
"build": "(tsbuild --web
|
|
53
|
+
"build": "(tsbuild --web && tsbundle)"
|
|
55
54
|
}
|
|
56
55
|
}
|
package/readme.md
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
# @design.estate/dees-comms
|
|
2
|
+
|
|
2
3
|
a comms module for communicating within the DOM
|
|
3
4
|
|
|
5
|
+
## Issue Reporting and Security
|
|
6
|
+
|
|
7
|
+
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
|
|
8
|
+
|
|
4
9
|
## Install
|
|
10
|
+
|
|
5
11
|
To integrate `@design.estate/dees-comms` into your project, run the following command in your terminal:
|
|
6
12
|
|
|
7
13
|
```bash
|
|
8
|
-
|
|
14
|
+
pnpm add @design.estate/dees-comms
|
|
9
15
|
```
|
|
10
16
|
|
|
11
17
|
This will add the package to your project dependencies.
|
|
@@ -20,6 +26,16 @@ First, make sure to import the module in your TypeScript file:
|
|
|
20
26
|
|
|
21
27
|
```typescript
|
|
22
28
|
import { DeesComms } from '@design.estate/dees-comms';
|
|
29
|
+
|
|
30
|
+
interface IMyMessage {
|
|
31
|
+
method: 'myMethod';
|
|
32
|
+
request: {
|
|
33
|
+
someData: string;
|
|
34
|
+
};
|
|
35
|
+
response: {
|
|
36
|
+
reply: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
23
39
|
```
|
|
24
40
|
|
|
25
41
|
### Initializing the Communication Module
|
|
@@ -35,21 +51,14 @@ const myDeesComms = new DeesComms();
|
|
|
35
51
|
To send messages, you'll need to create a typed request. Let's assume we are sending a message that requires a response:
|
|
36
52
|
|
|
37
53
|
```typescript
|
|
38
|
-
// Define the message type
|
|
39
|
-
interface MyMessageType {
|
|
40
|
-
method: 'myMethod';
|
|
41
|
-
someData: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
54
|
// Creating a typed request
|
|
45
|
-
const myTypedRequest = myDeesComms.createTypedRequest<
|
|
55
|
+
const myTypedRequest = myDeesComms.createTypedRequest<IMyMessage>('myMethod');
|
|
46
56
|
|
|
47
57
|
// Firing the request
|
|
48
|
-
myTypedRequest.fire({
|
|
58
|
+
const response = await myTypedRequest.fire({
|
|
49
59
|
someData: 'Hello, World!',
|
|
50
|
-
}).then(response => {
|
|
51
|
-
console.log('Received response:', response);
|
|
52
60
|
});
|
|
61
|
+
console.log('Received response:', response.reply);
|
|
53
62
|
```
|
|
54
63
|
|
|
55
64
|
### Receiving and Handling Messages
|
|
@@ -58,14 +67,14 @@ To handle incoming messages, you need to define handlers for the types of messag
|
|
|
58
67
|
|
|
59
68
|
```typescript
|
|
60
69
|
// Define the handler for the 'myMethod' message
|
|
61
|
-
myDeesComms.createTypedHandler<
|
|
62
|
-
console.log('Message received:',
|
|
70
|
+
myDeesComms.createTypedHandler<IMyMessage>('myMethod', async (request) => {
|
|
71
|
+
console.log('Message received:', request.someData);
|
|
63
72
|
|
|
64
73
|
// Process the incoming message...
|
|
65
74
|
|
|
66
75
|
// Return a response (if needed)
|
|
67
76
|
return {
|
|
68
|
-
|
|
77
|
+
reply: 'Message received loud and clear!'
|
|
69
78
|
};
|
|
70
79
|
});
|
|
71
80
|
```
|
|
@@ -74,15 +83,6 @@ myDeesComms.createTypedHandler<MyMessageType>('myMethod', async (incomingMessage
|
|
|
74
83
|
|
|
75
84
|
`@design.estate/dees-comms` uses the Broadcast Channel API and a polyfill for environments where it's not available, enabling seamless communication between different contexts like tabs, iframes, or web workers.
|
|
76
85
|
|
|
77
|
-
### Clean Up
|
|
78
|
-
|
|
79
|
-
When you're done with communication, or before creating a new instance for any reason, ensure you clean up properly to prevent memory leaks or other unexpected behaviors:
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
// Currently, the cleanup should be handled according to the specific needs of your application
|
|
83
|
-
// e.g., closing or nullifying references to the DeesComms instance.
|
|
84
|
-
```
|
|
85
|
-
|
|
86
86
|
### Complete Example
|
|
87
87
|
|
|
88
88
|
Putting it all together, let's create a small application that sends a message and listens for a response:
|
|
@@ -90,38 +90,49 @@ Putting it all together, let's create a small application that sends a message a
|
|
|
90
90
|
```typescript
|
|
91
91
|
import { DeesComms } from '@design.estate/dees-comms';
|
|
92
92
|
|
|
93
|
+
interface IGreetRequest {
|
|
94
|
+
method: 'greet';
|
|
95
|
+
request: {
|
|
96
|
+
name: string;
|
|
97
|
+
};
|
|
98
|
+
response: {
|
|
99
|
+
reply: string;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
93
103
|
const appDeesComms = new DeesComms();
|
|
94
104
|
|
|
95
105
|
// Setting up the listener
|
|
96
|
-
appDeesComms.createTypedHandler<
|
|
97
|
-
console.log(`Greetings received from ${
|
|
98
|
-
return { reply: `Hello ${
|
|
106
|
+
appDeesComms.createTypedHandler<IGreetRequest>('greet', async (request) => {
|
|
107
|
+
console.log(`Greetings received from ${request.name}`);
|
|
108
|
+
return { reply: `Hello ${request.name}, nice to meet you!` };
|
|
99
109
|
});
|
|
100
110
|
|
|
101
111
|
// Sending a greeting message
|
|
102
|
-
const greetRequest = appDeesComms.createTypedRequest<
|
|
103
|
-
greetRequest.fire({ name: 'Alice' })
|
|
104
|
-
|
|
105
|
-
});
|
|
112
|
+
const greetRequest = appDeesComms.createTypedRequest<IGreetRequest>('greet');
|
|
113
|
+
const response = await greetRequest.fire({ name: 'Alice' });
|
|
114
|
+
console.log(response.reply); // Expected output: "Hello Alice, nice to meet you!"
|
|
106
115
|
```
|
|
107
116
|
|
|
108
117
|
This module provides a powerful and flexible way to handle communications within the DOM, leveraging modern JavaScript features and patterns. The usage of TypeScript ensures type safety and enhances code understandability and maintainability.
|
|
109
118
|
|
|
110
119
|
## License and Legal Information
|
|
111
120
|
|
|
112
|
-
This repository contains open-source code
|
|
121
|
+
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the repository license file.
|
|
113
122
|
|
|
114
123
|
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
|
115
124
|
|
|
116
125
|
### Trademarks
|
|
117
126
|
|
|
118
|
-
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein.
|
|
127
|
+
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
|
|
128
|
+
|
|
129
|
+
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
|
|
119
130
|
|
|
120
131
|
### Company Information
|
|
121
132
|
|
|
122
|
-
Task Venture Capital GmbH
|
|
123
|
-
Registered at District
|
|
133
|
+
Task Venture Capital GmbH<br>
|
|
134
|
+
Registered at District Court Bremen HRB 35230 HB, Germany
|
|
124
135
|
|
|
125
|
-
For any legal inquiries or
|
|
136
|
+
For any legal inquiries or further information, please contact us via email at hello@task.vc.
|
|
126
137
|
|
|
127
138
|
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -24,14 +24,13 @@ export class DeesComms {
|
|
|
24
24
|
constructor() {
|
|
25
25
|
this.broadcastChannel.onmessage = async (eventArg) => {
|
|
26
26
|
const message = (eventArg as any).method ? eventArg : eventArg.data;
|
|
27
|
-
console.log(JSON.stringify(message));
|
|
28
27
|
// Skip hooks for broadcast-received messages to prevent infinite loops
|
|
29
28
|
// when traffic logging hooks are set up globally
|
|
30
|
-
const response = await this.typedrouter.routeAndAddResponse(message, {
|
|
29
|
+
const response = await this.typedrouter.routeAndAddResponse(message, {
|
|
30
|
+
skipHooks: true,
|
|
31
|
+
});
|
|
31
32
|
if (response && !response.error) {
|
|
32
33
|
this.postMessage(response);
|
|
33
|
-
} else {
|
|
34
|
-
// console.log(response);
|
|
35
34
|
}
|
|
36
35
|
};
|
|
37
36
|
}
|