@telperion/messenger 7.6.1

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 (136) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +600 -0
  3. package/broadcast/default-channel-name.cjs +4 -0
  4. package/broadcast/default-channel-name.d.ts +1 -0
  5. package/broadcast/default-channel-name.js +3 -0
  6. package/broadcast/default-channel-name.js.map +1 -0
  7. package/broadcast/index.cjs +13 -0
  8. package/broadcast/index.d.ts +5 -0
  9. package/broadcast/index.js +7 -0
  10. package/broadcast/index.js.map +1 -0
  11. package/broadcast/message-client.cjs +26 -0
  12. package/broadcast/message-client.d.ts +12 -0
  13. package/broadcast/message-client.js +24 -0
  14. package/broadcast/message-client.js.map +1 -0
  15. package/broadcast/message-host.cjs +28 -0
  16. package/broadcast/message-host.d.ts +9 -0
  17. package/broadcast/message-host.js +26 -0
  18. package/broadcast/message-host.js.map +1 -0
  19. package/broadcast/message-service.cjs +13 -0
  20. package/broadcast/message-service.d.ts +8 -0
  21. package/broadcast/message-service.js +11 -0
  22. package/broadcast/message-service.js.map +1 -0
  23. package/chrome/default-connection-name.cjs +4 -0
  24. package/chrome/default-connection-name.d.ts +1 -0
  25. package/chrome/default-connection-name.js +3 -0
  26. package/chrome/default-connection-name.js.map +1 -0
  27. package/chrome/index.cjs +11 -0
  28. package/chrome/index.d.ts +4 -0
  29. package/chrome/index.js +6 -0
  30. package/chrome/index.js.map +1 -0
  31. package/chrome/message-client.cjs +41 -0
  32. package/chrome/message-client.d.ts +15 -0
  33. package/chrome/message-client.js +39 -0
  34. package/chrome/message-client.js.map +1 -0
  35. package/chrome/message-host.cjs +43 -0
  36. package/chrome/message-host.d.ts +9 -0
  37. package/chrome/message-host.js +41 -0
  38. package/chrome/message-host.js.map +1 -0
  39. package/docs/images/broadcast-communication.svg +87 -0
  40. package/docs/images/chrome-extension-communication.svg +110 -0
  41. package/docs/images/core-architecture.svg +59 -0
  42. package/docs/images/iframe-communication.svg +74 -0
  43. package/docs/images/worker-communication.svg +75 -0
  44. package/iframe/channel-path-splitter.cjs +4 -0
  45. package/iframe/channel-path-splitter.d.ts +1 -0
  46. package/iframe/channel-path-splitter.js +3 -0
  47. package/iframe/channel-path-splitter.js.map +1 -0
  48. package/iframe/default-channel-name.cjs +4 -0
  49. package/iframe/default-channel-name.d.ts +1 -0
  50. package/iframe/default-channel-name.js +3 -0
  51. package/iframe/default-channel-name.js.map +1 -0
  52. package/iframe/iframe.type.cjs +2 -0
  53. package/iframe/iframe.type.d.ts +1 -0
  54. package/iframe/iframe.type.js +3 -0
  55. package/iframe/iframe.type.js.map +1 -0
  56. package/iframe/index.cjs +13 -0
  57. package/iframe/index.d.ts +6 -0
  58. package/iframe/index.js +7 -0
  59. package/iframe/index.js.map +1 -0
  60. package/iframe/message-client.cjs +50 -0
  61. package/iframe/message-client.d.ts +14 -0
  62. package/iframe/message-client.js +48 -0
  63. package/iframe/message-client.js.map +1 -0
  64. package/iframe/message-host.cjs +63 -0
  65. package/iframe/message-host.d.ts +11 -0
  66. package/iframe/message-host.js +61 -0
  67. package/iframe/message-host.js.map +1 -0
  68. package/iframe/message-service.cjs +13 -0
  69. package/iframe/message-service.d.ts +9 -0
  70. package/iframe/message-service.js +11 -0
  71. package/iframe/message-service.js.map +1 -0
  72. package/iframe/source-id-splitter.cjs +4 -0
  73. package/iframe/source-id-splitter.d.ts +1 -0
  74. package/iframe/source-id-splitter.js +3 -0
  75. package/iframe/source-id-splitter.js.map +1 -0
  76. package/iframe/upcoming-message.cjs +2 -0
  77. package/iframe/upcoming-message.d.ts +4 -0
  78. package/iframe/upcoming-message.js +3 -0
  79. package/iframe/upcoming-message.js.map +1 -0
  80. package/index.cjs +13 -0
  81. package/index.d.ts +7 -0
  82. package/index.js +7 -0
  83. package/index.js.map +1 -0
  84. package/listen.decorator.cjs +20 -0
  85. package/listen.decorator.d.ts +6 -0
  86. package/listen.decorator.js +19 -0
  87. package/listen.decorator.js.map +1 -0
  88. package/listener-storage.type.cjs +2 -0
  89. package/listener-storage.type.d.ts +2 -0
  90. package/listener-storage.type.js +3 -0
  91. package/listener-storage.type.js.map +1 -0
  92. package/message-client.cjs +10 -0
  93. package/message-client.d.ts +23 -0
  94. package/message-client.js +8 -0
  95. package/message-client.js.map +1 -0
  96. package/message-host.cjs +58 -0
  97. package/message-host.d.ts +26 -0
  98. package/message-host.js +56 -0
  99. package/message-host.js.map +1 -0
  100. package/message-response.type.cjs +2 -0
  101. package/message-response.type.d.ts +16 -0
  102. package/message-response.type.js +3 -0
  103. package/message-response.type.js.map +1 -0
  104. package/message.interface.cjs +2 -0
  105. package/message.interface.d.ts +6 -0
  106. package/message.interface.js +3 -0
  107. package/message.interface.js.map +1 -0
  108. package/package.json +158 -0
  109. package/request.decorator.cjs +20 -0
  110. package/request.decorator.d.ts +1 -0
  111. package/request.decorator.js +19 -0
  112. package/request.decorator.js.map +1 -0
  113. package/selectors.cjs +10 -0
  114. package/selectors.d.ts +7 -0
  115. package/selectors.js +9 -0
  116. package/selectors.js.map +1 -0
  117. package/worker/index.cjs +13 -0
  118. package/worker/index.d.ts +5 -0
  119. package/worker/index.js +7 -0
  120. package/worker/index.js.map +1 -0
  121. package/worker/initializer.cjs +39 -0
  122. package/worker/initializer.d.ts +12 -0
  123. package/worker/initializer.js +38 -0
  124. package/worker/initializer.js.map +1 -0
  125. package/worker/message-client.cjs +158 -0
  126. package/worker/message-client.d.ts +131 -0
  127. package/worker/message-client.js +156 -0
  128. package/worker/message-client.js.map +1 -0
  129. package/worker/message-host.cjs +165 -0
  130. package/worker/message-host.d.ts +131 -0
  131. package/worker/message-host.js +163 -0
  132. package/worker/message-host.js.map +1 -0
  133. package/worker/message-service.cjs +123 -0
  134. package/worker/message-service.d.ts +117 -0
  135. package/worker/message-service.js +121 -0
  136. package/worker/message-service.js.map +1 -0
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SOURCE_ID_SPLITTER = void 0;
4
+ exports.SOURCE_ID_SPLITTER = '__messenger_source_id_splitter__';
@@ -0,0 +1 @@
1
+ export declare const SOURCE_ID_SPLITTER = "__messenger_source_id_splitter__";
@@ -0,0 +1,3 @@
1
+ export const SOURCE_ID_SPLITTER = '__messenger_source_id_splitter__';
2
+
3
+ //# sourceMappingURL=source-id-splitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/iframe/source-id-splitter.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,kCAAkC,CAAC","file":"source-id-splitter.js","sourcesContent":["export const SOURCE_ID_SPLITTER = '__messenger_source_id_splitter__';\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export interface UpcomingMessage<T = any> {
2
+ data: T;
3
+ sender: Window;
4
+ }
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=upcoming-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/iframe/upcoming-message.ts"],"names":[],"mappings":"","file":"upcoming-message.js","sourcesContent":["export interface UpcomingMessage<T = any> {\n data: T;\n sender: Window;\n}\n"]}
package/index.cjs ADDED
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageHost = exports.MessageClient = exports.Listen = exports.Request = void 0;
4
+ const tslib_1 = require("tslib");
5
+ var request_decorator_1 = require("./request.decorator");
6
+ Object.defineProperty(exports, "Request", { enumerable: true, get: function () { return request_decorator_1.Request; } });
7
+ var listen_decorator_1 = require("./listen.decorator");
8
+ Object.defineProperty(exports, "Listen", { enumerable: true, get: function () { return listen_decorator_1.Listen; } });
9
+ var message_client_1 = require("./message-client");
10
+ Object.defineProperty(exports, "MessageClient", { enumerable: true, get: function () { return message_client_1.MessageClient; } });
11
+ var message_host_1 = require("./message-host");
12
+ Object.defineProperty(exports, "MessageHost", { enumerable: true, get: function () { return message_host_1.MessageHost; } });
13
+ tslib_1.__exportStar(require("./selectors"), exports);
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { Request } from './request.decorator';
2
+ export { Listen } from './listen.decorator';
3
+ export type { Message } from './message.interface';
4
+ export type { MessageResponse } from './message-response.type';
5
+ export { MessageClient } from './message-client';
6
+ export { MessageHost } from './message-host';
7
+ export * from './selectors';
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { Request } from './request.decorator';
2
+ export { Listen } from './listen.decorator';
3
+ export { MessageClient } from './message-client';
4
+ export { MessageHost } from './message-host';
5
+ export * from './selectors';
6
+
7
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,cAAc,aAAa,CAAC","file":"index.js","sourcesContent":["export { Request } from './request.decorator';\nexport { Listen } from './listen.decorator';\nexport type { Message } from './message.interface';\nexport type { MessageResponse } from './message-response.type';\nexport { MessageClient } from './message-client';\nexport { MessageHost } from './message-host';\nexport * from './selectors';\n"]}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Listen = Listen;
4
+ const selectors_1 = require("./selectors");
5
+ /**
6
+ * Decorate a generator method to listen messages of a domain and reply them by using `yield`
7
+ *
8
+ * @param path Acts like an api endpoint path of an XHR for extensions messaging
9
+ */
10
+ function Listen(path) {
11
+ return function (target, key, descriptor) {
12
+ if (!target.constructor[selectors_1.MESSAGE_LISTENERS]) {
13
+ target.constructor[selectors_1.MESSAGE_LISTENERS] = new Map();
14
+ }
15
+ target.constructor[selectors_1.MESSAGE_LISTENERS].set(path ?? key, [
16
+ ...(target.constructor[selectors_1.MESSAGE_LISTENERS].get(path ?? key) || []),
17
+ descriptor.value
18
+ ]);
19
+ };
20
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Decorate a generator method to listen messages of a domain and reply them by using `yield`
3
+ *
4
+ * @param path Acts like an api endpoint path of an XHR for extensions messaging
5
+ */
6
+ export declare function Listen(path?: string): MethodDecorator;
@@ -0,0 +1,19 @@
1
+ import { MESSAGE_LISTENERS } from './selectors';
2
+ /**
3
+ * Decorate a generator method to listen messages of a domain and reply them by using `yield`
4
+ *
5
+ * @param path Acts like an api endpoint path of an XHR for extensions messaging
6
+ */
7
+ export function Listen(path) {
8
+ return function (target, key, descriptor) {
9
+ if (!target.constructor[MESSAGE_LISTENERS]) {
10
+ target.constructor[MESSAGE_LISTENERS] = new Map();
11
+ }
12
+ target.constructor[MESSAGE_LISTENERS].set(path ?? key, [
13
+ ...(target.constructor[MESSAGE_LISTENERS].get(path ?? key) || []),
14
+ descriptor.value
15
+ ]);
16
+ };
17
+ }
18
+
19
+ //# sourceMappingURL=listen.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/listen.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,IAAa;IAClC,OAAO,UAAS,MAAM,EAAE,GAAG,EAAE,UAAU;QACrC,IAAI,CAAE,MAAM,CAAC,WAAmB,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACnD,MAAM,CAAC,WAAmB,CAAC,iBAAiB,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;QAC7D,CAAC;QAEC,MAAM,CAAC,WAAmB,CAAC,iBAAiB,CAAqB,CAAC,GAAG,CAAC,IAAK,IAAI,GAAG,EAAE;YACpF,GAAG,CAAE,MAAM,CAAC,WAAmB,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;YAC1E,UAAU,CAAC,KAAK;SACV,CAAC,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC","file":"listen.decorator.js","sourcesContent":["import { ListenerStorage } from './listener-storage.type';\nimport { MESSAGE_LISTENERS } from './selectors';\n\n/**\n * Decorate a generator method to listen messages of a domain and reply them by using `yield`\n *\n * @param path Acts like an api endpoint path of an XHR for extensions messaging\n */\nexport function Listen(path?: string): MethodDecorator {\n return function(target, key, descriptor) {\n if (!(target.constructor as any)[MESSAGE_LISTENERS]) {\n (target.constructor as any)[MESSAGE_LISTENERS] = new Map();\n }\n\n ((target.constructor as any)[MESSAGE_LISTENERS] as ListenerStorage).set(path! ?? key, [\n ...((target.constructor as any)[MESSAGE_LISTENERS].get(path ?? key) || []),\n descriptor.value\n ] as any);\n };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { Observable } from 'rxjs';
2
+ export type ListenerStorage<T = any> = Map<string, ((message: any) => Observable<T>)[]>;
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=listener-storage.type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/listener-storage.type.ts"],"names":[],"mappings":"","file":"listener-storage.type.js","sourcesContent":["import { Observable } from 'rxjs';\n\nexport type ListenerStorage<T = any> = Map<string, ((message: any) => Observable<T>)[]>;\n"]}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageClient = void 0;
4
+ const selectors_1 = require("./selectors");
5
+ /**
6
+ * Message Client
7
+ */
8
+ class MessageClient {
9
+ }
10
+ exports.MessageClient = MessageClient;
@@ -0,0 +1,23 @@
1
+ import { Observable } from 'rxjs';
2
+ import { MessageResponse } from './message-response.type';
3
+ import { Message } from './message.interface';
4
+ import { GET_NEW_ID, RESPONSES$, SEND } from './selectors';
5
+ /**
6
+ * Message Client
7
+ */
8
+ export declare abstract class MessageClient {
9
+ /**
10
+ * Emits all messages got from hosts
11
+ */
12
+ protected abstract readonly [RESPONSES$]: Observable<MessageResponse>;
13
+ /**
14
+ * Request decorators use this method to send messages
15
+ *
16
+ * @param message Message payload to send
17
+ */
18
+ protected abstract [SEND](message: Message): void;
19
+ /**
20
+ * Request decorators use this method to get unique message id all accross the platform
21
+ */
22
+ protected abstract [GET_NEW_ID](): string;
23
+ }
@@ -0,0 +1,8 @@
1
+ import { GET_NEW_ID, RESPONSES$, SEND } from './selectors';
2
+ /**
3
+ * Message Client
4
+ */
5
+ export class MessageClient {
6
+ }
7
+
8
+ //# sourceMappingURL=message-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/message-client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAE3D;;GAEG;AACH,MAAM,OAAgB,aAAa;CAiBlC","file":"message-client.js","sourcesContent":["import { Observable } from 'rxjs';\n\nimport { MessageResponse } from './message-response.type';\nimport { Message } from './message.interface';\nimport { GET_NEW_ID, RESPONSES$, SEND } from './selectors';\n\n/**\n * Message Client\n */\nexport abstract class MessageClient {\n /**\n * Emits all messages got from hosts\n */\n protected abstract readonly [RESPONSES$]: Observable<MessageResponse>;\n\n /**\n * Request decorators use this method to send messages\n *\n * @param message Message payload to send\n */\n protected abstract [SEND](message: Message): void;\n\n /**\n * Request decorators use this method to get unique message id all accross the platform\n */\n protected abstract [GET_NEW_ID](): string;\n}\n"]}
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageHost = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const operators_1 = require("rxjs/operators");
6
+ const selectors_1 = require("./selectors");
7
+ /**
8
+ * Message Host
9
+ */
10
+ class MessageHost {
11
+ /**
12
+ * Message Terminator Subject
13
+ *
14
+ * Use `next(messageId)` method to terminate a message connection
15
+ */
16
+ [selectors_1.TERMINATE_MESSAGE$] = new rxjs_1.Subject();
17
+ /**
18
+ * Run this method to start listening the requests
19
+ */
20
+ [selectors_1.LISTEN] = (messages$) => {
21
+ for (const [path, listeners] of this.#getListeners()) {
22
+ messages$
23
+ .pipe((0, operators_1.filter)(({ path: messagePath }) => path === messagePath))
24
+ .subscribe(({ body, id }) => {
25
+ for (const listener of listeners) {
26
+ listener.call(this, body).pipe((0, operators_1.takeUntil)(this[selectors_1.TERMINATE_MESSAGE$].pipe((0, operators_1.filter)(terminatedMessageId => terminatedMessageId === id)))).subscribe({
27
+ next: result => {
28
+ this[selectors_1.RESPONSE]({ completed: false, id, body: result });
29
+ },
30
+ error: error => {
31
+ this[selectors_1.RESPONSE]({ completed: true, id, error });
32
+ },
33
+ complete: () => {
34
+ this[selectors_1.RESPONSE]({ completed: true, id });
35
+ }
36
+ });
37
+ }
38
+ });
39
+ }
40
+ };
41
+ /**
42
+ * All inherited listeners
43
+ */
44
+ #getListeners() {
45
+ const map = new Map();
46
+ let currentProto = this['__proto__' + ''];
47
+ while (currentProto.constructor !== Object) {
48
+ if (Reflect.ownKeys(currentProto.constructor).includes(selectors_1.MESSAGE_LISTENERS)) {
49
+ for (const [key, handlers] of currentProto.constructor[selectors_1.MESSAGE_LISTENERS]) {
50
+ map.set(key, [...(map.get(key) || []), ...handlers]);
51
+ }
52
+ }
53
+ currentProto = currentProto.__proto__;
54
+ }
55
+ return map;
56
+ }
57
+ }
58
+ exports.MessageHost = MessageHost;
@@ -0,0 +1,26 @@
1
+ import { Observable, Subject } from 'rxjs';
2
+ import { SuccessfulMessageResponse } from './message-response.type';
3
+ import { Message } from './message.interface';
4
+ import { LISTEN, RESPONSE, TERMINATE_MESSAGE$ } from './selectors';
5
+ /**
6
+ * Message Host
7
+ */
8
+ export declare abstract class MessageHost {
9
+ #private;
10
+ /**
11
+ * Message Terminator Subject
12
+ *
13
+ * Use `next(messageId)` method to terminate a message connection
14
+ */
15
+ protected readonly [TERMINATE_MESSAGE$]: Subject<string>;
16
+ /**
17
+ * Run this method to start listening the requests
18
+ */
19
+ protected readonly [LISTEN]: (messages$: Observable<Message>) => void;
20
+ /**
21
+ * Build a reponse method to send the responses to the requests by using the communication methods of the platform
22
+ *
23
+ * @param message Incoming response message
24
+ */
25
+ protected abstract [RESPONSE]<T = any>(message: SuccessfulMessageResponse<T>): void;
26
+ }
@@ -0,0 +1,56 @@
1
+ import { Subject } from 'rxjs';
2
+ import { filter, takeUntil } from 'rxjs/operators';
3
+ import { LISTEN, MESSAGE_LISTENERS, RESPONSE, TERMINATE_MESSAGE$ } from './selectors';
4
+ /**
5
+ * Message Host
6
+ */
7
+ export class MessageHost {
8
+ /**
9
+ * Message Terminator Subject
10
+ *
11
+ * Use `next(messageId)` method to terminate a message connection
12
+ */
13
+ [TERMINATE_MESSAGE$] = new Subject();
14
+ /**
15
+ * Run this method to start listening the requests
16
+ */
17
+ [LISTEN] = (messages$) => {
18
+ for (const [path, listeners] of this.#getListeners()) {
19
+ messages$
20
+ .pipe(filter(({ path: messagePath }) => path === messagePath))
21
+ .subscribe(({ body, id }) => {
22
+ for (const listener of listeners) {
23
+ listener.call(this, body).pipe(takeUntil(this[TERMINATE_MESSAGE$].pipe(filter(terminatedMessageId => terminatedMessageId === id)))).subscribe({
24
+ next: result => {
25
+ this[RESPONSE]({ completed: false, id, body: result });
26
+ },
27
+ error: error => {
28
+ this[RESPONSE]({ completed: true, id, error });
29
+ },
30
+ complete: () => {
31
+ this[RESPONSE]({ completed: true, id });
32
+ }
33
+ });
34
+ }
35
+ });
36
+ }
37
+ };
38
+ /**
39
+ * All inherited listeners
40
+ */
41
+ #getListeners() {
42
+ const map = new Map();
43
+ let currentProto = this['__proto__' + ''];
44
+ while (currentProto.constructor !== Object) {
45
+ if (Reflect.ownKeys(currentProto.constructor).includes(MESSAGE_LISTENERS)) {
46
+ for (const [key, handlers] of currentProto.constructor[MESSAGE_LISTENERS]) {
47
+ map.set(key, [...(map.get(key) || []), ...handlers]);
48
+ }
49
+ }
50
+ currentProto = currentProto.__proto__;
51
+ }
52
+ return map;
53
+ }
54
+ }
55
+
56
+ //# sourceMappingURL=message-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/message-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKnD,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtF;;GAEG;AACH,MAAM,OAAgB,WAAW;IAC/B;;;;OAIG;IACgB,CAAC,kBAAkB,CAAC,GAAG,IAAI,OAAO,EAAU,CAAC;IAEhE;;OAEG;IACgB,CAAC,MAAM,CAAC,GAAG,CAAC,SAA8B,EAAQ,EAAE;QACrE,KAAK,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,IAAI,CAAC,aAAa,EAAE,EAAE,CAAC;YACrD,SAAS;iBACN,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC;iBAC7D,SAAS,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE;gBAC1B,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;oBAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAqB,CAAC,IAAI,CACjD,SAAS,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,CAAC,mBAAmB,KAAK,EAAE,CAAC,CAAC,CAAC,CACpG,CAAC,SAAS,CAAC;wBACV,IAAI,EAAE,MAAM,CAAC,EAAE;4BACb,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;wBACzD,CAAC;wBACD,KAAK,EAAE,KAAK,CAAC,EAAE;4BACb,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;wBACjD,CAAC;wBACD,QAAQ,EAAE,GAAG,EAAE;4BACb,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;wBAC1C,CAAC;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC,CAAC,CAAC;QACP,CAAC;IACH,CAAC,CAAC;IASF;;OAEG;IACH,aAAa;QACX,MAAM,GAAG,GAAoB,IAAI,GAAG,EAAE,CAAC;QACvC,IAAI,YAAY,GAAI,IAAY,CAAC,WAAW,GAAG,EAAE,CAAC,CAAC;QAEnD,OAAO,YAAY,CAAC,WAAW,KAAK,MAAM,EAAE,CAAC;YAC3C,IAAI,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;gBAC1E,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,YAAY,CAAC,WAAW,CAAC,iBAAiB,CAAoB,EAAE,CAAC;oBAC7F,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;gBACvD,CAAC;YACH,CAAC;YAED,YAAY,GAAG,YAAY,CAAC,SAAS,CAAC;QACxC,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF","file":"message-host.js","sourcesContent":["import { Observable, Subject } from 'rxjs';\nimport { filter, takeUntil } from 'rxjs/operators';\n\nimport { ListenerStorage } from './listener-storage.type';\nimport { SuccessfulMessageResponse } from './message-response.type';\nimport { Message } from './message.interface';\nimport { LISTEN, MESSAGE_LISTENERS, RESPONSE, TERMINATE_MESSAGE$ } from './selectors';\n\n/**\n * Message Host\n */\nexport abstract class MessageHost {\n /**\n * Message Terminator Subject\n *\n * Use `next(messageId)` method to terminate a message connection\n */\n protected readonly [TERMINATE_MESSAGE$] = new Subject<string>();\n\n /**\n * Run this method to start listening the requests\n */\n protected readonly [LISTEN] = (messages$: Observable<Message>): void => {\n for (const [path, listeners] of this.#getListeners()) {\n messages$\n .pipe(filter(({ path: messagePath }) => path === messagePath))\n .subscribe(({ body, id }) => {\n for (const listener of listeners) {\n (listener.call(this, body) as Observable<any>).pipe(\n takeUntil(this[TERMINATE_MESSAGE$].pipe(filter(terminatedMessageId => terminatedMessageId === id))),\n ).subscribe({\n next: result => {\n this[RESPONSE]({ completed: false, id, body: result });\n },\n error: error => {\n this[RESPONSE]({ completed: true, id, error });\n },\n complete: () => {\n this[RESPONSE]({ completed: true, id });\n }\n });\n }\n });\n }\n };\n\n /**\n * Build a reponse method to send the responses to the requests by using the communication methods of the platform\n *\n * @param message Incoming response message\n */\n protected abstract [RESPONSE]<T = any>(message: SuccessfulMessageResponse<T>): void;\n\n /**\n * All inherited listeners\n */\n #getListeners(): ListenerStorage {\n const map: ListenerStorage = new Map();\n let currentProto = (this as any)['__proto__' + ''];\n\n while (currentProto.constructor !== Object) {\n if (Reflect.ownKeys(currentProto.constructor).includes(MESSAGE_LISTENERS)) {\n for (const [key, handlers] of currentProto.constructor[MESSAGE_LISTENERS] as ListenerStorage) {\n map.set(key, [...(map.get(key) || []), ...handlers]);\n }\n }\n\n currentProto = currentProto.__proto__;\n }\n\n return map;\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import { Message } from './message.interface';
2
+ type Omit<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
3
+ export type UncompletedMessageResponse<T = any> = Omit<Message<T>, 'path'> & {
4
+ completed: false;
5
+ };
6
+ type CompletedMessageResponse = Omit<Message, 'body' | 'path'> & {
7
+ completed: true;
8
+ };
9
+ export type ErrorMessageResponse = {
10
+ error: any;
11
+ id: string;
12
+ completed: true;
13
+ };
14
+ export type SuccessfulMessageResponse<T = any> = UncompletedMessageResponse<T> | CompletedMessageResponse;
15
+ export type MessageResponse<T = any> = SuccessfulMessageResponse<T> | ErrorMessageResponse;
16
+ export {};
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=message-response.type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/message-response.type.ts"],"names":[],"mappings":"","file":"message-response.type.js","sourcesContent":["import { Message } from './message.interface';\n\ntype Omit<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;\n\nexport type UncompletedMessageResponse<T = any> = Omit<Message<T>, 'path'> & { completed: false; };\ntype CompletedMessageResponse = Omit<Message, 'body' | 'path'> & { completed: true; };\n\nexport type ErrorMessageResponse = {error: any; id: string; completed: true; };\nexport type SuccessfulMessageResponse<T = any> = UncompletedMessageResponse<T> | CompletedMessageResponse;\n\nexport type MessageResponse<T = any> = SuccessfulMessageResponse<T> | ErrorMessageResponse;\n"]}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export interface Message<T = any> {
2
+ path: string;
3
+ body: T;
4
+ id: string;
5
+ error?: any;
6
+ }
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=message.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/message.interface.ts"],"names":[],"mappings":"","file":"message.interface.js","sourcesContent":["export interface Message<T = any> {\n path: string;\n body: T;\n id: string;\n error?: any;\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,158 @@
1
+ {
2
+ "name": "@telperion/messenger",
3
+ "version": "7.6.1",
4
+ "description": "Javascript messaging library",
5
+ "keywords": [
6
+ "javascript",
7
+ "messaging",
8
+ "send",
9
+ "message",
10
+ "chrome",
11
+ "extension",
12
+ "extensions",
13
+ "nodejs",
14
+ "child",
15
+ "process",
16
+ "webworkers"
17
+ ],
18
+ "homepage": "https://open-source.telperion.tr/messenger",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/telperiontech/telperion.git",
22
+ "directory": "libs/messenger"
23
+ },
24
+ "dependencies": {
25
+ "@telperion/js-utils": "^3.5.0",
26
+ "rxjs": "^7.8.1",
27
+ "tslib": "^2.3.0"
28
+ },
29
+ "type": "module",
30
+ "module": "./index.js",
31
+ "main": "./index.cjs",
32
+ "typings": "./index.d.ts",
33
+ "bugs": "https://github.com/telperiontech/telperion/issues",
34
+ "license": "MIT",
35
+ "author": {
36
+ "name": "Ali Şahin Özçelik",
37
+ "email": "alisahinozcelik@gmail.com",
38
+ "url": "https://alisah.in"
39
+ },
40
+ "funding": {
41
+ "type": "patreon",
42
+ "url": "https://www.patreon.com/alisahin"
43
+ },
44
+ "exports": {
45
+ ".": {
46
+ "default": "./index.cjs",
47
+ "import": "./index.js",
48
+ "node": "./index.cjs",
49
+ "require": "./index.cjs",
50
+ "types": "./index.d.ts"
51
+ },
52
+ "./broadcast": {
53
+ "default": "./broadcast/index.cjs",
54
+ "import": "./broadcast/index.js",
55
+ "node": "./broadcast/index.cjs",
56
+ "require": "./broadcast/index.cjs",
57
+ "types": "./broadcast/index.d.ts"
58
+ },
59
+ "./broadcast/message-client": {
60
+ "default": "./broadcast/message-client.cjs",
61
+ "import": "./broadcast/message-client.js",
62
+ "node": "./broadcast/message-client.cjs",
63
+ "require": "./broadcast/message-client.cjs",
64
+ "types": "./broadcast/message-client.d.ts"
65
+ },
66
+ "./broadcast/message-host": {
67
+ "default": "./broadcast/message-host.cjs",
68
+ "import": "./broadcast/message-host.js",
69
+ "node": "./broadcast/message-host.cjs",
70
+ "require": "./broadcast/message-host.cjs",
71
+ "types": "./broadcast/message-host.d.ts"
72
+ },
73
+ "./broadcast/message-service": {
74
+ "default": "./broadcast/message-service.cjs",
75
+ "import": "./broadcast/message-service.js",
76
+ "node": "./broadcast/message-service.cjs",
77
+ "require": "./broadcast/message-service.cjs",
78
+ "types": "./broadcast/message-service.d.ts"
79
+ },
80
+ "./chrome": {
81
+ "default": "./chrome/index.cjs",
82
+ "import": "./chrome/index.js",
83
+ "node": "./chrome/index.cjs",
84
+ "require": "./chrome/index.cjs",
85
+ "types": "./chrome/index.d.ts"
86
+ },
87
+ "./chrome/message-client": {
88
+ "default": "./chrome/message-client.cjs",
89
+ "import": "./chrome/message-client.js",
90
+ "node": "./chrome/message-client.cjs",
91
+ "require": "./chrome/message-client.cjs",
92
+ "types": "./chrome/message-client.d.ts"
93
+ },
94
+ "./chrome/message-host": {
95
+ "default": "./chrome/message-host.cjs",
96
+ "import": "./chrome/message-host.js",
97
+ "node": "./chrome/message-host.cjs",
98
+ "require": "./chrome/message-host.cjs",
99
+ "types": "./chrome/message-host.d.ts"
100
+ },
101
+ "./iframe": {
102
+ "default": "./iframe/index.cjs",
103
+ "import": "./iframe/index.js",
104
+ "node": "./iframe/index.cjs",
105
+ "require": "./iframe/index.cjs",
106
+ "types": "./iframe/index.d.ts"
107
+ },
108
+ "./iframe/message-client": {
109
+ "default": "./iframe/message-client.cjs",
110
+ "import": "./iframe/message-client.js",
111
+ "node": "./iframe/message-client.cjs",
112
+ "require": "./iframe/message-client.cjs",
113
+ "types": "./iframe/message-client.d.ts"
114
+ },
115
+ "./iframe/message-host": {
116
+ "default": "./iframe/message-host.cjs",
117
+ "import": "./iframe/message-host.js",
118
+ "node": "./iframe/message-host.cjs",
119
+ "require": "./iframe/message-host.cjs",
120
+ "types": "./iframe/message-host.d.ts"
121
+ },
122
+ "./iframe/message-service": {
123
+ "default": "./iframe/message-service.cjs",
124
+ "import": "./iframe/message-service.js",
125
+ "node": "./iframe/message-service.cjs",
126
+ "require": "./iframe/message-service.cjs",
127
+ "types": "./iframe/message-service.d.ts"
128
+ },
129
+ "./worker": {
130
+ "default": "./worker/index.cjs",
131
+ "import": "./worker/index.js",
132
+ "node": "./worker/index.cjs",
133
+ "require": "./worker/index.cjs",
134
+ "types": "./worker/index.d.ts"
135
+ },
136
+ "./worker/message-client": {
137
+ "default": "./worker/message-client.cjs",
138
+ "import": "./worker/message-client.js",
139
+ "node": "./worker/message-client.cjs",
140
+ "require": "./worker/message-client.cjs",
141
+ "types": "./worker/message-client.d.ts"
142
+ },
143
+ "./worker/message-host": {
144
+ "default": "./worker/message-host.cjs",
145
+ "import": "./worker/message-host.js",
146
+ "node": "./worker/message-host.cjs",
147
+ "require": "./worker/message-host.cjs",
148
+ "types": "./worker/message-host.d.ts"
149
+ },
150
+ "./worker/message-service": {
151
+ "default": "./worker/message-service.cjs",
152
+ "import": "./worker/message-service.js",
153
+ "node": "./worker/message-service.cjs",
154
+ "require": "./worker/message-service.cjs",
155
+ "types": "./worker/message-service.d.ts"
156
+ }
157
+ }
158
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Request = Request;
4
+ const operators_1 = require("rxjs/operators");
5
+ const selectors_1 = require("./selectors");
6
+ function Request(path) {
7
+ return function (target, key, descriptor) {
8
+ descriptor.value = function (message) {
9
+ const messageId = this[selectors_1.GET_NEW_ID]();
10
+ this[selectors_1.SEND]({ body: message, id: messageId, path });
11
+ return this[selectors_1.RESPONSES$].pipe((0, operators_1.filter)(({ id }) => id === messageId), (0, operators_1.map)((data) => {
12
+ const { error } = data;
13
+ if (error)
14
+ throw error;
15
+ return data;
16
+ }), (0, operators_1.takeWhile)((res) => !res.completed), (0, operators_1.map)(({ body }) => body));
17
+ };
18
+ return descriptor;
19
+ };
20
+ }
@@ -0,0 +1 @@
1
+ export declare function Request(path: string): MethodDecorator;
@@ -0,0 +1,19 @@
1
+ import { filter, map, takeWhile } from 'rxjs/operators';
2
+ import { GET_NEW_ID, RESPONSES$, SEND } from './selectors';
3
+ export function Request(path) {
4
+ return function (target, key, descriptor) {
5
+ descriptor.value = function (message) {
6
+ const messageId = this[GET_NEW_ID]();
7
+ this[SEND]({ body: message, id: messageId, path });
8
+ return this[RESPONSES$].pipe(filter(({ id }) => id === messageId), map((data) => {
9
+ const { error } = data;
10
+ if (error)
11
+ throw error;
12
+ return data;
13
+ }), takeWhile((res) => !res.completed), map(({ body }) => body));
14
+ };
15
+ return descriptor;
16
+ };
17
+ }
18
+
19
+ //# sourceMappingURL=request.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../libs/messenger/src/request.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAG3D,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,UAAS,MAAM,EAAE,GAAG,EAAE,UAAwC;QACnE,UAAU,CAAC,KAAK,GAAG,UAA8B,OAAY;YAC3D,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAErC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAEnD,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,IAAI,CAC1B,MAAM,CAAC,CAAC,EAAC,EAAE,EAAC,EAAE,EAAE,CAAC,EAAE,KAAK,SAAS,CAAC,EAClC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;gBACX,MAAM,EAAE,KAAK,EAAE,GAAG,IAA4B,CAAC;gBAE/C,IAAI,KAAK;oBAAE,MAAM,KAAK,CAAC;gBAEvB,OAAO,IAAiC,CAAC;YAC3C,CAAC,CAAC,EACF,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,EAClC,GAAG,CAAC,CAAC,EAAE,IAAI,EAA8B,EAAE,EAAE,CAAC,IAAI,CAAC,CACpD,CAAC;QACJ,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC","file":"request.decorator.js","sourcesContent":["import { filter, map, takeWhile } from 'rxjs/operators';\n\nimport { MessageClient } from './message-client';\nimport { GET_NEW_ID, RESPONSES$, SEND } from './selectors';\nimport { ErrorMessageResponse, SuccessfulMessageResponse, UncompletedMessageResponse } from './message-response.type';\n\nexport function Request(path: string): MethodDecorator {\n return function(target, key, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> {\n descriptor.value = function(this: MessageClient, message: any) {\n const messageId = this[GET_NEW_ID]();\n\n this[SEND]({ body: message, id: messageId, path });\n\n return this[RESPONSES$].pipe(\n filter(({id}) => id === messageId),\n map((data) => {\n const { error } = data as ErrorMessageResponse;\n\n if (error) throw error;\n\n return data as SuccessfulMessageResponse;\n }),\n takeWhile((res) => !res.completed),\n map(({ body }: UncompletedMessageResponse) => body),\n );\n };\n\n return descriptor;\n };\n}\n"]}
package/selectors.cjs ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RESPONSE = exports.TERMINATE_MESSAGE$ = exports.LISTEN = exports.GET_NEW_ID = exports.SEND = exports.RESPONSES$ = exports.MESSAGE_LISTENERS = void 0;
4
+ exports.MESSAGE_LISTENERS = Symbol('Message Listeners');
5
+ exports.RESPONSES$ = Symbol('Responses');
6
+ exports.SEND = Symbol('Send');
7
+ exports.GET_NEW_ID = Symbol('Get New Id');
8
+ exports.LISTEN = Symbol('Listen');
9
+ exports.TERMINATE_MESSAGE$ = Symbol('Terminate Message');
10
+ exports.RESPONSE = Symbol('Response');
package/selectors.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export declare const MESSAGE_LISTENERS: unique symbol;
2
+ export declare const RESPONSES$: unique symbol;
3
+ export declare const SEND: unique symbol;
4
+ export declare const GET_NEW_ID: unique symbol;
5
+ export declare const LISTEN: unique symbol;
6
+ export declare const TERMINATE_MESSAGE$: unique symbol;
7
+ export declare const RESPONSE: unique symbol;