web-manager 4.0.34 → 4.0.36

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/CLAUDE.md CHANGED
@@ -1,42 +1,270 @@
1
- This is a helper library that I built 6 years ago in 2019 when the web landscape was very different.
2
-
3
- I built many functionalities that I found myself writing for every project so that I could reuse them easily.
4
- It has been a great help in my projects, but many of these things are now not needed due to webpack, and other amazing tools.
5
-
6
- The first thing I did is move all the old code to the "legacy" folder so that we can keep it as a reference. You should reference this as your REBUILD THE NEW LIBRARY IN "src" folder. DO NOT DELETE OR CHANGE LEGACY CODE, just reference it and recreate the functioinality I want in the "src" folder.
7
-
8
- Going forward, you can use any new JS you want like backticks and => since we are going to transpile everything to ES5.
9
-
10
- MAKE THIS NEW VERSION OF THE LIBRARY OPTIMIZED FOR WEBPACK (but know that it WONT ALWAYS BE USED WITH WEBPACK)
11
-
12
- We are going to completely rewrite and refactor this library. Let's start with how and where it will be used.
13
- 1. Web: It will be webpacked with a project that transpiles everything to ES5
14
- 2. Electron: It will be used in an Electron app.
15
- 3. Chrome Extension: It will be used in a Chrome extension.
16
-
17
- Now lets go over what I want to keep.
18
- 1. Firebase
19
- - Let's updte to use the latest version of Firebase (12)
20
- - I want a sort of "mini firebase auth wrapper" that has some basic functions
21
- - auth.ready(options).then(result => {})
22
- - This should return a promise that resolves when the auth is ready OR not (so i can call it when the page loads and result will either be the signed in user or nothing if they are not signed in)
23
- - result (AN OBJECT) = {
24
- user: the signed in firebase user OR null
25
- account: the signed in user's acconunt data IF requested in options.account = true
26
- }
27
- - We will for sure need to have Firebase auth, firestore, messaging.
28
- 2. Manager.prototype.notifications
29
- - Easily check if subscribed and subscribe to push notifications. Keeps track in local storage.
30
- - automatically requests permission after a click and a timeout
31
- 3. Manager.prototype.storage
32
- - A simple wrapper around localStorage and sessionStorage that allows for easy setting, getting, and removing of items.
33
- 4. navigator.serviceWorker.register
34
- - A simple wrapper around the service worker registration that allows for easy registration and unregistration.
35
-
36
- Some things we can definitely remove:
37
- 1. Most of the legacy/lib/dom.js library since webpack can help me avoid this shit. BUT i do want a light helper that does some things
38
- - loadScript so we can load and dynamically import external scripts
39
- 2. I think we can remove init_loadPolyfills since we are transpiling, correct?
40
- 3. Most of legacy/lib/utilities.js
41
- - Keep clipboardCopy, escapeHTML, getContext
1
+ # Web Manager - AI Agent Guide
42
2
 
