mango-cms 0.2.46 → 0.2.48

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/cli.js CHANGED
@@ -168,6 +168,13 @@ program
168
168
  fs.mkdirSync(projectDir);
169
169
  fs.copySync(templateDir, projectDir, { filter: (src, dest) => true });
170
170
 
171
+ // Copy gitignore file (npm excludes .gitignore, so we store it as gitignore)
172
+ const gitignoreSource = path.join(templateDir, 'gitignore');
173
+ const gitignoreDest = path.join(projectDir, '.gitignore');
174
+ if (fs.existsSync(gitignoreSource)) {
175
+ fs.copySync(gitignoreSource, gitignoreDest);
176
+ }
177
+
171
178
  // Create config directory if it doesn't exist
172
179
  const configDir = path.join(projectDir, 'mango');
173
180
 
@@ -668,6 +675,60 @@ program
668
675
  }
669
676
  });
670
677
 
678
+ program
679
+ .command('pull')
680
+ .description('Pull the remote database to your local machine')
681
+ .action(async () => {
682
+ try {
683
+ const configPath = path.join(process.cwd(), 'mango/config/settings.json');
684
+
685
+ if (!fs.existsSync(configPath)) {
686
+ console.error('Error: settings.json not found at', configPath);
687
+ process.exit(1);
688
+ }
689
+
690
+ const settings = JSON.parse(fs.readFileSync(configPath, 'utf8'));
691
+ const serverIp = settings.serverIp;
692
+ const database = settings.database;
693
+
694
+ if (!serverIp) {
695
+ console.error('Error: serverIp is not configured in settings.json');
696
+ process.exit(1);
697
+ }
698
+
699
+ if (!database) {
700
+ console.error('Error: database is not configured in settings.json');
701
+ process.exit(1);
702
+ }
703
+
704
+ console.log(`Using server IP: ${serverIp}`);
705
+ console.log(`Using database: ${database}`);
706
+
707
+ const downloadsDir = path.join(require('os').homedir(), 'Downloads');
708
+ const dumpZip = path.join(downloadsDir, 'dump.zip');
709
+ const dumpDir = path.join(downloadsDir, 'dump');
710
+
711
+ console.log('Dumping remote database...');
712
+ execSync(`ssh root@${serverIp} "rm -rf dump dump.zip; mongodump --db ${database}; zip -r dump.zip dump/${database}"`, { stdio: 'inherit' });
713
+
714
+ console.log('Downloading dump...');
715
+ execSync(`rsync root@${serverIp}:~/dump.zip ${dumpZip}`, { stdio: 'inherit' });
716
+
717
+ console.log('Restoring locally...');
718
+ execSync(`unzip -o ${dumpZip}`, { cwd: downloadsDir, stdio: 'inherit' });
719
+ execSync(`mongorestore --drop --db ${database} ${path.join(dumpDir, database)}`, { stdio: 'inherit' });
720
+
721
+ // Clean up
722
+ fs.removeSync(dumpDir);
723
+ fs.removeSync(dumpZip);
724
+
725
+ console.log(`\n✨ Database "${database}" pulled and restored successfully!`);
726
+ } catch (error) {
727
+ console.error('Error pulling database:', error.message);
728
+ process.exit(1);
729
+ }
730
+ });
731
+
671
732
  program
672
733
  .command('update')
673
734
  .description('Update Mango CMS source files to the latest version')
