@zolomedia/bifrost-client 1.7.74

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 (140) hide show
  1. package/L1_Foundation/L1_Foundation.js +13 -0
  2. package/L1_Foundation/bootstrap/bootstrap.js +11 -0
  3. package/L1_Foundation/bootstrap/bootstrap_hooks.js +123 -0
  4. package/L1_Foundation/bootstrap/bootstrap_index.js +15 -0
  5. package/L1_Foundation/bootstrap/bootstrap_logger.js +135 -0
  6. package/L1_Foundation/bootstrap/cdn_loader.js +217 -0
  7. package/L1_Foundation/bootstrap/module_registry.js +102 -0
  8. package/L1_Foundation/bootstrap/prism_loader.js +164 -0
  9. package/L1_Foundation/config/client_config.js +110 -0
  10. package/L1_Foundation/config/config.js +7 -0
  11. package/L1_Foundation/connection/connection.js +8 -0
  12. package/L1_Foundation/connection/websocket_connection.js +122 -0
  13. package/L1_Foundation/constants/bifrost_constants.js +284 -0
  14. package/L1_Foundation/constants/constants.js +7 -0
  15. package/L1_Foundation/logger/logger.js +10 -0
  16. package/L2_Handling/L2_Handling.js +15 -0
  17. package/L2_Handling/cache/cache.js +22 -0
  18. package/L2_Handling/cache/cache_constants.js +69 -0
  19. package/L2_Handling/cache/orchestration/cache_manager.js +299 -0
  20. package/L2_Handling/cache/orchestration/cache_orchestrator.js +260 -0
  21. package/L2_Handling/cache/orchestration/orchestration.js +12 -0
  22. package/L2_Handling/cache/storage/session_manager.js +289 -0
  23. package/L2_Handling/cache/storage/storage.js +10 -0
  24. package/L2_Handling/cache/storage/storage_manager.js +590 -0
  25. package/L2_Handling/display/composite/composite.js +13 -0
  26. package/L2_Handling/display/composite/dashboard_renderer.js +221 -0
  27. package/L2_Handling/display/composite/swiper_renderer.js +564 -0
  28. package/L2_Handling/display/composite/terminal_renderer.js +922 -0
  29. package/L2_Handling/display/composite/wizard_conditional_renderer.js +274 -0
  30. package/L2_Handling/display/display.js +30 -0
  31. package/L2_Handling/display/feedback/feedback.js +11 -0
  32. package/L2_Handling/display/feedback/progressbar_renderer.js +418 -0
  33. package/L2_Handling/display/feedback/spinner_renderer.js +246 -0
  34. package/L2_Handling/display/inputs/button_renderer.js +634 -0
  35. package/L2_Handling/display/inputs/form_renderer.js +583 -0
  36. package/L2_Handling/display/inputs/input_renderer.js +658 -0
  37. package/L2_Handling/display/inputs/inputs.js +12 -0
  38. package/L2_Handling/display/navigation/menu_renderer.js +206 -0
  39. package/L2_Handling/display/navigation/navigation.js +11 -0
  40. package/L2_Handling/display/navigation/navigation_renderer.js +703 -0
  41. package/L2_Handling/display/orchestration/orchestration.js +11 -0
  42. package/L2_Handling/display/orchestration/renderer.js +430 -0
  43. package/L2_Handling/display/orchestration/zdisplay_orchestrator.js +1759 -0
  44. package/L2_Handling/display/outputs/alert_renderer.js +161 -0
  45. package/L2_Handling/display/outputs/audio_renderer.js +94 -0
  46. package/L2_Handling/display/outputs/card_renderer.js +229 -0
  47. package/L2_Handling/display/outputs/code_renderer.js +66 -0
  48. package/L2_Handling/display/outputs/dl_renderer.js +131 -0
  49. package/L2_Handling/display/outputs/header_renderer.js +162 -0
  50. package/L2_Handling/display/outputs/icon_renderer.js +107 -0
  51. package/L2_Handling/display/outputs/image_renderer.js +145 -0
  52. package/L2_Handling/display/outputs/list_renderer.js +190 -0
  53. package/L2_Handling/display/outputs/outputs.js +19 -0
  54. package/L2_Handling/display/outputs/table_renderer.js +765 -0
  55. package/L2_Handling/display/outputs/text_renderer.js +818 -0
  56. package/L2_Handling/display/outputs/typography_renderer.js +293 -0
  57. package/L2_Handling/display/outputs/video_renderer.js +116 -0
  58. package/L2_Handling/display/primitives/document_structure_primitives.js +319 -0
  59. package/L2_Handling/display/primitives/form_primitives.js +526 -0
  60. package/L2_Handling/display/primitives/generic_containers.js +109 -0
  61. package/L2_Handling/display/primitives/interactive_primitives.js +305 -0
  62. package/L2_Handling/display/primitives/link_primitives.js +552 -0
  63. package/L2_Handling/display/primitives/lists_primitives.js +262 -0
  64. package/L2_Handling/display/primitives/media_primitives.js +383 -0
  65. package/L2_Handling/display/primitives/primitives.js +19 -0
  66. package/L2_Handling/display/primitives/semantic_element_primitive.js +226 -0
  67. package/L2_Handling/display/primitives/table_primitives.js +528 -0
  68. package/L2_Handling/display/primitives/typography_primitives.js +175 -0
  69. package/L2_Handling/display/specialized/input_request_renderer.js +467 -0
  70. package/L2_Handling/display/specialized/specialized.js +10 -0
  71. package/L2_Handling/hooks/hooks.js +9 -0
  72. package/L2_Handling/hooks/menu_integration.js +57 -0
  73. package/L2_Handling/hooks/widget_hook_manager.js +292 -0
  74. package/L2_Handling/message/message.js +8 -0
  75. package/L2_Handling/message/message_handler.js +701 -0
  76. package/L2_Handling/navigation/navigation.js +8 -0
  77. package/L2_Handling/navigation/navigation_manager.js +403 -0
  78. package/L2_Handling/zhooks/features/cache_live.js +287 -0
  79. package/L2_Handling/zhooks/features/crumbs_live.js +292 -0
  80. package/L2_Handling/zhooks/zhooks_manager.js +65 -0
  81. package/L2_Handling/zvaf/zvaf.js +8 -0
  82. package/L2_Handling/zvaf/zvaf_manager.js +334 -0
  83. package/L3_Abstraction/L3_Abstraction.js +12 -0
  84. package/L3_Abstraction/orchestrator/container_unwrapper.js +101 -0
  85. package/L3_Abstraction/orchestrator/group_renderer.js +698 -0
  86. package/L3_Abstraction/orchestrator/input_event_handler.js +797 -0
  87. package/L3_Abstraction/orchestrator/metadata_processor.js +249 -0
  88. package/L3_Abstraction/orchestrator/navbar_builder.js +201 -0
  89. package/L3_Abstraction/orchestrator/orchestrator.js +13 -0
  90. package/L3_Abstraction/orchestrator/wizard_gate_handler.js +360 -0
  91. package/L3_Abstraction/renderer/renderer.js +1 -0
  92. package/L3_Abstraction/session/session.js +1 -0
  93. package/L4_Orchestration/L4_Orchestration.js +11 -0
  94. package/L4_Orchestration/client/client.js +1 -0
  95. package/L4_Orchestration/facade/facade.js +9 -0
  96. package/L4_Orchestration/facade/manager_registry.js +118 -0
  97. package/L4_Orchestration/facade/renderer_registry.js +274 -0
  98. package/L4_Orchestration/lifecycle/asset_loader.js +255 -0
  99. package/L4_Orchestration/lifecycle/initializer.js +135 -0
  100. package/L4_Orchestration/lifecycle/lifecycle.js +8 -0
  101. package/L4_Orchestration/rendering/facade.js +94 -0
  102. package/L4_Orchestration/rendering/rendering.js +7 -0
  103. package/LICENSE +21 -0
  104. package/README.md +82 -0
  105. package/bifrost_client.js +204 -0
  106. package/bifrost_core.js +1686 -0
  107. package/docs/ARCHITECTURE.md +111 -0
  108. package/docs/PROTOCOL.md +106 -0
  109. package/docs/RENDERERS.md +101 -0
  110. package/docs/SECURITY.md +92 -0
  111. package/package.json +24 -0
  112. package/syntax/prism-zconfig.js +41 -0
  113. package/syntax/prism-zenv.js +69 -0
  114. package/syntax/prism-zolo-theme.css +288 -0
  115. package/syntax/prism-zolo.js +380 -0
  116. package/syntax/prism-zschema.js +38 -0
  117. package/syntax/prism-zspark.js +25 -0
  118. package/syntax/prism-zui.js +68 -0
  119. package/zSys/accessibility/accessibility.js +10 -0
  120. package/zSys/accessibility/emoji_accessibility.js +173 -0
  121. package/zSys/dom/block_utils.js +122 -0
  122. package/zSys/dom/container_utils.js +370 -0
  123. package/zSys/dom/dom.js +13 -0
  124. package/zSys/dom/dom_utils.js +328 -0
  125. package/zSys/dom/encoding_utils.js +117 -0
  126. package/zSys/dom/style_utils.js +71 -0
  127. package/zSys/errors/error_display.js +299 -0
  128. package/zSys/errors/errors.js +10 -0
  129. package/zSys/theme/color_utils.js +274 -0
  130. package/zSys/theme/dark_mode_utils.js +272 -0
  131. package/zSys/theme/size_utils.js +256 -0
  132. package/zSys/theme/spacing_utils.js +405 -0
  133. package/zSys/theme/theme.js +14 -0
  134. package/zSys/theme/zbase.css +1735 -0
  135. package/zSys/theme/zbase_inject.js +161 -0
  136. package/zSys/theme/ztheme_utils.js +305 -0
  137. package/zSys/validation/error_boundary.js +201 -0
  138. package/zSys/validation/validation.js +11 -0
  139. package/zSys/validation/validation_utils.js +238 -0
  140. package/zSys/zSys.js +14 -0
