rx-postmessenger 3.0.0 → 4.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/README.md +77 -64
- package/{esm → dist}/MessageFactory.d.ts +1 -1
- package/dist/MessageFactory.js +34 -0
- package/{esm → dist}/MessageIDGenerator.d.ts +1 -1
- package/dist/MessageIDGenerator.js +19 -0
- package/{cjs → dist}/MessageValidator.d.ts +3 -3
- package/{esm → dist}/MessageValidator.js +19 -19
- package/{esm → dist}/Messenger.d.ts +6 -6
- package/dist/Messenger.js +79 -0
- package/{cjs → dist}/PostmessageAdapter.d.ts +1 -1
- package/dist/PostmessageAdapter.js +11 -0
- package/{esm → dist}/RxPostmessengerRequest.d.ts +4 -4
- package/dist/RxPostmessengerRequest.js +23 -0
- package/dist/functions/GUIDGenerator.js +10 -0
- package/dist/index.d.ts +4 -0
- package/{esm → dist}/index.js +8 -8
- package/{rx-postmessenger.d.ts → dist/public-api.d.ts} +11 -31
- package/{esm → dist}/types.d.ts +6 -6
- package/dist/types.js +1 -0
- package/package.json +33 -35
- package/CHANGELOG.md +0 -169
- package/cjs/MessageFactory.d.ts +0 -9
- package/cjs/MessageFactory.js +0 -38
- package/cjs/MessageIDGenerator.d.ts +0 -8
- package/cjs/MessageIDGenerator.js +0 -24
- package/cjs/MessageValidator.js +0 -44
- package/cjs/Messenger.d.ts +0 -52
- package/cjs/Messenger.js +0 -69
- package/cjs/PostmessageAdapter.js +0 -14
- package/cjs/RxPostmessengerRequest.d.ts +0 -11
- package/cjs/RxPostmessengerRequest.js +0 -28
- package/cjs/functions/GUIDGenerator.js +0 -59
- package/cjs/index.d.ts +0 -3
- package/cjs/index.js +0 -16
- package/cjs/types.d.ts +0 -58
- package/cjs/types.js +0 -2
- package/esm/MessageFactory.js +0 -35
- package/esm/MessageIDGenerator.js +0 -21
- package/esm/MessageValidator.d.ts +0 -29
- package/esm/Messenger.js +0 -66
- package/esm/PostmessageAdapter.d.ts +0 -7
- package/esm/PostmessageAdapter.js +0 -11
- package/esm/RxPostmessengerRequest.js +0 -25
- package/esm/functions/GUIDGenerator.d.ts +0 -1
- package/esm/functions/GUIDGenerator.js +0 -55
- package/esm/index.d.ts +0 -3
- package/jest.config.js +0 -10
- package/typedoc.json +0 -6
- package/umd/rx-postmessenger.js +0 -2069
- package/umd/rx-postmessenger.js.map +0 -1
- package/umd/rx-postmessenger.min.js +0 -2
- package/umd/rx-postmessenger.min.js.map +0 -1
- /package/{cjs → dist}/functions/GUIDGenerator.d.ts +0 -0
- /package/{esm/types.js → dist/public-api.js} +0 -0
|
@@ -1,75 +1,55 @@
|
|
|
1
|
-
import type { Observable } from 'rxjs'
|
|
2
|
-
|
|
3
|
-
declare const RxPostmessenger: Static
|
|
4
|
-
export default RxPostmessenger
|
|
5
|
-
export as namespace RxPostmessenger
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
8
2
|
export interface Static {
|
|
9
3
|
/**
|
|
10
4
|
* Create a new messenger for given window object. The remoteOrigin URL is used both to give to window.postMessage
|
|
11
5
|
* calls on remoteWindow, and to filter inbound-message-events on the local window object.
|
|
12
6
|
*/
|
|
13
|
-
connect(remoteWindow: Window, remoteOrigin: string): Messenger
|
|
7
|
+
connect(remoteWindow: Window, remoteOrigin: string): Messenger;
|
|
14
8
|
}
|
|
15
|
-
|
|
16
9
|
export interface Messenger {
|
|
17
|
-
|
|
18
10
|
/**
|
|
19
11
|
* Returns an Observable that emits all incoming notifications for given notification-channel.
|
|
20
12
|
*/
|
|
21
|
-
notifications<T = any>(channel: string): Observable<T
|
|
22
|
-
|
|
13
|
+
notifications<T = any>(channel: string): Observable<T>;
|
|
23
14
|
/**
|
|
24
15
|
* Send a notification over given channel with given payload.
|
|
25
16
|
*/
|
|
26
|
-
notify<T>(channel: string, payload?: T): void
|
|
27
|
-
|
|
17
|
+
notify<T>(channel: string, payload?: T): void;
|
|
28
18
|
/**
|
|
29
19
|
* Send a request over given channel with given payload. Returns an observable that will emit the response
|
|
30
20
|
* and then complete.
|
|
31
21
|
*/
|
|
32
|
-
request<T = any, U = any>(channel: string, payload?: T): Observable<U
|
|
33
|
-
|
|
22
|
+
request<T = any, U = any>(channel: string, payload?: T): Observable<U>;
|
|
34
23
|
/**
|
|
35
24
|
* Returns an Observable that emits all incoming requests for given request-channel.
|
|
36
25
|
*/
|
|
37
|
-
requests<T = any, U = any>(channel: string): Observable<Request<T, U
|
|
26
|
+
requests<T = any, U = any>(channel: string): Observable<Request<T, U>>;
|
|
38
27
|
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
*
|
|
42
|
-
*/
|
|
43
28
|
export interface Request<T, U> {
|
|
44
|
-
|
|
45
29
|
/**
|
|
46
30
|
* The name of the channel the request was sent through. The
|
|
47
31
|
* channel literal is immutable. Attempts to override the
|
|
48
32
|
* channel property
|
|
49
33
|
*/
|
|
50
|
-
readonly channel: string
|
|
51
|
-
|
|
34
|
+
readonly channel: string;
|
|
52
35
|
/**
|
|
53
36
|
* The payload data for the request. The payload is immutable.
|
|
54
37
|
* Attempts to set / override payload values will silently fail.
|
|
55
38
|
* Attempts to mutate members of object-type payloads will
|
|
56
39
|
* silently fail as well.
|
|
57
40
|
*/
|
|
58
|
-
readonly payload: T
|
|
59
|
-
|
|
41
|
+
readonly payload: T;
|
|
60
42
|
/**
|
|
61
43
|
* Boolean indicating whether respond() has been called on the request
|
|
62
44
|
* previously.
|
|
63
45
|
*/
|
|
64
|
-
readonly isHandled: boolean
|
|
65
|
-
|
|
46
|
+
readonly isHandled: boolean;
|
|
66
47
|
/**
|
|
67
48
|
* The unique ID of the request.
|
|
68
49
|
*/
|
|
69
|
-
readonly id: string
|
|
70
|
-
|
|
50
|
+
readonly id: string;
|
|
71
51
|
/**
|
|
72
52
|
* Respond to the request with given data.
|
|
73
53
|
*/
|
|
74
|
-
respond(data: U): void
|
|
54
|
+
respond(data: U): void;
|
|
75
55
|
}
|
package/{esm → dist}/types.d.ts
RENAMED
|
@@ -31,14 +31,14 @@ export interface IResponseObject<T = any> extends IMessageObject<T> {
|
|
|
31
31
|
export interface INotificationObject<T = any> extends IMessageObject<T> {
|
|
32
32
|
readonly type: 'notification';
|
|
33
33
|
}
|
|
34
|
-
export
|
|
34
|
+
export type AnyMessage = IRequestObject | IResponseObject | INotificationObject;
|
|
35
35
|
export interface IMessageTypeMap<T = any> {
|
|
36
|
-
request: IRequestObject
|
|
37
|
-
response: IResponseObject
|
|
38
|
-
notification: INotificationObject
|
|
36
|
+
request: IRequestObject<T>;
|
|
37
|
+
response: IResponseObject<T>;
|
|
38
|
+
notification: INotificationObject<T>;
|
|
39
39
|
}
|
|
40
|
-
export
|
|
41
|
-
export
|
|
40
|
+
export type MessageType = keyof IMessageTypeMap;
|
|
41
|
+
export type MappedMessage<T extends MessageType> = IMessageTypeMap[T];
|
|
42
42
|
export interface IMessageFactory {
|
|
43
43
|
invalidateID(id: string): void;
|
|
44
44
|
makeRequest<T>(channel: string, payload: T): IRequestObject<T>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rx-postmessenger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"author": "Jeffrey Westerkamp",
|
|
5
5
|
"repository": "git+https://github.com/JJWesterkamp/rx-postmessenger.git",
|
|
6
6
|
"description": "Minimal RxJS adapter for the window.postMessage API for request-response streams and notification streams across frame windows.",
|
|
@@ -16,50 +16,48 @@
|
|
|
16
16
|
"typescript"
|
|
17
17
|
],
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"main": "./
|
|
20
|
-
"module": "./
|
|
21
|
-
"types": "./
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"module": "./dist/index.js",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
-
"
|
|
25
|
-
"import": "./
|
|
26
|
-
"default": "./esm/index.js"
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
27
26
|
}
|
|
28
27
|
},
|
|
29
|
-
"unpkg": "umd/rx-postmessenger.min.js",
|
|
30
|
-
"jsdelivr": "umd/rx-postmessenger.min.js",
|
|
31
28
|
"scripts": {
|
|
32
|
-
"clean:dist": "rm -rf
|
|
29
|
+
"clean:dist": "rm -rf dist",
|
|
33
30
|
"clean:coverage": "rm -rf coverage",
|
|
34
|
-
"dev": "
|
|
35
|
-
"build": "npm run clean:dist &&
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"coveralls": "cat ./coverage/lcov.info | coveralls"
|
|
31
|
+
"dev": "tsc --project tsconfig.app.json --watch",
|
|
32
|
+
"build": "npm run clean:dist && tsc --project tsconfig.app.json",
|
|
33
|
+
"check": "tsc --project tsconfig.app.json --noEmit && tsc --project tsconfig.spec.json",
|
|
34
|
+
"prepublishOnly": "npm run check && npm test && npm run build",
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"test:watch": "vitest",
|
|
37
|
+
"test:coverage": "vitest run --coverage",
|
|
38
|
+
"fmt": "oxfmt --check",
|
|
39
|
+
"lint": "oxlint",
|
|
40
|
+
"lint:fix": "oxfmt && oxlint --fix"
|
|
45
41
|
},
|
|
46
42
|
"peerDependencies": {
|
|
47
43
|
"rxjs": "6.x || 7.x"
|
|
48
44
|
},
|
|
49
45
|
"devDependencies": {
|
|
50
|
-
"@
|
|
51
|
-
"@
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
"
|
|
63
|
-
|
|
46
|
+
"@types/node": "^26.6.6",
|
|
47
|
+
"@vitest/coverage-v8": "^5.1.1",
|
|
48
|
+
"jsdom": "^31.0.1",
|
|
49
|
+
"oxfmt": "0.80.0",
|
|
50
|
+
"oxlint": "1.95.0",
|
|
51
|
+
"oxlint-tsgolint": "7.0.2008",
|
|
52
|
+
"rxjs": "^7.8.2",
|
|
53
|
+
"typescript": "^7.0.2",
|
|
54
|
+
"vitest": "^5.1.1"
|
|
55
|
+
},
|
|
56
|
+
"type": "module",
|
|
57
|
+
"files": [
|
|
58
|
+
"dist"
|
|
59
|
+
],
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
|
64
62
|
}
|
|
65
63
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
[](https://badge.fury.io/js/rx-postmessenger)
|
|
3
|
-
|
|
4
|
-
All notable changes to `rx-postmessenger` will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
|
-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
-
|
|
7
|
-
## [Unreleased]
|
|
8
|
-
|
|
9
|
-
## [3.0.0] (2021-08-17)
|
|
10
|
-
|
|
11
|
-
### BREAKING CHANGES
|
|
12
|
-
- Made RxJS a peer dependency
|
|
13
|
-
> I'm not entirely sure if this is breaking from a user point-of-view, but I made this a
|
|
14
|
-
> major release just to be sure.
|
|
15
|
-
|
|
16
|
-
### Changed
|
|
17
|
-
- Added support for RxJS 7
|
|
18
|
-
- Many internal changes: dependencies, test suite, etc.
|
|
19
|
-
|
|
20
|
-
## [2.0.1] (2019-06-22)
|
|
21
|
-
- Updated all npm dev-dependencies latest versions, fixing vulnerability issues reported by Github.
|
|
22
|
-
|
|
23
|
-
## [2.0.0] (2019-05-27)
|
|
24
|
-
### Changed
|
|
25
|
-
- Documented alpha.1 changes in README.
|
|
26
|
-
|
|
27
|
-
## [2.0.0-alpha.1] (2019-01-06)
|
|
28
|
-
### BREAKING CHANGES
|
|
29
|
-
- **Removed EventMap feature**
|
|
30
|
-
|
|
31
|
-
This proved to be unmaintainable in terms of type-mapping in private implementations
|
|
32
|
-
and also made the package less 'portable'. Payload type constraints are from now on
|
|
33
|
-
enforced directly on Messenger method calls.
|
|
34
|
-
|
|
35
|
-
- **RxJS v6**
|
|
36
|
-
|
|
37
|
-
Upgraded the RxJS dependency from v5 to v6.
|
|
38
|
-
|
|
39
|
-
- **Removed `Static.useObservable()` and `Static.getObservable()`**
|
|
40
|
-
|
|
41
|
-
These methods are obsolete as of RxJS v6, as the Observable operators are no longer
|
|
42
|
-
provided through prototype patching, but explicitly supplied with `Observable.pipe()`.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
## [1.0.4] (2019-01-06)
|
|
46
|
-
### Added
|
|
47
|
-
- 🧪 Test suite
|
|
48
|
-
- Added TravisCI Build status to README
|
|
49
|
-
|
|
50
|
-
### Changed
|
|
51
|
-
- Major refactor of package internals: better SOC and adherence to SRP.
|
|
52
|
-
- Refactor public interface definition of EventMap structure.
|
|
53
|
-
|
|
54
|
-
## [1.0.3] (2018-05-15)
|
|
55
|
-
### Changed
|
|
56
|
-
- Internal naming of TS interfaces.
|
|
57
|
-
- Documentation of Public interface in `rx-postmessenger.d.ts`
|
|
58
|
-
|
|
59
|
-
## [1.0.2] (2018-03-17)
|
|
60
|
-
README update only.
|
|
61
|
-
|
|
62
|
-
## [1.0.1] (2018-03-17)
|
|
63
|
-
README update only.
|
|
64
|
-
|
|
65
|
-
## [1.0.0] (2018-03-12)
|
|
66
|
-
No code changes.
|
|
67
|
-
|
|
68
|
-
### Added
|
|
69
|
-
- LICENSE file
|
|
70
|
-
|
|
71
|
-
## [1.0.0-beta.1] (2018-01-14)
|
|
72
|
-
README update only.
|
|
73
|
-
|
|
74
|
-
## [0.2.1] (2018-01-01)
|
|
75
|
-
### Fixed
|
|
76
|
-
- npm distribution config: rename CommonJS build folder
|
|
77
|
-
- npm distribution config: ignore `/src` folder
|
|
78
|
-
|
|
79
|
-
## [0.2.0] (2018-01-01)
|
|
80
|
-
### Added
|
|
81
|
-
- Support for mapping event-channel names to payload types
|
|
82
|
-
|
|
83
|
-
## [0.1.12] (2017-12-07)
|
|
84
|
-
README update only.
|
|
85
|
-
|
|
86
|
-
## [0.1.11] (2017-12-07)
|
|
87
|
-
README update only.
|
|
88
|
-
|
|
89
|
-
## [0.1.10] (2017-12-07)
|
|
90
|
-
|
|
91
|
-
### Changed
|
|
92
|
-
- **TS declaration pointer** Package now relies on the dedicated declaration file and no longer generates declarations for CommonJS builds.
|
|
93
|
-
## [0.1.9] (2017-12-07)
|
|
94
|
-
General development, no notable changes
|
|
95
|
-
|
|
96
|
-
## [0.1.8] (2017-12-02)
|
|
97
|
-
|
|
98
|
-
### Fixed
|
|
99
|
-
- README error: Code example accessing properties in the wrong way.
|
|
100
|
-
|
|
101
|
-
## [0.1.7] (2017-12-01)
|
|
102
|
-
### Added
|
|
103
|
-
- Method to override the used RxJS Observable implementation allowing for custom sets of prototype methods.
|
|
104
|
-
|
|
105
|
-
## 0.1.6 (2018-12-01) [YANKED]
|
|
106
|
-
## [0.1.5] (2017-11-29)
|
|
107
|
-
|
|
108
|
-
### Changed
|
|
109
|
-
- Use full build of RxJS for faster development
|
|
110
|
-
- README content
|
|
111
|
-
|
|
112
|
-
## [0.1.4] (2017-11-28)
|
|
113
|
-
|
|
114
|
-
### Added
|
|
115
|
-
- Initial (serious) README content
|
|
116
|
-
|
|
117
|
-
### Changed
|
|
118
|
-
- Signature of `RxPostmessenger ~ createMessageObject`
|
|
119
|
-
|
|
120
|
-
## [0.1.3] (2017-11-27)
|
|
121
|
-
|
|
122
|
-
### Changed
|
|
123
|
-
- Messenger methods visibility + other development
|
|
124
|
-
- Package.json meta info
|
|
125
|
-
|
|
126
|
-
## [0.1.2] (2017-11-26)
|
|
127
|
-
|
|
128
|
-
### Added
|
|
129
|
-
- Minified and non-minified UMD bundle builds
|
|
130
|
-
|
|
131
|
-
### Changed
|
|
132
|
-
- Temporarily removed `/src` from gitignore
|
|
133
|
-
|
|
134
|
-
## [0.1.1] (2017-11-26)
|
|
135
|
-
|
|
136
|
-
### Fixed
|
|
137
|
-
- Wrong value for `"main""` entry in package.json.
|
|
138
|
-
|
|
139
|
-
## [0.1.0] (2017-11-26, initial release)
|
|
140
|
-
|
|
141
|
-
### Added
|
|
142
|
-
- Bade messenger class
|
|
143
|
-
- Project setup (builds, configuration etc.)
|
|
144
|
-
|
|
145
|
-
[Unreleased]: https://github.com/PXLWidgets/php-composer-version/compare/v3.0.0...HEAD
|
|
146
|
-
[3.0.0]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v2.0.0...v3.0.0
|
|
147
|
-
[2.0.1]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v2.0.0...v2.0.1
|
|
148
|
-
[2.0.0]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v2.0.0-alpha.1...v2.0.0
|
|
149
|
-
[2.0.0-alpha.1]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v1.0.4...v2.0.0-alpha.1
|
|
150
|
-
[1.0.4]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v1.0.3...v1.0.4
|
|
151
|
-
[1.0.3]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v1.0.2...v1.0.3
|
|
152
|
-
[1.0.2]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v1.0.1...v1.0.2
|
|
153
|
-
[1.0.1]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v1.0.0...v1.0.1
|
|
154
|
-
[1.0.0]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v1.0.0-beta.1...v1.0.0
|
|
155
|
-
[1.0.0-beta.1]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.2.1...v1.0.0-beta.1
|
|
156
|
-
[0.2.1]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.2.0...v0.2.1
|
|
157
|
-
[0.2.0]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.1.12...v0.2.0
|
|
158
|
-
[0.1.12]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.1.11...v0.1.12
|
|
159
|
-
[0.1.11]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.1.10...v0.1.11
|
|
160
|
-
[0.1.10]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.1.9...v0.1.10
|
|
161
|
-
[0.1.9]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.1.8...v0.1.9
|
|
162
|
-
[0.1.8]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.1.7...v0.1.8
|
|
163
|
-
[0.1.7]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.1.5...v0.1.7
|
|
164
|
-
[0.1.5]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.1.4...v0.1.5
|
|
165
|
-
[0.1.4]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.1.3...v0.1.4
|
|
166
|
-
[0.1.3]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.1.2...v0.1.3
|
|
167
|
-
[0.1.2]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.1.1...v0.1.2
|
|
168
|
-
[0.1.1]: https://github.com/JJWesterkamp/rx-postmessenger/compare/v0.1.0...v0.1.1
|
|
169
|
-
[0.1.0]: https://github.com/JJWesterkamp/rx-postmessenger/tree/v0.1.0
|
package/cjs/MessageFactory.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { IMessageFactory, IMessageIDGenerator, INotificationObject, IRequestObject, IResponseObject } from './types';
|
|
2
|
-
export declare class MessageFactory implements IMessageFactory {
|
|
3
|
-
protected readonly IDGenerator: IMessageIDGenerator;
|
|
4
|
-
constructor(IDGenerator: IMessageIDGenerator);
|
|
5
|
-
makeNotification<T>(channel: string, payload: T): INotificationObject<T>;
|
|
6
|
-
makeRequest<T>(channel: string, payload: T): IRequestObject<T>;
|
|
7
|
-
makeResponse<T>(requestId: string, channel: string, payload: T): IResponseObject<T>;
|
|
8
|
-
invalidateID(id: string): void;
|
|
9
|
-
}
|
package/cjs/MessageFactory.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MessageFactory = void 0;
|
|
4
|
-
var MessageFactory = /** @class */ (function () {
|
|
5
|
-
function MessageFactory(IDGenerator) {
|
|
6
|
-
this.IDGenerator = IDGenerator;
|
|
7
|
-
}
|
|
8
|
-
MessageFactory.prototype.makeNotification = function (channel, payload) {
|
|
9
|
-
return {
|
|
10
|
-
channel: channel,
|
|
11
|
-
id: this.IDGenerator.generateID(),
|
|
12
|
-
payload: payload,
|
|
13
|
-
type: 'notification',
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
MessageFactory.prototype.makeRequest = function (channel, payload) {
|
|
17
|
-
return {
|
|
18
|
-
channel: channel,
|
|
19
|
-
id: this.IDGenerator.generateID(),
|
|
20
|
-
payload: payload,
|
|
21
|
-
type: 'request',
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
MessageFactory.prototype.makeResponse = function (requestId, channel, payload) {
|
|
25
|
-
return {
|
|
26
|
-
channel: channel,
|
|
27
|
-
id: this.IDGenerator.generateID(),
|
|
28
|
-
payload: payload,
|
|
29
|
-
requestId: requestId,
|
|
30
|
-
type: 'response',
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
MessageFactory.prototype.invalidateID = function (id) {
|
|
34
|
-
this.IDGenerator.invalidateID(id);
|
|
35
|
-
};
|
|
36
|
-
return MessageFactory;
|
|
37
|
-
}());
|
|
38
|
-
exports.MessageFactory = MessageFactory;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { IMessageIDGenerator } from './types';
|
|
2
|
-
export declare class MessageIDGenerator implements IMessageIDGenerator {
|
|
3
|
-
protected readonly gen: Iterator<string>;
|
|
4
|
-
protected readonly usedIDValues: string[];
|
|
5
|
-
constructor(gen?: Iterator<string>);
|
|
6
|
-
generateID(): string;
|
|
7
|
-
invalidateID(id: string): void;
|
|
8
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MessageIDGenerator = void 0;
|
|
4
|
-
var GUIDGenerator_1 = require("./functions/GUIDGenerator");
|
|
5
|
-
var MessageIDGenerator = /** @class */ (function () {
|
|
6
|
-
function MessageIDGenerator(gen) {
|
|
7
|
-
if (gen === void 0) { gen = GUIDGenerator_1.GUIDGenerator(); }
|
|
8
|
-
this.gen = gen;
|
|
9
|
-
this.usedIDValues = [];
|
|
10
|
-
}
|
|
11
|
-
MessageIDGenerator.prototype.generateID = function () {
|
|
12
|
-
var newID;
|
|
13
|
-
do {
|
|
14
|
-
newID = this.gen.next().value;
|
|
15
|
-
} while (this.usedIDValues.indexOf(newID) >= 0);
|
|
16
|
-
this.invalidateID(newID);
|
|
17
|
-
return newID;
|
|
18
|
-
};
|
|
19
|
-
MessageIDGenerator.prototype.invalidateID = function (id) {
|
|
20
|
-
this.usedIDValues.push(id);
|
|
21
|
-
};
|
|
22
|
-
return MessageIDGenerator;
|
|
23
|
-
}());
|
|
24
|
-
exports.MessageIDGenerator = MessageIDGenerator;
|
package/cjs/MessageValidator.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MessageValidator = void 0;
|
|
4
|
-
var MessageValidator = /** @class */ (function () {
|
|
5
|
-
function MessageValidator(acceptedSource, acceptedOrigin) {
|
|
6
|
-
this.acceptedSource = acceptedSource;
|
|
7
|
-
this.acceptedOrigin = acceptedOrigin;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Validates the identity of the message's sender and the format of the message's data.
|
|
11
|
-
*
|
|
12
|
-
* Checks whether the remoteOrigin location matches any allowed origins.
|
|
13
|
-
* Separate assertion of the remoteOrigin allows for cross-domain navigation
|
|
14
|
-
* within this.frame, and still treating inbound messages from the
|
|
15
|
-
* frame as being equal.
|
|
16
|
-
*
|
|
17
|
-
* Checks whether the source Window object equals the remoteWindow object.
|
|
18
|
-
* This check allows for implementation of multiple i-frames that share the
|
|
19
|
-
* same remoteOrigin, and still being able to distinguish between messages from
|
|
20
|
-
* such frames.
|
|
21
|
-
*/
|
|
22
|
-
MessageValidator.prototype.validate = function (message) {
|
|
23
|
-
return message instanceof MessageEvent
|
|
24
|
-
&& message.origin === this.acceptedOrigin
|
|
25
|
-
&& message.source === this.acceptedSource
|
|
26
|
-
&& this.isWellFormedMessage(message.data);
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Tests whether the data sent through postMessage is a well-formed message
|
|
30
|
-
* object. This serves as runtime data format validation. If messages do not
|
|
31
|
-
* comply to the AnyMessage compound interface, the entire event is ignored.
|
|
32
|
-
*
|
|
33
|
-
* @param {*} message
|
|
34
|
-
* @return {boolean}
|
|
35
|
-
*/
|
|
36
|
-
MessageValidator.prototype.isWellFormedMessage = function (message) {
|
|
37
|
-
return (typeof message.id === 'string')
|
|
38
|
-
&& (['request', 'response', 'notification'].indexOf(message.type) >= 0)
|
|
39
|
-
&& (typeof message.channel === 'string')
|
|
40
|
-
&& (message.type !== 'response' || (typeof message.requestId === 'string'));
|
|
41
|
-
};
|
|
42
|
-
return MessageValidator;
|
|
43
|
-
}());
|
|
44
|
-
exports.MessageValidator = MessageValidator;
|
package/cjs/Messenger.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { Messenger as IMessenger, Request } from '../rx-postmessenger';
|
|
2
|
-
import type { AnyMessage, INotificationObject, IRequestObject, IResponseObject, MappedMessage, MessageType, IMessageFactory, IMessageValidator, IPostmessageAdapter } from './types';
|
|
3
|
-
import { Observable } from 'rxjs';
|
|
4
|
-
export declare class Messenger implements IMessenger {
|
|
5
|
-
protected readonly messageFactory: IMessageFactory;
|
|
6
|
-
protected readonly messageValidator: IMessageValidator;
|
|
7
|
-
protected readonly adapter: IPostmessageAdapter;
|
|
8
|
-
/**
|
|
9
|
-
* Observable stream of all incoming messages that originate from remoteWindow with a
|
|
10
|
-
* remoteOrigin url matching this.remoteOrigin.
|
|
11
|
-
*/
|
|
12
|
-
readonly inboundMessages$: Observable<AnyMessage>;
|
|
13
|
-
/**
|
|
14
|
-
* Filtered subset of inboundMessages$, emitting all messages of type 'notification'
|
|
15
|
-
*/
|
|
16
|
-
readonly notifications$: Observable<INotificationObject>;
|
|
17
|
-
/**
|
|
18
|
-
* Filtered subset of inboundMessages$, emitting all messages of type 'request'
|
|
19
|
-
*/
|
|
20
|
-
readonly requests$: Observable<IRequestObject>;
|
|
21
|
-
/**
|
|
22
|
-
* Filtered subset of inboundMessages$, emitting all messages of type 'response'
|
|
23
|
-
*/
|
|
24
|
-
readonly responses$: Observable<IResponseObject>;
|
|
25
|
-
/**
|
|
26
|
-
* @param {IMessageFactory} messageFactory - Factory instance for scalar message objects.
|
|
27
|
-
* @param {IMessageValidator} messageValidator - Validator instance for incoming messages.
|
|
28
|
-
* @param {IPostmessageAdapter} adapter - Adapter for interacting with the postMessage API
|
|
29
|
-
*/
|
|
30
|
-
constructor(messageFactory: IMessageFactory, messageValidator: IMessageValidator, adapter: IPostmessageAdapter);
|
|
31
|
-
request<T = any, U = any>(channel: string, payload?: T): Observable<U>;
|
|
32
|
-
notify<T>(channel: string, payload?: T): void;
|
|
33
|
-
requests<T = any, U = any>(channel: string): Observable<Request<T, U>>;
|
|
34
|
-
notifications<T = any>(channel: string): Observable<T>;
|
|
35
|
-
/**
|
|
36
|
-
* Sends a response through given channel to the remote window, carrying given payload.
|
|
37
|
-
*/
|
|
38
|
-
protected respond<T>(requestId: string, channel: string, payload: T): this;
|
|
39
|
-
/**
|
|
40
|
-
* Creates an Observable that completes after a single emission of the MessageEvent
|
|
41
|
-
* response for request of given requestId. If no matching response is ever received,
|
|
42
|
-
* the Observable never completes.
|
|
43
|
-
*/
|
|
44
|
-
protected createResponseObservable<T>(requestId: string): Observable<T>;
|
|
45
|
-
/**
|
|
46
|
-
* Returns an Observable emitting all inbound messages` of given type.
|
|
47
|
-
* Returns an Observable emitting a subset of MessageEvent objects emitted
|
|
48
|
-
* by this.inboundMessages$, passing through all MessageEvent objects whose
|
|
49
|
-
* data.type property matches given type.
|
|
50
|
-
*/
|
|
51
|
-
protected messagesOfType<T extends MessageType>(type: T): Observable<MappedMessage<T>>;
|
|
52
|
-
}
|
package/cjs/Messenger.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Messenger = void 0;
|
|
4
|
-
var rxjs_1 = require("rxjs");
|
|
5
|
-
var operators_1 = require("rxjs/operators");
|
|
6
|
-
var RxPostmessengerRequest_1 = require("./RxPostmessengerRequest");
|
|
7
|
-
var Messenger = /** @class */ (function () {
|
|
8
|
-
/**
|
|
9
|
-
* @param {IMessageFactory} messageFactory - Factory instance for scalar message objects.
|
|
10
|
-
* @param {IMessageValidator} messageValidator - Validator instance for incoming messages.
|
|
11
|
-
* @param {IPostmessageAdapter} adapter - Adapter for interacting with the postMessage API
|
|
12
|
-
*/
|
|
13
|
-
function Messenger(messageFactory, messageValidator, adapter) {
|
|
14
|
-
var _this = this;
|
|
15
|
-
this.messageFactory = messageFactory;
|
|
16
|
-
this.messageValidator = messageValidator;
|
|
17
|
-
this.adapter = adapter;
|
|
18
|
-
this.inboundMessages$ = rxjs_1.fromEvent(window, 'message').pipe(operators_1.filter(function (message) { return _this.messageValidator.validate(message); }), operators_1.pluck('data'), rxjs_1.share());
|
|
19
|
-
this.requests$ = this.messagesOfType('request');
|
|
20
|
-
this.responses$ = this.messagesOfType('response');
|
|
21
|
-
this.notifications$ = this.messagesOfType('notification');
|
|
22
|
-
this.inboundMessages$.subscribe(function (_a) {
|
|
23
|
-
var id = _a.id;
|
|
24
|
-
return _this.messageFactory.invalidateID(id);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
Messenger.prototype.request = function (channel, payload) {
|
|
28
|
-
var request = this.messageFactory.makeRequest(channel, payload);
|
|
29
|
-
var responseObservable = this.createResponseObservable(request.id);
|
|
30
|
-
this.adapter.postMessage(request);
|
|
31
|
-
return responseObservable;
|
|
32
|
-
};
|
|
33
|
-
Messenger.prototype.notify = function (channel, payload) {
|
|
34
|
-
this.adapter.postMessage(this.messageFactory.makeNotification(channel, payload));
|
|
35
|
-
};
|
|
36
|
-
Messenger.prototype.requests = function (channel) {
|
|
37
|
-
var _this = this;
|
|
38
|
-
return this.requests$.pipe(operators_1.filter(function (request) { return request.channel === channel; }), operators_1.map(function (request) { return new RxPostmessengerRequest_1.RxPostmessengerRequest(request.id, request.channel, request.payload, function (payload) { return _this.respond(request.id, channel, payload); }); }));
|
|
39
|
-
};
|
|
40
|
-
Messenger.prototype.notifications = function (channel) {
|
|
41
|
-
return this.notifications$.pipe(operators_1.filter(function (notification) { return notification.channel === channel; }), operators_1.pluck('payload'));
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Sends a response through given channel to the remote window, carrying given payload.
|
|
45
|
-
*/
|
|
46
|
-
Messenger.prototype.respond = function (requestId, channel, payload) {
|
|
47
|
-
this.adapter.postMessage(this.messageFactory.makeResponse(requestId, channel, payload));
|
|
48
|
-
return this;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Creates an Observable that completes after a single emission of the MessageEvent
|
|
52
|
-
* response for request of given requestId. If no matching response is ever received,
|
|
53
|
-
* the Observable never completes.
|
|
54
|
-
*/
|
|
55
|
-
Messenger.prototype.createResponseObservable = function (requestId) {
|
|
56
|
-
return this.responses$.pipe(operators_1.filter(function (response) { return response.requestId === requestId; }), operators_1.pluck('payload'), operators_1.take(1));
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Returns an Observable emitting all inbound messages` of given type.
|
|
60
|
-
* Returns an Observable emitting a subset of MessageEvent objects emitted
|
|
61
|
-
* by this.inboundMessages$, passing through all MessageEvent objects whose
|
|
62
|
-
* data.type property matches given type.
|
|
63
|
-
*/
|
|
64
|
-
Messenger.prototype.messagesOfType = function (type) {
|
|
65
|
-
return this.inboundMessages$.pipe(operators_1.filter(function (message) { return message.type === type; }));
|
|
66
|
-
};
|
|
67
|
-
return Messenger;
|
|
68
|
-
}());
|
|
69
|
-
exports.Messenger = Messenger;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PostmessageAdapter = void 0;
|
|
4
|
-
var PostmessageAdapter = /** @class */ (function () {
|
|
5
|
-
function PostmessageAdapter(targetWindow, targetOrigin) {
|
|
6
|
-
this.targetWindow = targetWindow;
|
|
7
|
-
this.targetOrigin = targetOrigin;
|
|
8
|
-
}
|
|
9
|
-
PostmessageAdapter.prototype.postMessage = function (data) {
|
|
10
|
-
this.targetWindow.postMessage(data, this.targetOrigin);
|
|
11
|
-
};
|
|
12
|
-
return PostmessageAdapter;
|
|
13
|
-
}());
|
|
14
|
-
exports.PostmessageAdapter = PostmessageAdapter;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Request } from '../rx-postmessenger';
|
|
2
|
-
export declare class RxPostmessengerRequest<T, U> implements Request<T, U> {
|
|
3
|
-
readonly id: string;
|
|
4
|
-
readonly channel: string;
|
|
5
|
-
readonly payload: T;
|
|
6
|
-
private readonly _injectResponse;
|
|
7
|
-
private _isHandled;
|
|
8
|
-
constructor(id: string, channel: string, payload: T, _injectResponse: (data: U) => void);
|
|
9
|
-
get isHandled(): boolean;
|
|
10
|
-
respond(data: U): void;
|
|
11
|
-
}
|