@@ -0,0 +1,5 @@
1
+ node_modules
2
+ .DS_store
3
+ yarn.lock
4
+ build
5
+ dist
@@ -4,7 +4,7 @@ let { PlainText, Select, Timestamp, Relationship } = fields
4
4
  export default {
5
5
 
6
6
  // title: PlainText({ required: true }),
7
- author: Relationship({ collection: 'member', single: true, computed: (doc, req) => [req?.member?.id] || [] }),
7
+ author: Relationship({ collection: 'member', single: true, default: (doc, req) => req?.member?.id || null }),
8
8
  editId: { computed: (doc, req) => req?.member?.id || null },
9
9
  created: { computed: doc => doc.created || new Date, type: 'Float' },
10
10
  updated: { computed: doc => doc.updated ? new Date : doc.created, type: 'Float' },
@@ -23,6 +23,7 @@
23
23
  "s3Bucket": "exampleBucket",
24
24
 
25
25
  "emailProvider": "resend",
26
+ "emailFrom": "Example <info@example.com>",
26
27
  "resendKey": null,
27
28
  "mailgunKey": null,
28
29
  "emailDomain": null,
@@ -33,9 +33,9 @@ echo "Using server IP: $SERVER_IP"
33
33
  echo "Using database: $DATABASE"
34
34
 
35
35
  cd ~/Downloads;
36
- ssh root@$SERVER_IP "rm -rf dump.zip; mongodump --db $DATABASE; zip -r dump.zip dump"
36
+ ssh root@$SERVER_IP "rm -rf dump dump.zip; mongodump --db $DATABASE; zip -r dump.zip dump/$DATABASE"
37
37
  rsync root@$SERVER_IP:~/dump.zip ~/Downloads/dump.zip;
38
38
  unzip -o dump.zip;
39
- mongorestore --drop dump;
39
+ mongorestore --drop --db $DATABASE dump/$DATABASE;
40
40
  rm -rf dump;
41
41
  rm -rf dump.zip;
@@ -25,7 +25,7 @@
25
25
  "dayjs": "^1.10.7",
26
26
  "express": "^4.18.1",
27
27
  "google-maps": "^4.3.3",
28
- "mango-cms": "^0.2.46",
28
+ "mango-cms": "^0.2.48",
29
29
  "mapbox-gl": "^2.7.0",
30
30
  "sweetalert2": "^11.4.0",
31
31
  "vite": "^6.2.2",
@@ -87,6 +87,14 @@ const processFields = (fields, collectionName) => {
87
87
  return result
88
88
  }
89
89
 
90
+ // Function for setting cookies
91
+ let setCookie = function (cname, cvalue) {
92
+ var d = new Date();
93
+ d.setTime(d.getTime() + (365 * 24 * 60 * 60 * 1000));
94
+ var expires = "expires=" + d.toUTCString();
95
+ document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
96
+ }
97
+
90
98
  const Mango = collections.reduce((a, c) => {
91
99
  let localDB = new LocalDB(c.name, api)
92
100
 
@@ -348,6 +356,11 @@ const Mango = collections.reduce((a, c) => {
348
356
  a[c.singular]['local']['delete'] = localDB.delete
349
357
  a[c.name]['sync'] = sync
350
358
 
359
+ a[c.name]['count'] = ({ search } = {}) => {
360
+ return runQuery({ search, fields: ['id'], verbose: true })
361
+ .then(data => data?.count || 0)
362
+ }
363
+
351
364
  a[c.name]['search'] = search
352
365
  a[c.name]['search']['init'] = (search, query, algoliaFilters) => {
353
366
  let loading = ref(true)
@@ -487,12 +500,22 @@ Mango.login = ({ email, password }) => {
487
500
  window.localStorage.setItem('token', response.data.token)
488
501
  window.localStorage.setItem('user', response.data.memberId)
489
502
  window.localStorage.setItem('email', email)
503
+ setCookie(`Authorization`, `${response.data.token}`)
490
504
  resolve(response.data)
491
505
  })
492
506
  .catch((e) => reject(e))
493
507
  })
494
508
  }
495
509
 
510
+ Mango.logout = (axios) => {
511
+ window.localStorage.removeItem('token')
512
+ window.localStorage.removeItem('user')
513
+ window.localStorage.removeItem('email')
514
+ setCookie(`Authorization`, ``)
515
+ if (axios) delete axios.defaults.headers.common['Authorization']
516
+ return true
517
+ }
518
+
496
519
  // Build endpoints from the generated .endpoints.json
497
520
  Mango.endpoints = Object.keys(endpointsData).reduce((acc, path) => {
498
521
  const methods = endpointsData[path]
@@ -71,5 +71,6 @@ export default defineConfig({
71
71
  },
72
72
  optimizeDeps: {
73
73
  exclude: ['vue', '@collections', '@settings', '@endpoints'], // Prevent Vite from optimizing Vue separately
74
+ include: ['socket.io-client'],
74
75
  },
75
76
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mango-cms",
3
- "version": "0.2.46",
3
+ "version": "0.2.48",
4
4
  "main": "./index.js",
5
5
  "exports": {
6
6
  ".": "./index.js",