@effect.healthcare/messenger 0.3.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.
package/LICENSE ADDED
@@ -0,0 +1,144 @@
1
+ Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License
2
+
3
+ By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions.
4
+
5
+ Section 1 – Definitions.
6
+ a. Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image.
7
+
8
+ b. Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License.
9
+
10
+ c. BY-NC-SA Compatible License means a license listed at creativecommons.org/compatiblelicenses, approved by Creative Commons as essentially the equivalent of this Public License.
11
+
12
+ d. Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights.
13
+
14
+ e. Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements.
15
+
16
+ f. Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.
17
+
18
+ g. License Elements means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution, NonCommercial, and ShareAlike.
19
+
20
+ h. Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License.
21
+
22
+ i. Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.
23
+
24
+ h. Licensor means the individual(s) or entity(ies) granting rights under this Public License.
25
+
26
+ i. NonCommercial means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange.
27
+
28
+ j. Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.
29
+
30
+ k. Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.
31
+
32
+ l. You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning.
33
+
34
+ Section 2 – Scope.
35
+ a. License grant.
36
+
37
+ Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:
38
+ A. reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and
39
+
40
+ B. produce, reproduce, and Share Adapted Material for NonCommercial purposes only.
41
+
42
+ Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions.
43
+
44
+ Term. The term of this Public License is specified in Section 6(a).
45
+
46
+ Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material.
47
+
48
+ Downstream recipients.
49
+
50
+ A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License.
51
+
52
+ B. Additional offer from the Licensor – Adapted Material. Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply.
53
+
54
+ C. No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.
55
+
56
+ No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i).
57
+ b. Other rights.
58
+
59
+ Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise.
60
+
61
+ Patent and trademark rights are not licensed under this Public License.
62
+
63
+ To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes.
64
+
65
+ Section 3 – License Conditions.
66
+ Your exercise of the Licensed Rights is expressly made subject to the following conditions.
67
+
68
+ a. Attribution.
69
+
70
+ If You Share the Licensed Material (including in modified form), You must:
71
+ A. retain the following if it is supplied by the Licensor with the Licensed Material:
72
+
73
+ i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated);
74
+
75
+ ii. a copyright notice;
76
+
77
+ iii. a notice that refers to this Public License;
78
+
79
+ iv. a notice that refers to the disclaimer of warranties;
80
+
81
+ v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable;
82
+
83
+ B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and
84
+
85
+ C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License.
86
+
87
+ You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.
88
+
89
+ If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable.
90
+
91
+ b. ShareAlike.
92
+
93
+ In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply.
94
+
95
+ The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-NC-SA Compatible License.
96
+
97
+ You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material.
98
+
99
+ You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply.
100
+
101
+ Section 4 – Sui Generis Database Rights.
102
+ Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:
103
+
104
+ a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only;
105
+
106
+ b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and
107
+
108
+ c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database.
109
+
110
+ For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights.
111
+
112
+ Section 5 – Disclaimer of Warranties and Limitation of Liability.
113
+ a. Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.
114
+
115
+ b. To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.
116
+
117
+ c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability.
118
+
119
+ Section 6 – Term and Termination.
120
+ a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically.
121
+
122
+ b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates:
123
+
124
+ automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or
125
+
126
+ automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or
127
+
128
+ For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License.
129
+
130
+ c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License.
131
+
132
+ d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License.
133
+
134
+ Section 7 – Other Terms and Conditions.
135
+ a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed.
136
+
137
+ b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License.
138
+
139
+ Section 8 – Interpretation.
140
+ a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License.
141
+
142
+ b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions.
143
+
144
+ c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ ![License: CC BY-NC-SA 4.0](https://flat.badgen.net/static/license/CC-BY-NC-SA-4.0/green)
2
+
3
+ # Messenger
4
+
5
+ `@effect.healthcare/messenger` (`<app-messenger>`) is a **headless** web component that bridges your application to an Azure Web PubSub hub. It authenticates with the session token in local storage, negotiates a short‑lived client access URL, opens a live connection, and dispatches inbound master‑data‑change notifications as a semantic DOM event.
6
+
7
+ It renders nothing — no template, no styles. You configure it, bind an event, and call `connect()`.
8
+
9
+ > This foundation is **receive‑only**; outbound collaboration messaging is a future capability.
10
+
11
+ ## Overview
12
+
13
+ ```js
14
+ import { Messenger } from "@effect.healthcare/messenger";
15
+
16
+ // Register the element
17
+ customElements.define(Messenger.Tag, Messenger);
18
+
19
+ // Get the instance (or place <app-messenger> in your HTML)
20
+ const messenger = await Messenger.get();
21
+
22
+ // Bind the event you care about
23
+ messenger.onmasterdatachange = (event) =>
24
+ console.log("master data changed at", event.detail.datetime);
25
+
26
+ // Configure the negotiate endpoint, then connect
27
+ messenger.endpoint = "https://your-api/realtime/master-data/negotiate";
28
+ await messenger.connect();
29
+ ```
30
+
31
+ ### 1. Configuration
32
+
33
+ Two inputs drive the messenger:
34
+
35
+ - **`endpoint`** — the negotiate URL of the hub. It is an attribute‑backed state, so set it either as a property or as an attribute:
36
+
37
+ ```html
38
+ <app-messenger endpoint="https://your-api/realtime/master-data/negotiate"></app-messenger>
39
+ ```
40
+
41
+ ```js
42
+ messenger.endpoint = "https://your-api/realtime/master-data/negotiate";
43
+ ```
44
+
45
+ - **Session token** — read **fresh on every connect attempt** from local storage under the key **`app-license.session`**. Your application (e.g. the License component) must have written it before connecting. The messenger never logs in itself.
46
+
47
+ ### 2. Binding to `onmasterdatachange`
48
+
49
+ The messenger dispatches **`onmasterdatachange`** whenever the server signals a master‑data change. The payload carries the receipt time:
50
+
51
+ ```js
52
+ messenger.onmasterdatachange = (event) => {
53
+ const { datetime } = event.detail; // ISO-8601 timestamp
54
+ // re-sync your application data here
55
+ };
56
+ ```
57
+
58
+ Assigning a handler replaces the previous one; assign `null` to remove it.
59
+
60
+ ### 3. Connecting
61
+
62
+ ```js
63
+ await messenger.connect(); // negotiates + opens the live connection
64
+ messenger.disconnect(); // closes the connection
65
+ ```
66
+
67
+ `connect()` is a **no‑op** unless both an `endpoint` and a session token are available, or when already connecting/connected — so it is safe to call repeatedly.
68
+
69
+ ### Connection lifecycle events
70
+
71
+ Observe the live status if you need to coordinate around it. Each `event.detail.connection` is one of `connecting` | `connected` | `disconnected`:
72
+
73
+ | Event | Fires when |
74
+ | --- | --- |
75
+ | `onconnecting` | a connection attempt starts |
76
+ | `onconnected` | the live connection opens |
77
+ | `ondisconnected` | the connection closes |
78
+ | `onendpointchange` | the `endpoint` changes (`event.detail.endpoint`) |
79
+
80
+ ## Development
81
+
82
+ ```bash
83
+ npm install # install dependencies
84
+ npm test # run the suite (coverage in ./coverage, report in ./report)
85
+ npm run document # generate API docs into ./docs
86
+ ```
87
+
88
+ ## License
89
+
90
+ > This software and its documentation are released under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License (CC BY-NC-SA 4.0). This means you are free to share, copy, distribute, and transmit the work, and to adapt it, but only under the following conditions:
91
+ >
92
+ > Attribution: You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
93
+ >
94
+ > NonCommercial: You may not use this material for commercial purposes.
95
+ >
96
+ > ShareAlike: If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
97
+ >
98
+ > For more details, please visit the full [license agreement](https://creativecommons.org/licenses/by-nc-sa/4.0/).
package/dist/.gitkeep ADDED
@@ -0,0 +1 @@
1
+ gitkeep
@@ -0,0 +1,6 @@
1
+ /* =======================
2
+ Host Element Styles
3
+ ======================= */
4
+ :host {
5
+ display: inline-block;
6
+ }
@@ -0,0 +1 @@
1
+ <template id="component-template"> </template>
@@ -0,0 +1,3 @@
1
+ export { Tag, Session, Protocol, Message, Attributes, State, Connection, Operation, Event, Gesture, } from "./messenger.meta.js";
2
+ export { Validate } from "./messenger.validation.js";
3
+ export { Messenger } from "./messenger.js";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { Tag, Session, Protocol, Message, Attributes, State, Connection, Operation, Event, Gesture, } from "./messenger.meta.js";
2
+ export { Validate } from "./messenger.validation.js";
3
+ export { Messenger } from "./messenger.js";
@@ -0,0 +1,181 @@
1
+ /**
2
+ * @module Component
3
+ */
4
+ import { Component } from "@scalable.software/component";
5
+ import { type Configuration } from "@scalable.software/component";
6
+ import { Attributes, Connection } from "./messenger.meta.js";
7
+ import { type Endpoint } from "./messenger.meta.js";
8
+ /**
9
+ * Configuration for the headless component — no template or stylesheet.
10
+ * @category Configuration
11
+ */
12
+ export declare const configuration: Configuration;
13
+ /**
14
+ * @category Component
15
+ */
16
+ export declare class Messenger extends Component {
17
+ /**
18
+ * The tag name of the component
19
+ * @category Configuration
20
+ */
21
+ static get Tag(): "app-messenger";
22
+ /**
23
+ * Only attributes defined the Attributes object will be observed in DOM
24
+ * @category State
25
+ */
26
+ static get Attributes(): Attributes;
27
+ /**
28
+ * The live connection status of the messenger. Internally owned.
29
+ * @category State
30
+ * @hidden
31
+ */
32
+ private _connection;
33
+ /**
34
+ * The negotiate endpoint URL. When absent the messenger stays disconnected.
35
+ * @category State
36
+ * @hidden
37
+ */
38
+ private _endpoint;
39
+ /**
40
+ * The live Web PubSub socket. Held so it can be closed and replaced.
41
+ * @category State
42
+ * @hidden
43
+ */
44
+ private _socket;
45
+ /**
46
+ * Event subscription handler slots.
47
+ * @category Event
48
+ * @hidden
49
+ */
50
+ private _onendpointchange;
51
+ private _onconnecting;
52
+ private _onconnected;
53
+ private _ondisconnected;
54
+ private _onmasterdatachange;
55
+ /**
56
+ * Cache element references to improve performance
57
+ * @category State
58
+ * @hidden
59
+ */
60
+ protected elements: {};
61
+ /**
62
+ * @hidden
63
+ */
64
+ constructor();
65
+ /**
66
+ * The live connection status of the messenger. Internally owned — readable
67
+ * externally, but only mutable from within (protected setter).
68
+ * @category State
69
+ */
70
+ get connection(): Connection;
71
+ protected set connection(connection: Connection);
72
+ /**
73
+ * The negotiate endpoint URL. When absent the messenger stays disconnected.
74
+ * @category State
75
+ */
76
+ get endpoint(): Endpoint | null;
77
+ set endpoint(endpoint: Endpoint | null);
78
+ /**
79
+ * The session token, read fresh from local storage on every access — never
80
+ * cached — because the License component renews and rewrites the key.
81
+ * @category Operation
82
+ * @hidden
83
+ */
84
+ private get _token();
85
+ /**
86
+ * Negotiates a client access URL from the configured endpoint, authenticating
87
+ * with the session token, then opens the live connection. No-op when the
88
+ * endpoint or token is unavailable, or when already connecting or connected.
89
+ * @category Operation
90
+ */
91
+ connect: () => Promise<void>;
92
+ /**
93
+ * Closes the live connection.
94
+ * @category Operation
95
+ */
96
+ disconnect: () => void;
97
+ /**
98
+ * Subscribes to the `onendpointchange` event. Assigning replaces the previous
99
+ * handler; assigning `null` removes it.
100
+ * @category Event
101
+ */
102
+ set onendpointchange(handler: EventListener | null);
103
+ /**
104
+ * Subscribes to the `onconnecting` event. Assigning replaces the previous
105
+ * handler; assigning `null` removes it.
106
+ * @category Event
107
+ */
108
+ set onconnecting(handler: EventListener | null);
109
+ /**
110
+ * Subscribes to the `onconnected` event. Assigning replaces the previous
111
+ * handler; assigning `null` removes it.
112
+ * @category Event
113
+ */
114
+ set onconnected(handler: EventListener | null);
115
+ /**
116
+ * Subscribes to the `ondisconnected` event. Assigning replaces the previous
117
+ * handler; assigning `null` removes it.
118
+ * @category Event
119
+ */
120
+ set ondisconnected(handler: EventListener | null);
121
+ /**
122
+ * Subscribes to the `onmasterdatachange` event. Assigning replaces the
123
+ * previous handler; assigning `null` removes it.
124
+ * @category Event
125
+ */
126
+ set onmasterdatachange(handler: EventListener | null);
127
+ /**
128
+ * List operations to perform for selected attributes being observed in the DOM.
129
+ * @category Configuration
130
+ * @hidden
131
+ */
132
+ protected _attributeHandlers: {
133
+ connection: (value: Connection) => false | void;
134
+ endpoint: (value: Endpoint) => string;
135
+ };
136
+ /**
137
+ * Cache element references to improve performance
138
+ * @category Configuration
139
+ * @hidden
140
+ */
141
+ protected _cache: () => void;
142
+ /**
143
+ * Initialize component attributes with default values
144
+ * @category Configuration
145
+ * @hidden
146
+ */
147
+ protected _initialize: () => void;
148
+ /**
149
+ * Called by the connectedCallback prototypical method
150
+ * @category Configuration
151
+ * @hidden
152
+ */
153
+ protected _addEventListeners: () => void;
154
+ /**
155
+ * Called by the disconnectedCallback prototypical method
156
+ * @category Configuration
157
+ * @hidden
158
+ */
159
+ protected _removeEventListeners: () => void;
160
+ /**
161
+ * Negotiates a short-lived Web PubSub client access URL from the endpoint,
162
+ * authenticating the request with the session token.
163
+ * @category Operation
164
+ * @hidden
165
+ */
166
+ private _negotiate;
167
+ /**
168
+ * Opens a Web PubSub WebSocket with the required subprotocol and wires the
169
+ * connection lifecycle handlers.
170
+ * @category Operation
171
+ * @hidden
172
+ */
173
+ private _open;
174
+ /**
175
+ * Handles an inbound Web PubSub message (the `message` gesture). Dispatches
176
+ * `onmasterdatachange` when the payload's `data.type` is `masterData.changed`.
177
+ * @category Gesture
178
+ * @hidden
179
+ */
180
+ private _handleMessage;
181
+ }