rx-postmessenger 2.0.1 → 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/LICENSE +2 -2
- package/README.md +83 -63
- package/{esm → dist}/MessageFactory.d.ts +1 -3
- package/dist/MessageFactory.js +34 -0
- package/{cjs → dist}/MessageIDGenerator.d.ts +1 -1
- package/dist/MessageIDGenerator.js +19 -0
- package/{cjs → dist}/MessageValidator.d.ts +3 -4
- package/{esm → dist}/MessageValidator.js +19 -20
- package/dist/Messenger.d.ts +52 -0
- package/dist/Messenger.js +79 -0
- package/{cjs → dist}/PostmessageAdapter.d.ts +1 -2
- package/dist/PostmessageAdapter.js +11 -0
- package/dist/RxPostmessengerRequest.d.ts +11 -0
- package/dist/RxPostmessengerRequest.js +23 -0
- package/dist/functions/GUIDGenerator.d.ts +1 -0
- package/dist/functions/GUIDGenerator.js +10 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +14 -0
- package/dist/public-api.d.ts +55 -0
- package/dist/public-api.js +1 -0
- package/dist/types.d.ts +58 -0
- package/dist/types.js +1 -0
- package/package.json +39 -47
- package/CHANGELOG.md +0 -159
- package/cjs/MessageFactory.d.ts +0 -11
- package/cjs/MessageFactory.js +0 -38
- package/cjs/MessageFactory.js.map +0 -1
- package/cjs/MessageIDGenerator.js +0 -24
- package/cjs/MessageIDGenerator.js.map +0 -1
- package/cjs/MessageValidator.js +0 -44
- package/cjs/MessageValidator.js.map +0 -1
- package/cjs/Messenger.d.ts +0 -99
- package/cjs/Messenger.js +0 -116
- package/cjs/Messenger.js.map +0 -1
- package/cjs/PostmessageAdapter.js +0 -14
- package/cjs/PostmessageAdapter.js.map +0 -1
- package/cjs/RxPostmessengerRequest.d.ts +0 -10
- package/cjs/RxPostmessengerRequest.js +0 -23
- package/cjs/RxPostmessengerRequest.js.map +0 -1
- package/cjs/functions/GUIDGenerator.d.ts +0 -1
- package/cjs/functions/GUIDGenerator.js +0 -59
- package/cjs/functions/GUIDGenerator.js.map +0 -1
- package/cjs/index.d.ts +0 -4
- package/cjs/index.js +0 -20
- package/cjs/index.js.map +0 -1
- package/cjs/interface/id-generator.d.ts +0 -11
- package/cjs/interface/id-generator.js +0 -3
- package/cjs/interface/id-generator.js.map +0 -1
- package/cjs/interface/message-factory.d.ts +0 -7
- package/cjs/interface/message-factory.js +0 -3
- package/cjs/interface/message-factory.js.map +0 -1
- package/cjs/interface/message-objects.d.ts +0 -30
- package/cjs/interface/message-objects.js +0 -3
- package/cjs/interface/message-objects.js.map +0 -1
- package/cjs/interface/message-validator.d.ts +0 -7
- package/cjs/interface/message-validator.js +0 -3
- package/cjs/interface/message-validator.js.map +0 -1
- package/cjs/interface/postmessage-adapter.d.ts +0 -6
- package/cjs/interface/postmessage-adapter.js +0 -3
- package/cjs/interface/postmessage-adapter.js.map +0 -1
- package/cjs/interface/public-interface.d.ts +0 -4
- package/cjs/interface/public-interface.js +0 -3
- package/cjs/interface/public-interface.js.map +0 -1
- package/esm/MessageFactory.js +0 -36
- package/esm/MessageFactory.js.map +0 -1
- package/esm/MessageIDGenerator.d.ts +0 -8
- package/esm/MessageIDGenerator.js +0 -22
- package/esm/MessageIDGenerator.js.map +0 -1
- package/esm/MessageValidator.d.ts +0 -30
- package/esm/MessageValidator.js.map +0 -1
- package/esm/Messenger.d.ts +0 -99
- package/esm/Messenger.js +0 -114
- package/esm/Messenger.js.map +0 -1
- package/esm/PostmessageAdapter.d.ts +0 -8
- package/esm/PostmessageAdapter.js +0 -12
- package/esm/PostmessageAdapter.js.map +0 -1
- package/esm/RxPostmessengerRequest.d.ts +0 -10
- package/esm/RxPostmessengerRequest.js +0 -21
- package/esm/RxPostmessengerRequest.js.map +0 -1
- package/esm/functions/GUIDGenerator.d.ts +0 -1
- package/esm/functions/GUIDGenerator.js +0 -56
- package/esm/functions/GUIDGenerator.js.map +0 -1
- package/esm/index.d.ts +0 -4
- package/esm/index.js +0 -17
- package/esm/index.js.map +0 -1
- package/esm/interface/id-generator.d.ts +0 -11
- package/esm/interface/id-generator.js +0 -1
- package/esm/interface/id-generator.js.map +0 -1
- package/esm/interface/message-factory.d.ts +0 -7
- package/esm/interface/message-factory.js +0 -1
- package/esm/interface/message-factory.js.map +0 -1
- package/esm/interface/message-objects.d.ts +0 -30
- package/esm/interface/message-objects.js +0 -1
- package/esm/interface/message-objects.js.map +0 -1
- package/esm/interface/message-validator.d.ts +0 -7
- package/esm/interface/message-validator.js +0 -1
- package/esm/interface/message-validator.js.map +0 -1
- package/esm/interface/postmessage-adapter.d.ts +0 -6
- package/esm/interface/postmessage-adapter.js +0 -1
- package/esm/interface/postmessage-adapter.js.map +0 -1
- package/esm/interface/public-interface.d.ts +0 -4
- package/esm/interface/public-interface.js +0 -1
- package/esm/interface/public-interface.js.map +0 -1
- package/karma.conf.js +0 -99
- package/rx-postmessenger.d.ts +0 -74
- package/umd/rx-postmessenger.js +0 -10827
- package/umd/rx-postmessenger.js.map +0 -1
- package/umd/rx-postmessenger.min.js +0 -17
- package/umd/rx-postmessenger.min.js.map +0 -1
- package/yarn-error.log +0 -4522
package/cjs/Messenger.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// -----------------------------------------------------------------------------
|
|
3
|
-
// Concrete imports
|
|
4
|
-
// -----------------------------------------------------------------------------
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var rxjs_1 = require("rxjs");
|
|
7
|
-
var operators_1 = require("rxjs/operators");
|
|
8
|
-
var RxPostmessengerRequest_1 = require("./RxPostmessengerRequest");
|
|
9
|
-
var Messenger = /** @class */ (function () {
|
|
10
|
-
/**
|
|
11
|
-
* @param {IMessageFactory} messageFactory - Factory instance for scalar message objects.
|
|
12
|
-
* @param {IMessageValidator} messageValidator - Validator instance for incoming messages.
|
|
13
|
-
* @param {IPostmessageAdapter} adapter - Adapter for interacting with the postMessage API
|
|
14
|
-
*/
|
|
15
|
-
function Messenger(messageFactory, messageValidator, adapter) {
|
|
16
|
-
var _this = this;
|
|
17
|
-
this.messageFactory = messageFactory;
|
|
18
|
-
this.messageValidator = messageValidator;
|
|
19
|
-
this.adapter = adapter;
|
|
20
|
-
this.inboundMessages$ = rxjs_1.fromEvent(window, 'message').pipe(operators_1.filter(function (message) { return _this.messageValidator.validate(message); }), operators_1.pluck('data'));
|
|
21
|
-
this.requests$ = this.messagesOfType('request');
|
|
22
|
-
this.responses$ = this.messagesOfType('response');
|
|
23
|
-
this.notifications$ = this.messagesOfType('notification');
|
|
24
|
-
this.inboundMessages$.subscribe(function (_a) {
|
|
25
|
-
var id = _a.id;
|
|
26
|
-
return _this.messageFactory.invalidateID(id);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* Send a request over given channel with given payload. Returns an observable that will
|
|
32
|
-
* emit the response and then complete.
|
|
33
|
-
*
|
|
34
|
-
* @param {string} channel The channel name of the request.
|
|
35
|
-
* @param {*} [payload] The payload to send along with the request.
|
|
36
|
-
*/
|
|
37
|
-
Messenger.prototype.request = function (channel, payload) {
|
|
38
|
-
var request = this.messageFactory.makeRequest(channel, payload);
|
|
39
|
-
var responseObservable = this.createResponseObservable(request.id);
|
|
40
|
-
this.adapter.postMessage(request);
|
|
41
|
-
return responseObservable;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Send a notification over given channel with given payload.
|
|
45
|
-
*
|
|
46
|
-
* @param {string} channel - The channel name of the notification.
|
|
47
|
-
* @param {*} [payload] - The payload to send along with the notification.
|
|
48
|
-
*/
|
|
49
|
-
Messenger.prototype.notify = function (channel, payload) {
|
|
50
|
-
this.adapter.postMessage(this.messageFactory.makeNotification(channel, payload));
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Returns an Observable that emits the subset of inbound notification messages where their
|
|
54
|
-
* channel equals given channel name.
|
|
55
|
-
*
|
|
56
|
-
* @param {string} channel - The request channel name to listen to.
|
|
57
|
-
* @return {Observable<object>}
|
|
58
|
-
* @public
|
|
59
|
-
*/
|
|
60
|
-
Messenger.prototype.requests = function (channel) {
|
|
61
|
-
var _this = this;
|
|
62
|
-
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); }); }));
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Returns an Observable that emits the subset of inbound notification messages where their
|
|
66
|
-
* channel equals given channel name.
|
|
67
|
-
*
|
|
68
|
-
* @param {string} channel - The notification channel name to listen to.
|
|
69
|
-
* @return {Observable<*>}
|
|
70
|
-
* @public
|
|
71
|
-
*/
|
|
72
|
-
Messenger.prototype.notifications = function (channel) {
|
|
73
|
-
return this.notifications$.pipe(operators_1.filter(function (notification) { return notification.channel === channel; }), operators_1.pluck('payload'));
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Sends a response through given channel to the remote window, carrying given payload.
|
|
77
|
-
*
|
|
78
|
-
* @param {string} requestId - The request ID of the original request
|
|
79
|
-
* @param {string} channel - The request-channel name to send the response over
|
|
80
|
-
* @param {*} payload - The response payload
|
|
81
|
-
* @return {Messenger}
|
|
82
|
-
* @protected
|
|
83
|
-
*/
|
|
84
|
-
Messenger.prototype.respond = function (requestId, channel, payload) {
|
|
85
|
-
this.adapter.postMessage(this.messageFactory.makeResponse(requestId, channel, payload));
|
|
86
|
-
return this;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Creates an Observable that completes after a single emission of the MessageEvent response for request of given
|
|
90
|
-
* requestId. If no matching response is ever received, the Observable never completes.
|
|
91
|
-
*
|
|
92
|
-
* @param {string} requestId
|
|
93
|
-
* @return {Observable<object>}
|
|
94
|
-
* @protected
|
|
95
|
-
*/
|
|
96
|
-
Messenger.prototype.createResponseObservable = function (requestId) {
|
|
97
|
-
return this.responses$.pipe(operators_1.filter(function (response) { return response.requestId === requestId; }), operators_1.pluck('payload'), operators_1.take(1));
|
|
98
|
-
};
|
|
99
|
-
/**
|
|
100
|
-
* Returns an Observable emitting all inbound messages` of given type.
|
|
101
|
-
*
|
|
102
|
-
* Returns an Observable emitting a subset of MessageEvent objects emitted
|
|
103
|
-
* by this.inboundMessages$, passing through all MessageEvent objects whose
|
|
104
|
-
* data.type property matches given type.
|
|
105
|
-
*
|
|
106
|
-
* @param {string} type
|
|
107
|
-
* @return {Observable<object>}
|
|
108
|
-
* @protected
|
|
109
|
-
*/
|
|
110
|
-
Messenger.prototype.messagesOfType = function (type) {
|
|
111
|
-
return this.inboundMessages$.pipe(operators_1.filter(function (message) { return message.type === type; }));
|
|
112
|
-
};
|
|
113
|
-
return Messenger;
|
|
114
|
-
}());
|
|
115
|
-
exports.Messenger = Messenger;
|
|
116
|
-
//# sourceMappingURL=Messenger.js.map
|
package/cjs/Messenger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Messenger.js","sourceRoot":"","sources":["../src/Messenger.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var PostmessageAdapter = /** @class */ (function () {
|
|
4
|
-
function PostmessageAdapter(targetWindow, targetOrigin) {
|
|
5
|
-
this.targetWindow = targetWindow;
|
|
6
|
-
this.targetOrigin = targetOrigin;
|
|
7
|
-
}
|
|
8
|
-
PostmessageAdapter.prototype.postMessage = function (data) {
|
|
9
|
-
this.targetWindow.postMessage(data, this.targetOrigin);
|
|
10
|
-
};
|
|
11
|
-
return PostmessageAdapter;
|
|
12
|
-
}());
|
|
13
|
-
exports.PostmessageAdapter = PostmessageAdapter;
|
|
14
|
-
//# sourceMappingURL=PostmessageAdapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PostmessageAdapter.js","sourceRoot":"","sources":["../src/PostmessageAdapter.ts"],"names":[],"mappings":";;AAGA;IAEI,4BACoB,YAAoB,EACpB,YAAoB;QADpB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,iBAAY,GAAZ,YAAY,CAAQ;IACrC,CAAC;IAEG,wCAAW,GAAlB,UAAyC,IAAO;QAE5C,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC3D,CAAC;IACL,yBAAC;AAAD,CAAC,AAXD,IAWC;AAXY,gDAAkB"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { IRequest } from './interface/public-interface';
|
|
2
|
-
export declare class RxPostmessengerRequest<T, U> implements IRequest<T, U> {
|
|
3
|
-
readonly channel: string;
|
|
4
|
-
readonly payload: T;
|
|
5
|
-
readonly isHandled: boolean;
|
|
6
|
-
readonly id: string;
|
|
7
|
-
private readonly _injectResponse;
|
|
8
|
-
constructor(id: string, channel: string, payload: T, responseInjector: (data: U) => void);
|
|
9
|
-
respond(data: U): void;
|
|
10
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var RxPostmessengerRequest = /** @class */ (function () {
|
|
4
|
-
function RxPostmessengerRequest(id, channel, payload, responseInjector) {
|
|
5
|
-
this.isHandled = false;
|
|
6
|
-
Object.defineProperties(this, {
|
|
7
|
-
_injectResponse: { value: responseInjector },
|
|
8
|
-
channel: { value: channel },
|
|
9
|
-
id: { value: id },
|
|
10
|
-
payload: { value: payload },
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
RxPostmessengerRequest.prototype.respond = function (data) {
|
|
14
|
-
if (this.isHandled) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
this._injectResponse(data);
|
|
18
|
-
Object.defineProperty(this, 'isHandled', { value: true });
|
|
19
|
-
};
|
|
20
|
-
return RxPostmessengerRequest;
|
|
21
|
-
}());
|
|
22
|
-
exports.RxPostmessengerRequest = RxPostmessengerRequest;
|
|
23
|
-
//# sourceMappingURL=RxPostmessengerRequest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RxPostmessengerRequest.js","sourceRoot":"","sources":["../src/RxPostmessengerRequest.ts"],"names":[],"mappings":";;AAEA;IASI,gCACI,EAAU,EACV,OAAe,EACf,OAAU,EACV,gBAAmC;QATvB,cAAS,GAAY,KAAK,CAAC;QAWvC,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE;YAC1B,eAAe,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE;YAC5C,OAAO,EAAU,EAAE,KAAK,EAAE,OAAO,EAAE;YACnC,EAAE,EAAe,EAAE,KAAK,EAAE,EAAE,EAAE;YAC9B,OAAO,EAAU,EAAE,KAAK,EAAE,OAAO,EAAE;SACtC,CAAC,CAAC;IACP,CAAC;IAEM,wCAAO,GAAd,UAAe,IAAO;QAClB,IAAI,IAAI,CAAC,SAAS,EAAE;YAChB,OAAO;SACV;QAED,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC;IACL,6BAAC;AAAD,CAAC,AA/BD,IA+BC;AA/BY,wDAAsB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function GUIDGenerator(): IterableIterator<string>;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
3
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
4
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
5
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
6
|
-
function step(op) {
|
|
7
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
8
|
-
while (_) try {
|
|
9
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
10
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11
|
-
switch (op[0]) {
|
|
12
|
-
case 0: case 1: t = op; break;
|
|
13
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
14
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
15
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
16
|
-
default:
|
|
17
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
18
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
19
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
20
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
21
|
-
if (t[2]) _.ops.pop();
|
|
22
|
-
_.trys.pop(); continue;
|
|
23
|
-
}
|
|
24
|
-
op = body.call(thisArg, _);
|
|
25
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
26
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
function GUIDGenerator() {
|
|
31
|
-
var s4, IDSegment, guid;
|
|
32
|
-
return __generator(this, function (_a) {
|
|
33
|
-
switch (_a.label) {
|
|
34
|
-
case 0:
|
|
35
|
-
s4 = function () { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); };
|
|
36
|
-
IDSegment = function (size) {
|
|
37
|
-
if (size === void 0) { size = 1; }
|
|
38
|
-
return Array(size).fill(null).map(s4).join('');
|
|
39
|
-
};
|
|
40
|
-
guid = function () { return [
|
|
41
|
-
IDSegment(2),
|
|
42
|
-
IDSegment(),
|
|
43
|
-
IDSegment(),
|
|
44
|
-
IDSegment(),
|
|
45
|
-
IDSegment(3),
|
|
46
|
-
].join('-'); };
|
|
47
|
-
_a.label = 1;
|
|
48
|
-
case 1:
|
|
49
|
-
if (!true) return [3 /*break*/, 3];
|
|
50
|
-
return [4 /*yield*/, guid()];
|
|
51
|
-
case 2:
|
|
52
|
-
_a.sent();
|
|
53
|
-
return [3 /*break*/, 1];
|
|
54
|
-
case 3: return [2 /*return*/];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
exports.GUIDGenerator = GUIDGenerator;
|
|
59
|
-
//# sourceMappingURL=GUIDGenerator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GUIDGenerator.js","sourceRoot":"","sources":["../../src/functions/GUIDGenerator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAiB,aAAa;;;;;gBACpB,EAAE,GAAG,cAAc,OAAA,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAnE,CAAmE,CAAC;gBACvF,SAAS,GAAG,UAAC,IAAgB;oBAAhB,qBAAA,EAAA,QAAgB;oBAAK,OAAA,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAvC,CAAuC,CAAC;gBAC1E,IAAI,GAAiB,cAAM,OAAA;oBAC7B,SAAS,CAAC,CAAC,CAAC;oBACZ,SAAS,EAAE;oBACX,SAAS,EAAE;oBACX,SAAS,EAAE;oBACX,SAAS,CAAC,CAAC,CAAC;iBACf,CAAC,IAAI,CAAC,GAAG,CAAC,EANsB,CAMtB,CAAC;;;qBAEL,IAAI;gBACP,qBAAM,IAAI,EAAE,EAAA;;gBAAZ,SAAY,CAAC;;;;;CAEpB;AAdD,sCAcC"}
|
package/cjs/index.d.ts
DELETED
package/cjs/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var MessageFactory_1 = require("./MessageFactory");
|
|
4
|
-
var MessageIDGenerator_1 = require("./MessageIDGenerator");
|
|
5
|
-
var MessageValidator_1 = require("./MessageValidator");
|
|
6
|
-
var Messenger_1 = require("./Messenger");
|
|
7
|
-
var PostmessageAdapter_1 = require("./PostmessageAdapter");
|
|
8
|
-
function connect(remoteWindow, remoteOrigin) {
|
|
9
|
-
if (window === remoteWindow) {
|
|
10
|
-
throw new Error('Remote window can not be the same as the local window environment');
|
|
11
|
-
}
|
|
12
|
-
return new Messenger_1.Messenger(new MessageFactory_1.MessageFactory(new MessageIDGenerator_1.MessageIDGenerator()), new MessageValidator_1.MessageValidator(remoteWindow, remoteOrigin), new PostmessageAdapter_1.PostmessageAdapter(remoteWindow, remoteOrigin));
|
|
13
|
-
}
|
|
14
|
-
exports.connect = connect;
|
|
15
|
-
// ---------------------------------------------------------------------------------------
|
|
16
|
-
// API Exports
|
|
17
|
-
// ---------------------------------------------------------------------------------------
|
|
18
|
-
var defaultNamespace = { connect: connect };
|
|
19
|
-
exports.default = defaultNamespace;
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AACA,mDAAkD;AAClD,2DAA0D;AAC1D,uDAAsD;AACtD,yCAAwC;AACxC,2DAA0D;AAE1D,SAAgB,OAAO,CAAC,YAAoB,EAAE,YAAoB;IAE9D,IAAI,MAAM,KAAK,YAAY,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;KACxF;IAED,OAAO,IAAI,qBAAS,CAChB,IAAI,+BAAc,CACd,IAAI,uCAAkB,EAAE,CAC3B,EACD,IAAI,mCAAgB,CAAC,YAAY,EAAE,YAAY,CAAC,EAChD,IAAI,uCAAkB,CAAC,YAAY,EAAE,YAAY,CAAC,CACrD,CAAC;AACN,CAAC;AAbD,0BAaC;AAED,0FAA0F;AAC1F,cAAc;AACd,0FAA0F;AAE1F,IAAM,gBAAgB,GAAY,EAAE,OAAO,SAAA,EAAE,CAAC;AAC9C,kBAAe,gBAAgB,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export interface IMessageIDGenerator {
|
|
2
|
-
/**
|
|
3
|
-
* Get a new unique ID value for message objects.
|
|
4
|
-
*/
|
|
5
|
-
generateID(): string;
|
|
6
|
-
/**
|
|
7
|
-
* Invalidates an ID value - marks it a used. This is a required
|
|
8
|
-
* feature for syncing the used ID values
|
|
9
|
-
*/
|
|
10
|
-
invalidateID(id: string): void;
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"id-generator.js","sourceRoot":"","sources":["../../src/interface/id-generator.ts"],"names":[],"mappings":""}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { INotificationObject, IRequestObject, IResponseObject } from './message-objects';
|
|
2
|
-
export interface IMessageFactory {
|
|
3
|
-
invalidateID(id: string): void;
|
|
4
|
-
makeRequest<T>(channel: string, payload: T): IRequestObject<T>;
|
|
5
|
-
makeResponse<T>(requestId: string, channel: string, payload: T): IResponseObject<T>;
|
|
6
|
-
makeNotification<T>(channel: string, payload: T): INotificationObject<T>;
|
|
7
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"message-factory.js","sourceRoot":"","sources":["../../src/interface/message-factory.ts"],"names":[],"mappings":""}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The IMessageObject interface defines the format for data property values of MessageEvent objects.
|
|
3
|
-
* This interface describes the actual format of data sent with postMessage that is required for
|
|
4
|
-
* another RxPostmessenger on the other end of the line to be able to correctly interpret the
|
|
5
|
-
* message.
|
|
6
|
-
*/
|
|
7
|
-
export interface IMessageObject<T = any> {
|
|
8
|
-
readonly id: string;
|
|
9
|
-
readonly type: MessageType;
|
|
10
|
-
readonly channel: string;
|
|
11
|
-
readonly payload: T;
|
|
12
|
-
}
|
|
13
|
-
export interface IRequestObject<T = any> extends IMessageObject<T> {
|
|
14
|
-
readonly type: 'request';
|
|
15
|
-
}
|
|
16
|
-
export interface IResponseObject<T = any> extends IMessageObject<T> {
|
|
17
|
-
readonly requestId: string;
|
|
18
|
-
readonly type: 'response';
|
|
19
|
-
}
|
|
20
|
-
export interface INotificationObject<T = any> extends IMessageObject<T> {
|
|
21
|
-
readonly type: 'notification';
|
|
22
|
-
}
|
|
23
|
-
export declare type AnyMessage = IRequestObject | IResponseObject | INotificationObject;
|
|
24
|
-
export interface IMessageTypeMap<T = any> {
|
|
25
|
-
request: IRequestObject;
|
|
26
|
-
response: IResponseObject;
|
|
27
|
-
notification: INotificationObject;
|
|
28
|
-
}
|
|
29
|
-
export declare type MessageType = keyof IMessageTypeMap;
|
|
30
|
-
export declare type MappedMessage<T extends MessageType> = IMessageTypeMap[T];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"message-objects.js","sourceRoot":"","sources":["../../src/interface/message-objects.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"message-validator.js","sourceRoot":"","sources":["../../src/interface/message-validator.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"postmessage-adapter.js","sourceRoot":"","sources":["../../src/interface/postmessage-adapter.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"public-interface.js","sourceRoot":"","sources":["../../src/interface/public-interface.ts"],"names":[],"mappings":""}
|
package/esm/MessageFactory.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
var MessageFactory = /** @class */ (function () {
|
|
2
|
-
function MessageFactory(IDGenerator) {
|
|
3
|
-
this.IDGenerator = IDGenerator;
|
|
4
|
-
}
|
|
5
|
-
MessageFactory.prototype.makeNotification = function (channel, payload) {
|
|
6
|
-
return {
|
|
7
|
-
channel: channel,
|
|
8
|
-
id: this.IDGenerator.generateID(),
|
|
9
|
-
payload: payload,
|
|
10
|
-
type: 'notification',
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
MessageFactory.prototype.makeRequest = function (channel, payload) {
|
|
14
|
-
return {
|
|
15
|
-
channel: channel,
|
|
16
|
-
id: this.IDGenerator.generateID(),
|
|
17
|
-
payload: payload,
|
|
18
|
-
type: 'request',
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
MessageFactory.prototype.makeResponse = function (requestId, channel, payload) {
|
|
22
|
-
return {
|
|
23
|
-
channel: channel,
|
|
24
|
-
id: this.IDGenerator.generateID(),
|
|
25
|
-
payload: payload,
|
|
26
|
-
requestId: requestId,
|
|
27
|
-
type: 'response',
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
MessageFactory.prototype.invalidateID = function (id) {
|
|
31
|
-
this.IDGenerator.invalidateID(id);
|
|
32
|
-
};
|
|
33
|
-
return MessageFactory;
|
|
34
|
-
}());
|
|
35
|
-
export { MessageFactory };
|
|
36
|
-
//# sourceMappingURL=MessageFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MessageFactory.js","sourceRoot":"","sources":["../src/MessageFactory.ts"],"names":[],"mappings":"AAIA;IAEI,wBAA+B,WAAgC;QAAhC,gBAAW,GAAX,WAAW,CAAqB;IAAI,CAAC;IAE7D,yCAAgB,GAAvB,UAA2B,OAAe,EAAE,OAAU;QAClD,OAAO;YACH,OAAO,SAAA;YACP,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE;YACjC,OAAO,SAAA;YACP,IAAI,EAAE,cAAc;SACvB,CAAC;IACN,CAAC;IAEM,oCAAW,GAAlB,UAAsB,OAAe,EAAE,OAAU;QAC7C,OAAO;YACH,OAAO,SAAA;YACP,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE;YACjC,OAAO,SAAA;YACP,IAAI,EAAE,SAAS;SAClB,CAAC;IACN,CAAC;IAEM,qCAAY,GAAnB,UAAuB,SAAiB,EAAE,OAAe,EAAE,OAAU;QACjE,OAAO;YACH,OAAO,SAAA;YACP,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,UAAU,EAAE;YACjC,OAAO,SAAA;YACP,SAAS,WAAA;YACT,IAAI,EAAE,UAAU;SACnB,CAAC;IACN,CAAC;IAEM,qCAAY,GAAnB,UAAoB,EAAU;QAC1B,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;IACtC,CAAC;IACL,qBAAC;AAAD,CAAC,AAnCD,IAmCC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { IMessageIDGenerator } from './interface/id-generator';
|
|
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,22 +0,0 @@
|
|
|
1
|
-
import { GUIDGenerator } from './functions/GUIDGenerator';
|
|
2
|
-
var MessageIDGenerator = /** @class */ (function () {
|
|
3
|
-
function MessageIDGenerator(gen) {
|
|
4
|
-
if (gen === void 0) { gen = GUIDGenerator(); }
|
|
5
|
-
this.gen = gen;
|
|
6
|
-
this.usedIDValues = [];
|
|
7
|
-
}
|
|
8
|
-
MessageIDGenerator.prototype.generateID = function () {
|
|
9
|
-
var newID;
|
|
10
|
-
do {
|
|
11
|
-
newID = this.gen.next().value;
|
|
12
|
-
} while (this.usedIDValues.indexOf(newID) >= 0);
|
|
13
|
-
this.invalidateID(newID);
|
|
14
|
-
return newID;
|
|
15
|
-
};
|
|
16
|
-
MessageIDGenerator.prototype.invalidateID = function (id) {
|
|
17
|
-
this.usedIDValues.push(id);
|
|
18
|
-
};
|
|
19
|
-
return MessageIDGenerator;
|
|
20
|
-
}());
|
|
21
|
-
export { MessageIDGenerator };
|
|
22
|
-
//# sourceMappingURL=MessageIDGenerator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MessageIDGenerator.js","sourceRoot":"","sources":["../src/MessageIDGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG1D;IAII,4BAA+B,GAAuC;QAAvC,oBAAA,EAAA,MAAwB,aAAa,EAAE;QAAvC,QAAG,GAAH,GAAG,CAAoC;QAFnD,iBAAY,GAAa,EAAE,CAAC;IAE0B,CAAC;IAEnE,uCAAU,GAAjB;QACI,IAAI,KAAa,CAAC;QAElB,GAAG;YACC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;SACjC,QAAQ,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;QAEhD,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QACzB,OAAO,KAAK,CAAC;IACjB,CAAC;IAEM,yCAAY,GAAnB,UAAoB,EAAU;QAC1B,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/B,CAAC;IACL,yBAAC;AAAD,CAAC,AApBD,IAoBC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { AnyMessage } from './interface/message-objects';
|
|
2
|
-
import { IMessageValidator, IOwnMessageEvent } from './interface/message-validator';
|
|
3
|
-
export declare class MessageValidator implements IMessageValidator {
|
|
4
|
-
protected acceptedSource: Window;
|
|
5
|
-
protected acceptedOrigin: string;
|
|
6
|
-
constructor(acceptedSource: Window, acceptedOrigin: string);
|
|
7
|
-
/**
|
|
8
|
-
* Validates the identity of the message's sender and the format of the message's data.
|
|
9
|
-
*
|
|
10
|
-
* Checks whether the remoteOrigin location matches any allowed origins.
|
|
11
|
-
* Separate assertion of the remoteOrigin allows for cross-domain navigation
|
|
12
|
-
* within this.frame, and still treating inbound messages from the
|
|
13
|
-
* frame as being equal.
|
|
14
|
-
*
|
|
15
|
-
* Checks whether the source Window object equals the remoteWindow object.
|
|
16
|
-
* This check allows for implementation of multiple i-frames that share the
|
|
17
|
-
* same remoteOrigin, and still being able to distinguish between messages from
|
|
18
|
-
* such frames.
|
|
19
|
-
*/
|
|
20
|
-
validate(message: MessageEvent): message is IOwnMessageEvent<AnyMessage>;
|
|
21
|
-
/**
|
|
22
|
-
* Tests whether the data sent through postMessage is a well-formed message
|
|
23
|
-
* object. This serves as runtime data format validation. If messages do not
|
|
24
|
-
* comply to the AnyMessage compound interface, the entire event is ignored.
|
|
25
|
-
*
|
|
26
|
-
* @param {*} message
|
|
27
|
-
* @return {boolean}
|
|
28
|
-
*/
|
|
29
|
-
isWellFormedMessage(message: any): message is AnyMessage;
|
|
30
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MessageValidator.js","sourceRoot":"","sources":["../src/MessageValidator.ts"],"names":[],"mappings":"AAGA;IAEI,0BAAsB,cAAsB,EAAY,cAAsB;QAAxD,mBAAc,GAAd,cAAc,CAAQ;QAAY,mBAAc,GAAd,cAAc,CAAQ;IAAI,CAAC;IAEnF;;;;;;;;;;;;OAYG;IACI,mCAAQ,GAAf,UAAgB,OAAqB;QACjC,OAAO,OAAO,YAAY,YAAY;eAC/B,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,cAAc;eACtC,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,cAAc;eACtC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;OAOG;IACI,8CAAmB,GAA1B,UAA2B,OAAY;QACnC,OAAO,CAAC,OAAO,OAAO,CAAC,EAAE,KAAK,QAAQ,CAAC;eAChC,CAAC,CAAC,SAAS,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;eACpE,CAAC,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,CAAC;eACrC,CAAC,OAAO,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,OAAO,OAAO,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC;IACpF,CAAC;IACL,uBAAC;AAAD,CAAC,AAtCD,IAsCC"}
|
package/esm/Messenger.d.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
import { IMessageFactory } from './interface/message-factory';
|
|
3
|
-
import { IMessageValidator } from './interface/message-validator';
|
|
4
|
-
import { IPostmessageAdapter } from './interface/postmessage-adapter';
|
|
5
|
-
import { IMessenger, IRequest } from './interface/public-interface';
|
|
6
|
-
import { AnyMessage, INotificationObject, IRequestObject, IResponseObject, MappedMessage, MessageType } from './interface/message-objects';
|
|
7
|
-
export declare class Messenger implements IMessenger {
|
|
8
|
-
protected readonly messageFactory: IMessageFactory;
|
|
9
|
-
protected readonly messageValidator: IMessageValidator;
|
|
10
|
-
protected readonly adapter: IPostmessageAdapter;
|
|
11
|
-
/**
|
|
12
|
-
* Observable stream of all incoming messages that originate from remoteWindow with a
|
|
13
|
-
* remoteOrigin url matching this.remoteOrigin.
|
|
14
|
-
*/
|
|
15
|
-
readonly inboundMessages$: Observable<AnyMessage>;
|
|
16
|
-
/**
|
|
17
|
-
* Filtered subset of inboundMessages$, emitting all messages of type 'notification'
|
|
18
|
-
*/
|
|
19
|
-
readonly notifications$: Observable<INotificationObject>;
|
|
20
|
-
/**
|
|
21
|
-
* Filtered subset of inboundMessages$, emitting all messages of type 'request'
|
|
22
|
-
*/
|
|
23
|
-
readonly requests$: Observable<IRequestObject>;
|
|
24
|
-
/**
|
|
25
|
-
* Filtered subset of inboundMessages$, emitting all messages of type 'response'
|
|
26
|
-
*/
|
|
27
|
-
readonly responses$: Observable<IResponseObject>;
|
|
28
|
-
/**
|
|
29
|
-
* @param {IMessageFactory} messageFactory - Factory instance for scalar message objects.
|
|
30
|
-
* @param {IMessageValidator} messageValidator - Validator instance for incoming messages.
|
|
31
|
-
* @param {IPostmessageAdapter} adapter - Adapter for interacting with the postMessage API
|
|
32
|
-
*/
|
|
33
|
-
constructor(messageFactory: IMessageFactory, messageValidator: IMessageValidator, adapter: IPostmessageAdapter);
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* Send a request over given channel with given payload. Returns an observable that will
|
|
37
|
-
* emit the response and then complete.
|
|
38
|
-
*
|
|
39
|
-
* @param {string} channel The channel name of the request.
|
|
40
|
-
* @param {*} [payload] The payload to send along with the request.
|
|
41
|
-
*/
|
|
42
|
-
request<T = any, U = any>(channel: string, payload?: T): Observable<U>;
|
|
43
|
-
/**
|
|
44
|
-
* Send a notification over given channel with given payload.
|
|
45
|
-
*
|
|
46
|
-
* @param {string} channel - The channel name of the notification.
|
|
47
|
-
* @param {*} [payload] - The payload to send along with the notification.
|
|
48
|
-
*/
|
|
49
|
-
notify<T>(channel: string, payload?: T): void;
|
|
50
|
-
/**
|
|
51
|
-
* Returns an Observable that emits the subset of inbound notification messages where their
|
|
52
|
-
* channel equals given channel name.
|
|
53
|
-
*
|
|
54
|
-
* @param {string} channel - The request channel name to listen to.
|
|
55
|
-
* @return {Observable<object>}
|
|
56
|
-
* @public
|
|
57
|
-
*/
|
|
58
|
-
requests<T = any, U = any>(channel: string): Observable<IRequest<T, U>>;
|
|
59
|
-
/**
|
|
60
|
-
* Returns an Observable that emits the subset of inbound notification messages where their
|
|
61
|
-
* channel equals given channel name.
|
|
62
|
-
*
|
|
63
|
-
* @param {string} channel - The notification channel name to listen to.
|
|
64
|
-
* @return {Observable<*>}
|
|
65
|
-
* @public
|
|
66
|
-
*/
|
|
67
|
-
notifications<T = any>(channel: string): Observable<T>;
|
|
68
|
-
/**
|
|
69
|
-
* Sends a response through given channel to the remote window, carrying given payload.
|
|
70
|
-
*
|
|
71
|
-
* @param {string} requestId - The request ID of the original request
|
|
72
|
-
* @param {string} channel - The request-channel name to send the response over
|
|
73
|
-
* @param {*} payload - The response payload
|
|
74
|
-
* @return {Messenger}
|
|
75
|
-
* @protected
|
|
76
|
-
*/
|
|
77
|
-
protected respond<T>(requestId: string, channel: string, payload: T): this;
|
|
78
|
-
/**
|
|
79
|
-
* Creates an Observable that completes after a single emission of the MessageEvent response for request of given
|
|
80
|
-
* requestId. If no matching response is ever received, the Observable never completes.
|
|
81
|
-
*
|
|
82
|
-
* @param {string} requestId
|
|
83
|
-
* @return {Observable<object>}
|
|
84
|
-
* @protected
|
|
85
|
-
*/
|
|
86
|
-
protected createResponseObservable<T>(requestId: string): Observable<T>;
|
|
87
|
-
/**
|
|
88
|
-
* Returns an Observable emitting all inbound messages` of given type.
|
|
89
|
-
*
|
|
90
|
-
* Returns an Observable emitting a subset of MessageEvent objects emitted
|
|
91
|
-
* by this.inboundMessages$, passing through all MessageEvent objects whose
|
|
92
|
-
* data.type property matches given type.
|
|
93
|
-
*
|
|
94
|
-
* @param {string} type
|
|
95
|
-
* @return {Observable<object>}
|
|
96
|
-
* @protected
|
|
97
|
-
*/
|
|
98
|
-
protected messagesOfType<T extends MessageType>(type: T): Observable<MappedMessage<T>>;
|
|
99
|
-
}
|