3
+ This document helps AI agents understand the web-manager codebase for effective contributions.
4
+
5
+ ## Project Overview
6
+
7
+ **Purpose**: Modern JavaScript utility library for web applications with Firebase integration. Provides authentication, data binding, storage, push notifications, error tracking, and more.
8
+
9
+ **Target Environments**:
10
+ - Web (primary, webpack-optimized)
11
+ - Electron (renderer process)
12
+ - Chrome/Firefox Extensions (content scripts, popups)
13
+
14
+ **Version**: 4.0.x | **Node**: >=12 | **License**: CC-BY-4.0
15
+
16
+ ## Architecture
17
+
18
+ ### Singleton Pattern
19
+ The library exports a singleton `Manager` instance:
20
+ ```javascript
21
+ const manager = new Manager();
22
+ export default manager;
23
+ export { Manager };
24
+ ```
25
+
26
+ ### Directory Structure
27
+ ```
28
+ web-manager/
29
+ ├── src/ # Source code (ES6+)
30
+ │ ├── index.js # Manager class, initialization, Firebase setup
31
+ │ └── modules/ # Feature modules
32
+ │ ├── auth.js # Firebase Auth wrapper
33
+ │ ├── bindings.js # Reactive DOM data binding
34
+ │ ├── dom.js # loadScript, ready utilities
35
+ │ ├── firestore.js # Firestore wrapper with chainable queries
36
+ │ ├── notifications.js # FCM push notifications
37
+ │ ├── sentry.js # Error tracking integration
38
+ │ ├── service-worker.js # SW registration and messaging
39
+ │ ├── storage.js # localStorage/sessionStorage wrapper
40
+ │ └── utilities.js # Helper functions (clipboard, escape, etc.)
41
+ ├── dist/ # Transpiled ES5 output (generated)
42
+ ├── _legacy/ # Old implementation (reference only, DO NOT MODIFY)
43
+ └── test/ # Mocha tests
44
+ ```
45
+
46
+ ### Module Dependencies
47
+ ```
48
+ Manager (index.js)
49
+ ├── Storage (standalone, no deps)
50
+ ├── Auth → Manager, Bindings, Storage, Firestore
51
+ ├── Bindings → Manager
52
+ ├── Firestore → Manager (lazy Firebase import)
53
+ ├── Notifications → Manager, Storage, Firestore
54
+ ├── ServiceWorker → Manager
55
+ ├── Sentry → Manager (dynamic import)
56
+ ├── DOM utilities (standalone)
57
+ └── Utilities (standalone)
58
+ ```
59
+
60
+ ## Key Patterns
61
+
62
+ ### 1. Early Return (Short-Circuit)
63
+ Always use early returns instead of nested conditionals:
64
+ ```javascript
65
+ // CORRECT
66
+ function doSomething() {
67
+ if (!condition) {
68
+ return;
69
+ }
70
+ // Long code block...
71
+ }
72
+
73
+ // WRONG
74
+ function doSomething() {
75
+ if (condition) {
76
+ // Long code block...
77
+ }
78
+ }
79
+ ```
80
+
81
+ ### 2. DOM Element Naming
82
+ Prefix DOM element variables with `$`:
83
+ ```javascript
84
+ const $button = document.querySelector('.submit-btn');
85
+ const $input = document.getElementById('email');
86
+ ```
87
+
88
+ ### 3. Logical Operator Formatting
89
+ Place operators at the START of continuation lines:
90
+ ```javascript
91
+ // CORRECT
92
+ const result = conditionA
93
+ || conditionB
94
+ || conditionC;
95
+
96
+ // WRONG
97
+ const result = conditionA ||
98
+ conditionB ||
99
+ conditionC;
100
+ ```
101
+
102
+ ### 4. Firestore Path Syntax
103
+ Prefer path syntax over collection/doc chaining:
104
+ ```javascript
105
+ // PREFERRED
106
+ db.doc('users/userId')
107
+
108
+ // ALSO SUPPORTED
109
+ db.doc('users', 'userId')
110
+ ```
111
+
112
+ ### 5. Dynamic Imports
113
+ Firebase modules are dynamically imported to reduce bundle size:
114
+ ```javascript
115
+ const { initializeApp } = await import('firebase/app');
116
+ const { getAuth } = await import('firebase/auth');
117
+ ```
118
+
119
+ ### 6. Configuration Deep Merge
120
+ User config is deep-merged with defaults in `_processConfiguration()`. Only override what you need:
121
+ ```javascript
122
+ // Defaults defined in _processConfiguration()
123
+ const defaults = {
124
+ environment: 'production',
125
+ firebase: { app: { enabled: true, config: {} } },
126
+ // ...
127
+ };
128
+ ```
129
+
130
+ ### 7. Event Delegation
131
+ Auth UI uses event delegation on document body:
132
+ ```javascript
133
+ document.body.addEventListener('click', (e) => {
134
+ if (e.target.closest('.auth-signout-btn')) {
135
+ // Handle signout
136
+ }
137
+ });
138
+ ```
139
+
140
+ ## Module Quick Reference
141
+
142
+ ### Storage (`storage.js`)
143
+ - **Class**: `Storage`
144
+ - **Key Methods**: `get(path, default)`, `set(path, value)`, `remove(path)`, `clear()`
145
+ - **Session**: Same methods under `.session` namespace
146
+ - **Storage Key**: `_manager` in localStorage
147
+
148
+ ### Auth (`auth.js`)
149
+ - **Class**: `Auth`
150
+ - **Key Methods**: `listen(options, callback)`, `isAuthenticated()`, `getUser()`, `signInWithEmailAndPassword()`, `signOut()`, `getIdToken()`
151
+ - **Bindings**: Updates `auth.user` and `auth.account` context
152
+
153
+ ### Bindings (`bindings.js`)
154
+ - **Class**: `Bindings`
155
+ - **Key Methods**: `update(data)`, `getContext()`, `clear()`
156
+ - **HTML Attr**: `data-wm-bind`
157
+ - **Actions**: `@text`, `@value`, `@show`, `@hide`, `@attr`, `@style`
158
+
159
+ ### Firestore (`firestore.js`)
160
+ - **Class**: `Firestore`
161
+ - **Key Methods**: `doc(path)`, `collection(path)`
162
+ - **Doc Methods**: `.get()`, `.set()`, `.update()`, `.delete()`
163
+ - **Query Methods**: `.where()`, `.orderBy()`, `.limit()`, `.startAt()`, `.endAt()`
164
+
165
+ ### Notifications (`notifications.js`)
166
+ - **Class**: `Notifications`
167
+ - **Key Methods**: `isSupported()`, `isSubscribed()`, `subscribe()`, `unsubscribe()`, `getToken()`, `onMessage()`
168
+ - **Storage**: Saves to localStorage and Firestore
169
+
170
+ ### ServiceWorker (`service-worker.js`)
171
+ - **Class**: `ServiceWorker`
172
+ - **Key Methods**: `isSupported()`, `register()`, `ready()`, `postMessage()`, `onMessage()`, `getState()`
173
+
174
+ ### Sentry (`sentry.js`)
175
+ - **Class**: `Sentry` (named `mod` internally)
176
+ - **Key Methods**: `init(config)`, `captureException(error, context)`
177
+ - **Filtering**: Blocks dev mode, Lighthouse, Selenium/Puppeteer
178
+
179
+ ### DOM (`dom.js`)
180
+ - **Exports**: `loadScript(options)`, `ready()`
181
+ - **loadScript Options**: src, async, defer, crossorigin, integrity, timeout, retries
182
+
183
+ ### Utilities (`utilities.js`)
184
+ - **Exports**: `clipboardCopy()`, `escapeHTML()`, `showNotification()`, `getPlatform()`, `getRuntime()`, `isMobile()`, `getDeviceType()`, `getContext()`
185
+
186
+ ## Build System
187
+
188
+ ### prepare-package
189
+ The library uses `prepare-package` for ES5 transpilation:
190
+
191
+ ```json
192
+ {
193
+ "preparePackage": {
194
+ "input": "./src",
195
+ "output": "./dist"
196
+ }
197
+ }
198
+ ```
199
+
200
+ **Commands**:
201
+ - `npm run prepare` - Build once
202
+ - `npm start` - Watch mode
203
+ - `npm test` - Run Mocha tests
204
+
205
+ ### Package Exports
206
+ ```json
207
+ {
208
+ "main": "dist/index.js",
209
+ "module": "src/index.js",
210
+ "exports": {
211
+ ".": "./dist/index.js",
212
+ "./modules/*": "./dist/modules/*"
213
+ }
214
+ }
215
+ ```
216
+
217
+ ## Testing
218
+
219
+ Tests are in `test/test.js` using Mocha:
220
+ ```bash
221
+ npm test
222
+ ```
223
+
224
+ Current test coverage is minimal - focuses on configuration and storage.
225
+
226
+ ## Common Tasks
227
+
228
+ ### Adding a New Utility Function
229
+ 1. Add function to `src/modules/utilities.js`
230
+ 2. Export it: `export function myFunction() { ... }`
231
+ 3. Update README.md with documentation
232
+ 4. Run `npm run prepare` to build
233
+
234
+ ### Adding a New Module
235
+ 1. Create `src/modules/my-module.js`
236
+ 2. Export class: `export default class MyModule { constructor(manager) { ... } }`
237
+ 3. Import in `src/index.js`: `import MyModule from './modules/my-module.js'`
238
+ 4. Add to Manager constructor: `this._myModule = new MyModule(this)`
239
+ 5. Add getter: `myModule() { return this._myModule; }`
240
+ 6. Update README.md
241
+ 7. Run `npm run prepare`
242
+
243
+ ### Modifying Configuration Defaults
244
+ 1. Edit `_processConfiguration()` in `src/index.js`
245
+ 2. Add to `defaults` object
246
+ 3. Document in README.md Configuration section
247
+
248
+ ### Adding a Data Binding Action
249
+ 1. Edit `_executeAction()` in `src/modules/bindings.js`
250
+ 2. Add case for new action (e.g., `@class`)
251
+ 3. Document in README.md Data Binding section
252
+
253
+ ## Dependencies
254
+
255
+ | Package | Purpose |
256
+ |---------|---------|
257
+ | `firebase` (^12.x) | Auth, Firestore, Messaging |
258
+ | `@sentry/browser` (^10.x) | Error tracking |
259
+ | `lodash` (^4.x) | get/set for path-based access |
260
+ | `resolve-account` (^2.x) | Account data resolution |
261
+ | `itwcw-package-analytics` | Analytics (internal) |
262
+
263
+ ## Important Notes
264
+
265
+ 1. **DO NOT MODIFY `_legacy/`** - Reference only for historical context
266
+ 2. **Backwards compatibility is NOT required** - Just change to the new way
267
+ 3. **Prefer `fs-jetpack`** over `fs` for any file operations in tests/scripts
268
+ 4. **No TypeScript** - This is a pure JavaScript library
269
+ 5. **Template strings** - Use backticks for string interpolation
270
+ 6. **Modular design** - Keep modules focused and small