ultimate-jekyll-manager 0.0.116 → 0.0.118

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.
@@ -17,169 +17,159 @@ importScripts(
17
17
  // 'https://www.gstatic.com/firebasejs/%%% firebaseVersion %%%/firebase-firestore-compat.js',
18
18
  );
19
19
 
20
- // Class
21
- function Manager() {
22
- const self = this;
23
-
24
- // Properties
25
- self.serviceWorker = null;
26
-
27
- // Load config
28
- self.config = serviceWorker.UJ_BUILD_JSON?.config || {};
29
-
30
- // Defaults
31
- self.app = self.config?.brand?.id || 'default';
32
- self.environment = self.config?.uj?.environment || 'production';
33
- self.cache = {
34
- breaker: self.config?.uj?.cache_breaker || new Date().getTime(),
35
- };
36
- self.cache.name = `${self.app}-${self.cache.breaker}`;
37
-
38
- // Libraries
39
- self.libraries = {
40
- firebase: false,
41
- messaging: false,
42
- promoServer: false,
43
- };
44
-
45
- // Return
46
- return self;
47
- }
48
-
49
- // Initialize
50
- Manager.prototype.initialize = function () {
51
- const self = this;
20
+ // Manager Class
21
+ class Manager {
22
+ constructor() {
23
+ // Properties
24
+ this.serviceWorker = null;
25
+
26
+ // Load config
27
+ this.config = serviceWorker.UJ_BUILD_JSON?.config || {};
28
+
29
+ // Defaults
30
+ this.app = this.config?.brand?.id || 'default';
31
+ this.environment = this.config?.uj?.environment || 'production';
32
+ this.cache = {
33
+ breaker: this.config?.uj?.cache_breaker || new Date().getTime(),
34
+ };
35
+ this.cache.name = `${this.app}-${this.cache.breaker}`;
36
+
37
+ // Libraries
38
+ this.libraries = {
39
+ firebase: false,
40
+ messaging: false,
41
+ promoServer: false,
42
+ };
43
+ }
52
44
 
53
- return new Promise(function(resolve, reject) {
45
+ // Initialize
46
+ async initialize() {
54
47
  // Properties
55
- self.serviceWorker = serviceWorker;
48
+ this.serviceWorker = serviceWorker;
56
49
 
57
50
  // Setup instance-specific message handlers
58
- self.setupInstanceHandlers();
51
+ this.setupInstanceHandlers();
59
52
 
60
53
  // Initialize Firebase
61
- self.initializeFirebase();
54
+ this.initializeFirebase();
62
55
 
63
56
  // Update cache
64
- self.updateCache();
57
+ this.updateCache();
65
58
 
66
59
  // Log
67
60
  console.log('Initialized!', serviceWorker.location.pathname, serviceWorker);
61
+ console.log('Config loaded from UJ_BUILD_JSON:', this.config);
68
62
 
69
63
  // Return
70
- return resolve(serviceWorker);
71
- });
72
- };
73
-
74
- // ['log', 'error', 'warn', 'info', 'debug'].forEach(method => {
75
- // Manager.prototype[method] = function() {
76
- // // Get arguments
77
- // const time = new Date().toLocaleTimeString('en-US', {
78
- // hour12: false,
79
- // hour: '2-digit',
80
- // minute: '2-digit',
81
- // second: '2-digit'
82
- // });
83
-
84
- // // Add prefix
85
- // const args = [`[${time}] service-worker:`, ...Array.from(arguments)];
86
-
87
- // // Call the original console method
88
- // console[method].apply(console, args);
89
- // };
90
- // });
91
-
92
- // Setup instance-specific message handlers
93
- Manager.prototype.setupInstanceHandlers = function () {
94
- const self = this;
95
-
96
- // Send messages: https://stackoverflow.com/questions/35725594/how-do-i-pass-data-like-a-user-id-to-a-web-worker-for-fetching-additional-push
97
- // more messaging: http://craig-russell.co.uk/2016/01/29/service-worker-messaging.html#.XSKpRZNKiL8
98
- serviceWorker.addEventListener('message', (event) => {
99
- // Get the data
100
- const data = event.data || {};
101
-
102
- // Parse the data
103
- const command = data.command || '';
104
- const payload = data.payload || {};
105
-
106
- // Quit if no command
107
- if (!command) return;
108
-
109
- // Log
110
- console.log('message', command, payload, event);
111
-
112
- // Handle commands
113
- if (command === 'update-cache') {
114
- const pages = payload.pages || [];
115
- self.updateCache(pages)
116
- .then(() => {
117
- event.ports[0]?.postMessage({ status: 'success' });
118
- })
119
- .catch(error => {
120
- event.ports[0]?.postMessage({ status: 'error', error: error.message });
121
- });
122
- }
123
- });
124
-
125
- // Log
126
- console.log('Set up message handlers');
127
- }
128
-
129
- // Setup Firebase init
130
- Manager.prototype.initializeFirebase = function () {
131
- const self = this;
132
-
133
- // Get Firebase config
134
- const firebaseConfig = self.config?.web_manager?.firebase?.app?.config;
135
-
136
- // Check if Firebase config is available
137
- if (!firebaseConfig) {
138
- console.log('Firebase config not available yet, skipping Firebase initialization');
139
- return;
64
+ return serviceWorker;
140
65
  }
141
66
 
142
- // Check if already initialized
143
- if (self.libraries.firebase) {
144
- console.log('Firebase already initialized');
145
- return;
146
- }
67
+ // ['log', 'error', 'warn', 'info', 'debug'].forEach(method => {
68
+ // Manager.prototype[method] = function() {
69
+ // // Get arguments
70
+ // const time = new Date().toLocaleTimeString('en-US', {
71
+ // hour12: false,
72
+ // hour: '2-digit',
73
+ // minute: '2-digit',
74
+ // second: '2-digit'
75
+ // });
76
+
77
+ // // Add prefix
78
+ // const args = [`[${time}] service-worker:`, ...Array.from(arguments)];
79
+
80
+ // // Call the original console method
81
+ // console[method].apply(console, args);
82
+ // };
83
+ // });
84
+
85
+ // Setup instance-specific message handlers
86
+ setupInstanceHandlers() {
87
+ // Send messages: https://stackoverflow.com/questions/35725594/how-do-i-pass-data-like-a-user-id-to-a-web-worker-for-fetching-additional-push
88
+ // more messaging: http://craig-russell.co.uk/2016/01/29/service-worker-messaging.html#.XSKpRZNKiL8
89
+ serviceWorker.addEventListener('message', (event) => {
90
+ // Get the data
91
+ const data = event.data || {};
92
+
93
+ // Parse the data
94
+ const command = data.command || '';
95
+ const payload = data.payload || {};
96
+
97
+ // Quit if no command
98
+ if (!command) {
99
+ return;
100
+ }
101
+
102
+ // Log
103
+ console.log('message', command, payload, event);
104
+
105
+ // Handle commands
106
+ if (command === 'update-cache') {
107
+ const pages = payload.pages || [];
108
+ this.updateCache(pages)
109
+ .then(() => {
110
+ event.ports[0]?.postMessage({ status: 'success' });
111
+ })
112
+ .catch(error => {
113
+ event.ports[0]?.postMessage({ status: 'error', error: error.message });
114
+ });
115
+ }
116
+ });
147
117
 
148
- // Log
149
- console.log('Initializing Firebase v%%% firebaseVersion %%%');
118
+ // Log
119
+ console.log('Set up message handlers');
120
+ }
150
121
 
151
- // Initialize app (libraries were already imported at the top)
152
- firebase.initializeApp(firebaseConfig);
122
+ // Setup Firebase init
123
+ initializeFirebase() {
124
+ // Get Firebase config
125
+ const firebaseConfig = this.config?.web_manager?.firebase?.app?.config;
153
126
 
154
- // Initialize messaging
155
- self.libraries.messaging = firebase.messaging();
127
+ // Check if Firebase config is available
128
+ if (!firebaseConfig) {
129
+ console.log('Firebase config not available yet, skipping Firebase initialization');
130
+ return;
131
+ }
156
132
 
157
- // Attach firebase to SWManager
158
- self.libraries.firebase = firebase;
159
- }
133
+ // Check if already initialized
134
+ if (this.libraries.firebase) {
135
+ console.log('Firebase already initialized');
136
+ return;
137
+ }
160
138
 
161
- // Setup cache update
162
- Manager.prototype.updateCache = function (pages) {
163
- const self = this;
139
+ // Log
140
+ console.log('Initializing Firebase v%%% firebaseVersion %%%');
164
141
 
165
- // Set default pages to cache
166
- const defaults = [
167
- '/',
168
- '/assets/css/main.bundle.css',
169
- '/assets/js/main.bundle.js',
170
- ];
142
+ // Initialize app (libraries were already imported at the top)
143
+ firebase.initializeApp(firebaseConfig);
171
144
 
172
- // Ensure pages is an array
173
- pages = pages || [];
145
+ // Initialize messaging
146
+ this.libraries.messaging = firebase.messaging();
174
147
 
175
- // Merge with additional pages
176
- const pagesToCache = [...new Set([...defaults, ...pages])];
148
+ // Attach firebase to SWManager
149
+ this.libraries.firebase = firebase;
150
+ }
177
151
 
178
- // Open cache and add pages
179
- return caches.open(self.cache.name)
180
- .then(cache => cache.addAll(pagesToCache))
181
- .then(() => console.log('Cached resources:', pagesToCache))
182
- .catch(error => console.error('Failed to cache resources:', error));
152
+ // Setup cache update
153
+ updateCache(pages) {
154
+ // Set default pages to cache
155
+ const defaults = [
156
+ '/',
157
+ '/assets/css/main.bundle.css',
158
+ '/assets/js/main.bundle.js',
159
+ ];
160
+
161
+ // Ensure pages is an array
162
+ pages = pages || [];
163
+
164
+ // Merge with additional pages
165
+ const pagesToCache = [...new Set([...defaults, ...pages])];
166
+
167
+ // Open cache and add pages
168
+ return caches.open(this.cache.name)
169
+ .then(cache => cache.addAll(pagesToCache))
170
+ .then(() => console.log('Cached resources:', pagesToCache))
171
+ .catch(error => console.error('Failed to cache resources:', error));
172
+ }
183
173
  }
184
174
 
185
175
  // Helper: Setup global listeners