zet-lib 2.0.0 → 2.0.2

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 (3) hide show
  1. package/lib/index.js +39 -12
  2. package/lib/moduleLib.js +165 -72
  3. package/package.json +17 -11
package/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
- module.exports = {
3
+ // Core modules - loaded immediately (lightweight)
4
+ const coreModules = {
4
5
  access: require("./access"),
5
6
  Util: require("./Util"),
6
7
  myCache: require("./cache"),
@@ -27,15 +28,41 @@ module.exports = {
27
28
  zPage: require("./zPage"),
28
29
  zTester: require("./zTester"),
29
30
  zCache: require("./zCache"),
30
- zDropbox: require("./zDropbox"),
31
- puppeteer: require("puppeteer"),
32
- moment: require("moment"),
33
- ejs: require("ejs"),
34
- axios: require("axios"),
35
- Excel: require("exceljs"),
36
- pm2: require("pm2"),
37
- nodemailer: require("nodemailer"),
38
- readXlsxFile: require("read-excel-file/node"),
39
- JSZip: require("jszip"),
40
- pg:require('pg')
31
+ zDropbox: require("./zDropbox")
41
32
  };
33
+
34
+ // Heavy dependencies - lazy loaded (only when accessed)
35
+ const lazyModules = {
36
+ get puppeteer() {
37
+ return require("puppeteer");
38
+ },
39
+ get moment() {
40
+ return require("moment");
41
+ },
42
+ get ejs() {
43
+ return require("ejs");
44
+ },
45
+ get axios() {
46
+ return require("axios");
47
+ },
48
+ get Excel() {
49
+ return require("exceljs");
50
+ },
51
+ get pm2() {
52
+ return require("pm2");
53
+ },
54
+ get nodemailer() {
55
+ return require("nodemailer");
56
+ },
57
+ get readXlsxFile() {
58
+ return require("read-excel-file/node");
59
+ },
60
+ get JSZip() {
61
+ return require("jszip");
62
+ },
63
+ get pg() {
64
+ return require("pg");
65
+ }
66
+ };
67
+
68
+ module.exports = Object.assign({}, coreModules, lazyModules);
package/lib/moduleLib.js CHANGED
@@ -147,92 +147,185 @@ m.location = function (req, res, key) {
147
147
  let script = ``;
148
148
  let head = ``;
149
149
  let end = ``;
150
- end += `<script src="https://maps.googleapis.com/maps/api/js?key=${process.env.GOOGLE_KEY}&callback=initAutocompleteZmap&libraries=places&language=ID" defer></script>`;
151
- script += `let searchAddressMap;
152
- let autocompleteMap;
153
- function initAutocompleteZmap() {
154
- if(mapLocationJSON && mapLocationJSON.lat) {
155
- $("#search_map_location").val(mapLocationJSON.address1);
156
- initMap(mapLocationJSON.lat,mapLocationJSON.lon);
157
- } else {
158
- navigator.geolocation.getCurrentPosition(function(location) {
159
- initMap(location.coords.latitude,location.coords.longitude);
160
- $("#search_map_location").val("My Place");
161
- });
150
+ end =+ `<script src="https://maps.googleapis.com/maps/api/js?key=${process.env.GOOGLE_KEY}&callback=initAutocompleteZmap&libraries=places,marker&language=ID&loading=async" defer></script>`
151
+ script += `let searchAddressMap, autocompleteMap, marker, map;
152
+
153
+ function initAutocompleteZmap() {
154
+ if (mapLocationJSON && mapLocationJSON.lat) {
155
+ $("#search_map_location").val(mapLocationJSON.address1);
156
+ initMap(mapLocationJSON.lat, mapLocationJSON.lon);
157
+ } else {
158
+ navigator.geolocation.getCurrentPosition(function(position) {
159
+ initMap(position.coords.latitude, position.coords.longitude);
160
+ $("#search_map_location").val("");
161
+ });
162
+ }
163
+
164
+ searchAddressMap = document.querySelector("#search_map_location");
165
+
166
+ // Use PlaceAutocompleteElement (new API) instead of deprecated Autocomplete
167
+ // Check if PlaceAutocompleteElement is available
168
+ if (google.maps.places && google.maps.places.PlaceAutocompleteElement) {
169
+ try {
170
+ // Create PlaceAutocompleteElement programmatically
171
+ autocompleteMap = new google.maps.places.PlaceAutocompleteElement({
172
+ inputField: searchAddressMap,
173
+ componentRestrictions: {country: ["ID"]},
174
+ requestedResultFields: ["formattedAddress", "geometry", "addressComponents"]
175
+ });
176
+
177
+ // Listen for place selection event
178
+ autocompleteMap.addEventListener("gmp-placeselect", function(event) {
179
+ if (event.place) {
180
+ fillInAddressNew(event.place);
181
+ }
182
+ });
183
+
184
+ searchAddressMap.focus();
185
+ } catch (e) {
186
+ console.warn("Error initializing PlaceAutocompleteElement, falling back to Autocomplete:", e);
187
+ // Fallback to old Autocomplete API
188
+ autocompleteMap = new google.maps.places.Autocomplete(searchAddressMap, {
189
+ componentRestrictions: {country: ["ID"]},
190
+ fields: ["address_component", "geometry"]
191
+ });
192
+ searchAddressMap.focus();
193
+ autocompleteMap.addListener("place_changed", fillInAddress);
162
194
  }
163
- searchAddressMap = document.querySelector("#search_map_location");
195
+ } else {
196
+ // Fallback to old Autocomplete API if PlaceAutocompleteElement is not available
197
+ console.warn("PlaceAutocompleteElement not available, using legacy Autocomplete");
164
198
  autocompleteMap = new google.maps.places.Autocomplete(searchAddressMap, {
165
199
  componentRestrictions: {country: ["ID"]},
166
- fields: ["address_component", "geometry"],
200
+ fields: ["address_component", "geometry"]
167
201
  });
168
202
  searchAddressMap.focus();
169
203
  autocompleteMap.addListener("place_changed", fillInAddress);
170
204
  }
205
+ }
206
+
207
+ function fillInAddress() {
208
+ var place = autocompleteMap.getPlace();
209
+ var lat = place.geometry.location.lat();
210
+ var lng = place.geometry.location.lng();
211
+ initMap(lat, lng);
212
+ mapLocationJSON = {
213
+ lat: lat,
214
+ lon: lng,
215
+ address1: $("#search_map_location").val(),
216
+ address2: place.address_components
217
+ };
218
+ setAddress();
219
+ }
220
+
221
+ function fillInAddressNew(place) {
222
+ // Handle PlaceAutocompleteElement place selection
223
+ var location = place.geometry.location;
224
+ var lat = typeof location.lat === 'function' ? location.lat() : location.lat;
225
+ var lng = typeof location.lng === 'function' ? location.lng() : location.lng;
171
226
 
172
- function fillInAddress() {
173
- const place = autocompleteMap.getPlace();
174
- let lat = place.geometry.location.lat();
175
- let lon = place.geometry.location.lng();
176
- initMap(lat, lon);
177
- mapLocationJSON = {
178
- lat:lat,
179
- lon:lon,
180
- address1: $("#search_map_location").val(),
181
- address2:place.address_components,
182
- }
183
- setAddress();
184
- }
185
- function setAddress() {
186
- $("#${key}").val(JSON.stringify(mapLocationJSON));
187
- }
188
- function initMap(lat, lon) {
189
- let position = {lat: lat, lng: lon}
190
- const map = new google.maps.Map(document.getElementById("map_${key}"), {
191
- zoom: 13,
192
- center: position,
193
- draggable: true
227
+ initMap(lat, lng);
228
+ mapLocationJSON = {
229
+ lat: lat,
230
+ lon: lng,
231
+ address1: place.formattedAddress || $("#search_map_location").val(),
232
+ address2: place.addressComponents || []
233
+ };
234
+ setAddress();
235
+ }
236
+
237
+ function setAddress() {
238
+ $("#${key}").val(JSON.stringify(mapLocationJSON));
239
+ }
240
+
241
+ function initMap(lat, lng) {
242
+ var position = {lat: lat, lng: lng};
243
+
244
+ // Create map with mapId for AdvancedMarkerElement support
245
+ // If you have a custom map ID from Google Cloud Console, replace "DEMO_MAP_ID" with it
246
+ map = new google.maps.Map(document.getElementById("map_${key}"), {
247
+ zoom: 13,
248
+ center: position,
249
+ draggable: true,
250
+ mapId: "DEMO_MAP_ID" // Required for AdvancedMarkerElement - replace with your actual Map ID
251
+ });
252
+
253
+ // Use AdvancedMarkerElement instead of deprecated Marker
254
+ // Note: AdvancedMarkerElement requires mapId on the map
255
+ try {
256
+ marker = new google.maps.marker.AdvancedMarkerElement({
257
+ position: position,
258
+ map: map,
259
+ gmpDraggable: true,
260
+ title: $("#search_map_location").val() || "Location"
194
261
  });
195
- var marker;
196
- placeMarker(position, map);
197
- var infowindow = new google.maps.InfoWindow();
198
- function placeMarker(position, map) {
199
- marker = new google.maps.Marker({
200
- position: position,
201
- map: map,
202
- draggable: true,
203
- animation: google.maps.Animation.DROP,
262
+
263
+ // Handle marker drag end
264
+ marker.addListener("dragend", function(event) {
265
+ var newPosition = event.latLng || marker.position;
266
+ mapLocationJSON.lat = typeof newPosition.lat === 'function' ? newPosition.lat() : newPosition.lat;
267
+ mapLocationJSON.lon = typeof newPosition.lng === 'function' ? newPosition.lng() : newPosition.lng;
268
+
269
+ var geocoder = new google.maps.Geocoder();
270
+ geocoder.geocode({location: newPosition}, function(results, status) {
271
+ if (status == google.maps.GeocoderStatus.OK) {
272
+ $("#search_map_location").val(results[0].formatted_address);
273
+ $("#mapErrorMsg").hide(100);
274
+ mapLocationJSON.address2 = results[0].formatted_address;
275
+ mapLocationJSON.address1 = $("#search_map_location").val();
276
+ setAddress();
277
+ } else {
278
+ $("#mapErrorMsg").html("Cannot determine address at this location." + status).show(100);
279
+ }
204
280
  });
205
- map.panTo(position);
206
- }
207
- google.maps.event.addListener(marker, 'dragend', function () {
208
- geocodePosition(marker.getPosition());
209
281
  });
210
- google.maps.event.addListener(marker, 'click', function() {
211
- infowindow.setContent($("#search_map_location").val());
212
- infowindow.open(map, this)
282
+
283
+ // Handle marker click
284
+ marker.addListener("click", function() {
285
+ var infoWindow = new google.maps.InfoWindow({
286
+ content: $("#search_map_location").val()
287
+ });
288
+ infoWindow.open(map, marker);
289
+ });
290
+ } catch (e) {
291
+ // Fallback to old Marker API if AdvancedMarkerElement is not available
292
+ console.warn("AdvancedMarkerElement not available, using legacy Marker:", e);
293
+ marker = new google.maps.Marker({
294
+ position: position,
295
+ map: map,
296
+ draggable: true,
297
+ animation: google.maps.Animation.DROP
213
298
  });
214
- function geocodePosition(pos) {
215
- mapLocationJSON.lat=pos.lat();
216
- mapLocationJSON.lon=pos.lng();
299
+
300
+ google.maps.event.addListener(marker, "dragend", function() {
301
+ var newPosition = marker.getPosition();
302
+ mapLocationJSON.lat = newPosition.lat();
303
+ mapLocationJSON.lon = newPosition.lng();
304
+
217
305
  var geocoder = new google.maps.Geocoder();
218
- geocoder.geocode
219
- ({
220
- latLng: pos
221
- },
222
- function (results, status) {
223
- if (status == google.maps.GeocoderStatus.OK) {
224
- $("#search_map_location").val(results[0].formatted_address);
225
- $("#mapErrorMsg").hide(100);
226
- mapLocationJSON.address2=results[0].formatted_address;
227
- mapLocationJSON.address1=$("#search_map_location").val();
228
- setAddress();
229
- } else {
230
- $("#mapErrorMsg").html('Cannot determine address at this location.' + status).show(100);
231
- }
306
+ geocoder.geocode({latLng: newPosition}, function(results, status) {
307
+ if (status == google.maps.GeocoderStatus.OK) {
308
+ $("#search_map_location").val(results[0].formatted_address);
309
+ $("#mapErrorMsg").hide(100);
310
+ mapLocationJSON.address2 = results[0].formatted_address;
311
+ mapLocationJSON.address1 = $("#search_map_location").val();
312
+ setAddress();
313
+ } else {
314
+ $("#mapErrorMsg").html("Cannot determine address at this location." + status).show(100);
232
315
  }
233
- );
234
- }
235
- }`;
316
+ });
317
+ });
318
+
319
+ google.maps.event.addListener(marker, "click", function() {
320
+ var infoWindow = new google.maps.InfoWindow({
321
+ content: $("#search_map_location").val()
322
+ });
323
+ infoWindow.open(map, marker);
324
+ });
325
+ }
326
+
327
+ map.panTo(position);
328
+ }`;
236
329
  return {
237
330
  head: head,
238
331
  end: end,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zet-lib",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "zet is a library that part of zet generator.",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -28,32 +28,38 @@
28
28
  },
29
29
  "sideEffects": false,
30
30
  "dependencies": {
31
- "axios": "^1.6.8",
31
+ "axios": "^1.7.9",
32
32
  "convert-excel-to-json": "^1.7.0",
33
33
  "csurf": "^1.11.0",
34
34
  "dotenv": "^16.5.0",
35
35
  "dropbox": "^10.34.0",
36
- "ejs": "^3.1.9",
36
+ "ejs": "^3.1.10",
37
37
  "exceljs": "^4.4.0",
38
38
  "express-zip": "^3.0.0",
39
- "fs-extra": "^11.3.0",
39
+ "fs-extra": "^11.3.2",
40
40
  "html-minifier-terser": "^7.2.0",
41
41
  "isomorphic-fetch": "^3.0.0",
42
- "js-sha256": "^0.9.0",
42
+ "js-sha256": "^0.11.1",
43
43
  "jszip": "^3.10.1",
44
44
  "moment": "^2.30.1",
45
45
  "node-cache": "^5.1.2",
46
46
  "nodemailer": "^6.9.4",
47
- "pg": "^8.11.2",
47
+ "pg": "^8.16.3",
48
48
  "pm2": "^5.3.1",
49
- "puppeteer": "^24.7.2",
50
- "qs": "^6.11.2",
51
- "randomstring": "^1.3.0",
49
+ "puppeteer": "^24.33.0",
50
+ "qs": "^6.14.0",
51
+ "randomstring": "^1.3.1",
52
52
  "read-excel-file": "^5.8.0",
53
53
  "sharp": "^0.34.1",
54
- "socket.io": "^4.8.0",
55
- "uglify-js": "^3.17.4",
54
+ "socket.io": "^4.8.1",
55
+ "uglify-js": "^3.19.3",
56
56
  "uuid": "^9.0.1",
57
57
  "xlsx": "^0.18.5"
58
+ },
59
+ "overrides": {
60
+ "unzipper": "^0.12.3",
61
+ "rimraf": "^6.1.2",
62
+ "fstream": "^2.0.0",
63
+ "glob": "^11.0.0"
58
64
  }
59
65
  }