@@ -0,0 +1,289 @@
1
+ /**
2
+ *
3
+ * zCLI - SessionManager (Layer 1 Primitive)
4
+ *
5
+ *
6
+ * Manages public session data on the frontend, synced with backend zSession.
7
+ *
8
+ * Architecture:
9
+ * - Public data in localStorage (username, role, session_hash)
10
+ * - Private data in httpOnly cookies (session token) ← backend managed
11
+ * - session_hash for cache invalidation
12
+ *
13
+ * Security:
14
+ * - NO sensitive data in localStorage (XSS-safe)
15
+ * - Session token in httpOnly cookie (backend only)
16
+ * - Public data for UI decisions (navbar, RBAC display)
17
+ *
18
+ * Usage:
19
+ * const session = new SessionManager(storage);
20
+ * await session.init();
21
+ *
22
+ * // After login (backend sends session_hash)
23
+ * session.setPublicData({
24
+ * username: 'Gal Nachshon',
25
+ * role: 'zAdmin',
26
+ * session_hash: 'abc123'
27
+ * });
28
+ *
29
+ * // Check authentication
30
+ * if (session.isAuthenticated()) {
31
+ * console.log('User:', session.get('username'));
32
+ * }
33
+ *
34
+ * @version 1.6.0
35
+ * @since 2025-12-16
36
+ *
37
+ */
38
+
39
+ (function(root, factory) {
40
+ if (typeof define === 'function' && define.amd) {
41
+ define([], factory);
42
+ } else if (typeof module === 'object' && module.exports) {
43
+ module.exports = factory();
44
+ } else {
45
+ root.SessionManager = factory();
46
+ }
47
+ }(typeof self !== 'undefined' ? self : this, () => {
48
+ 'use strict';
49
+
50
+ //
51
+ // Constants
52
+ //
53
+
54
+ const SESSION_KEY = 'public_session';
55
+ const DEFAULT_SESSION = {
56
+ authenticated: false,
57
+ username: null,
58
+ role: null,
59
+ session_hash: null,
60
+ app: null,
61
+ timestamp: null
62
+ };
63
+
64
+ //
65
+ // SessionManager Class
66
+ //
67
+
68
+ class SessionManager {
69
+ /**
70
+ * Create a new session manager instance
71
+ *
72
+ * @param {StorageManager} storage - StorageManager instance for persistence
73
+ * @param {Object} logger - Optional logger instance
74
+ */
75
+ constructor(storage, logger = null) {
76
+ if (!storage) {
77
+ throw new Error('[SessionManager] StorageManager required');
78
+ }
79
+
80
+ this.storage = storage;
81
+ this.session = { ...DEFAULT_SESSION };
82
+ this.listeners = [];
83
+ this.logger = logger || console;
84
+
85
+ this.logger.debug('[SessionManager] Created');
86
+ }
87
+
88
+ /**
89
+ * Initialize session manager
90
+ *
91
+ * Loads existing session from storage (if any).
92
+ *
93
+ * @returns {Promise<void>}
94
+ */
95
+ async init() {
96
+ // Load from storage
97
+ const stored = await this.storage.get(SESSION_KEY, 'session');
98
+
99
+ if (stored && this._isValidSession(stored)) {
100
+ this.session = stored;
101
+ this.logger.debug('[SessionManager] Restored session:', this.session.username || 'anonymous');
102
+ } else {
103
+ this.session = { ...DEFAULT_SESSION };
104
+ this.logger.debug('[SessionManager] No valid session found, starting anonymous');
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Validate session data structure
110
+ *
111
+ * @private
112
+ * @param {object} session - Session object to validate
113
+ * @returns {boolean} True if valid
114
+ */
115
+ _isValidSession(session) {
116
+ return session &&
117
+ typeof session === 'object' &&
118
+ typeof session.authenticated === 'boolean' &&
119
+ typeof session.session_hash === 'string';
120
+ }
121
+
122
+ /**
123
+ * Set public session data (after login)
124
+ *
125
+ * Called by BifrostClient after successful login/auth.
126
+ *
127
+ * @param {object} data - Public session data from backend
128
+ * @param {string} data.username - User's display name
129
+ * @param {string} data.role - User's role (e.g., 'zAdmin')
130
+ * @param {string} data.session_hash - Cache invalidation token
131
+ * @param {string} data.app - Application name
132
+ */
133
+ async setPublicData(data) {
134
+ const previousHash = this.session.session_hash;
135
+
136
+ this.session = {
137
+ authenticated: true,
138
+ username: data.username || null,
139
+ role: data.role || null,
140
+ session_hash: data.session_hash || null,
141
+ app: data.app || null,
142
+ timestamp: Date.now()
143
+ };
144
+
145
+ // Persist to storage
146
+ await this.storage.set(SESSION_KEY, this.session, 'session');
147
+
148
+ this.logger.debug('[SessionManager] Session updated:', this.session.username);
149
+
150
+ // Notify listeners (e.g., cache invalidation if hash changed)
151
+ if (previousHash !== this.session.session_hash) {
152
+ this._notifyListeners('session_changed', this.session);
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Clear session (logout)
158
+ *
159
+ * Removes public session data. Backend handles cookie removal.
160
+ */
161
+ async clear() {
162
+ const previousUsername = this.session.username;
163
+
164
+ this.session = { ...DEFAULT_SESSION };
165
+ await this.storage.remove(SESSION_KEY, 'session');
166
+
167
+ this.logger.debug('[SessionManager] Session cleared:', previousUsername);
168
+
169
+ // Notify listeners (e.g., clear caches)
170
+ this._notifyListeners('session_cleared');
171
+ }
172
+
173
+ /**
174
+ * Check if user is authenticated
175
+ *
176
+ * @returns {boolean} True if authenticated
177
+ */
178
+ isAuthenticated() {
179
+ return this.session.authenticated === true;
180
+ }
181
+
182
+ /**
183
+ * Check if user is a guest (not authenticated)
184
+ *
185
+ * @returns {boolean} True if guest
186
+ */
187
+ isGuest() {
188
+ return !this.isAuthenticated();
189
+ }
190
+
191
+ /**
192
+ * Get session property
193
+ *
194
+ * @param {string} key - Property key (e.g., 'username', 'role', 'session_hash')
195
+ * @returns {any} Property value or null
196
+ */
197
+ get(key) {
198
+ return this.session[key] || null;
199
+ }
200
+
201
+ /**
202
+ * Get entire session object (read-only)
203
+ *
204
+ * @returns {object} Session data (shallow copy)
205
+ */
206
+ getAll() {
207
+ return { ...this.session };
208
+ }
209
+
210
+ /**
211
+ * Get session hash (for cache validation)
212
+ *
213
+ * @returns {string|null} Session hash or null
214
+ */
215
+ getHash() {
216
+ return this.session.session_hash;
217
+ }
218
+
219
+ /**
220
+ * Check if user has a specific role
221
+ *
222
+ * @param {string} role - Role name (e.g., 'zAdmin')
223
+ * @returns {boolean} True if user has role
224
+ */
225
+ hasRole(role) {
226
+ return this.session.role === role;
227
+ }
228
+
229
+ /**
230
+ * Add listener for session changes
231
+ *
232
+ * @param {Function} callback - Callback function (event, data)
233
+ */
234
+ addListener(callback) {
235
+ if (typeof callback === 'function') {
236
+ this.listeners.push(callback);
237
+ }
238
+ }
239
+
240
+ /**
241
+ * Remove listener
242
+ *
243
+ * @param {Function} callback - Callback function to remove
244
+ */
245
+ removeListener(callback) {
246
+ const index = this.listeners.indexOf(callback);
247
+ if (index > -1) {
248
+ this.listeners.splice(index, 1);
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Notify all listeners of an event
254
+ *
255
+ * @private
256
+ * @param {string} event - Event name ('session_changed', 'session_cleared')
257
+ * @param {any} data - Event data
258
+ */
259
+ _notifyListeners(event, data = null) {
260
+ this.listeners.forEach(callback => {
261
+ try {
262
+ callback(event, data);
263
+ } catch (error) {
264
+ this.logger.debug('[SessionManager] Listener error:', error);
265
+ }
266
+ });
267
+ }
268
+
269
+ /**
270
+ * Debug: Print session state
271
+ */
272
+ debug() {
273
+ this.logger.debug('[SessionManager] Current session:', {
274
+ authenticated: this.session.authenticated,
275
+ username: this.session.username,
276
+ role: this.session.role,
277
+ hash: this.session.session_hash,
278
+ app: this.session.app
279
+ });
280
+ }
281
+ }
282
+
283
+ //
284
+ // Export
285
+ //
286
+
287
+ return SessionManager;
288
+ }));
289
+
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Storage Module - Barrel Export
3
+ *
4
+ * Storage primitives for caching system
5
+ *
6
+ * @module caching/storage
7
+ */
8
+
9
+ export { StorageManager } from './storage_manager.js';
10
+ export { SessionManager } from './session_manager.js';