propro-utils 1.5.42 → 1.5.46

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.
@@ -3,6 +3,9 @@ const axios = require('axios');
3
3
  const { getOrSetCache } = require('../utils/redis');
4
4
  const { v4: uuidv4 } = require('uuid');
5
5
  const ServiceManager = require('../utils/serviceManager');
6
+ const defaultUserGlobalStyleShortcuts =
7
+ require('./defaultUserGlobalStyleShortcuts.json').defaultGlobalStyleShortcuts;
8
+ const defaultFolders = require('./defaultFolders.json').defaultFolders;
6
9
 
7
10
  /**
8
11
  * Retrieves the account profile data from the authentication server and caches it using Redis.
@@ -59,7 +62,7 @@ const getAccountProfile = async (redisClient, userSchema, accountId) => {
59
62
  };
60
63
 
61
64
  /**
62
- * Creates a new user global styles document.
65
+ * Creates a new user global styles document with default style shortcuts.
63
66
  *
64
67
  * @param {Object} userStyleSchema - The user style schema to perform the operation on.
65
68
  * @param {string} accountId - The account ID of the user.
@@ -69,13 +72,32 @@ async function createUserGlobalStyles(userStyleSchema, accountId) {
69
72
  return await userStyleSchema.create({
70
73
  accountId,
71
74
  id: uuidv4(),
72
- styleShortcuts: [],
75
+ styleShortcuts: defaultUserGlobalStyleShortcuts,
73
76
  });
74
77
  }
75
78
 
79
+ /**
80
+ * Creates default folders for a new user.
81
+ *
82
+ * @param {Object} folderSchema - The folder schema to perform the operation on.
83
+ * @param {string} accountId - The account ID of the user.
84
+ * @returns {Promise<Array>} A promise that resolves to an array of created folder objects.
85
+ */
86
+ async function createDefaultFolders(folderSchema, accountId) {
87
+ const folderPromises = defaultFolders.map(folder =>
88
+ folderSchema.create({
89
+ ...folder,
90
+ id: uuidv4(),
91
+ accountId,
92
+ })
93
+ );
94
+ return Promise.all(folderPromises);
95
+ }
96
+
76
97
  /**
77
98
  * Checks if a user exists based on the given account ID.
78
99
  * If the user does not exist, creates a new user with the given account ID.
100
+ * If the user exists but doesn't have global styles, creates them.
79
101
  *
80
102
  * @param {string} accountId - The account ID of the user to check/create.
81
103
  * @returns {Promise<Object>} A promise that resolves to the user object.
@@ -85,6 +107,7 @@ const checkIfUserExists = async accountId => {
85
107
  try {
86
108
  const userSchema = await ServiceManager.getService('UserSchema');
87
109
  const userStyleSchema = await ServiceManager.getService('UserStyleSchema');
110
+ const folderSchema = await ServiceManager.getService('FolderSchema');
88
111
 
89
112
  let user = await userSchema
90
113
  .findOne({ accountId })
@@ -97,6 +120,14 @@ const checkIfUserExists = async accountId => {
97
120
  accountId
98
121
  );
99
122
  await user.save();
123
+ } else if (user.userGlobalStyles.styleShortcuts.length === 0) {
124
+ user.userGlobalStyles.styleShortcuts = defaultUserGlobalStyleShortcuts;
125
+ await user.userGlobalStyles.save();
126
+ }
127
+ // Check if user has any folders
128
+ const userFolders = await folderSchema.find({ accountId });
129
+ if (userFolders.length === 0) {
130
+ await createDefaultFolders(folderSchema, accountId);
100
131
  }
101
132
  return user;
102
133
  }
@@ -106,6 +137,11 @@ const checkIfUserExists = async accountId => {
106
137
  accountId
107
138
  );
108
139
 
140
+ const folders = await createDefaultFolders(folderSchema, accountId);
141
+ console.log('Folders created:', folders);
142
+ user.folders = folders;
143
+ await user.save();
144
+
109
145
  return await userSchema.create({
110
146
  accountId,
111
147
  id: uuidv4(),
@@ -0,0 +1,23 @@
1
+ {
2
+ "defaultFolders": [
3
+ {
4
+ "name": "Daily Notes",
5
+ "icon": {
6
+ "name": "CabanaMapPennant",
7
+ "color": "#F4BDA5",
8
+ "type": "icon"
9
+ },
10
+ "folderType": "currentDailyNotes"
11
+ },
12
+ {
13
+ "name": "Tasks",
14
+ "icon": {
15
+ "name": "CabanaVariousSubtask",
16
+ "color": "#FB923C",
17
+ "type": "icon"
18
+ },
19
+ "folderType": "currentTasks"
20
+ }
21
+ ]
22
+ }
23
+
@@ -0,0 +1,75 @@
1
+ {
2
+ "defaultGlobalStyleShortcuts": [
3
+ {
4
+ "alternativeShortcut": null,
5
+ "isActive": true,
6
+ "name": "Theme 1",
7
+ "shortcut": "mod+alt+Digit1",
8
+ "styleObject": "{\"border\":{\"thickness\":\"_3\",\"color\":\"#3050d6\"},\"fontSize\":18,\"textAlignment\":\"center\",\"indentation\":\"_0\",\"customWidth\":204}"
9
+ },
10
+ {
11
+ "alternativeShortcut": null,
12
+ "isActive": true,
13
+ "name": "Theme 2",
14
+ "shortcut": "mod+alt+Digit2",
15
+ "styleObject": "{\"border\":{\"isSquared\":true,\"thickness\":\"_1\",\"color\":\"#fff\"},\"fontSize\":12,\"textAlignment\":\"left\"}"
16
+ },
17
+ {
18
+ "alternativeShortcut": null,
19
+ "isActive": true,
20
+ "name": "Theme 3",
21
+ "shortcut": "mod+alt+Digit3",
22
+ "styleObject": "{\"border\":{\"thickness\":\"_1\",\"color\":\"#3050d4\",\"isSquared\":true},\"fontSize\":12,\"textAlignment\":\"left\",\"formattingOfTheEntireNote\":{\"isItalic\":true}}"
23
+ },
24
+ {
25
+ "alternativeShortcut": null,
26
+ "isActive": true,
27
+ "name": "Theme 4",
28
+ "shortcut": "mod+alt+Digit4",
29
+ "styleObject": "{\"fontSize\":28,\"textColor\":\"#fff\",\"formattingOfTheEntireNote\":{\"isBold\":true}}"
30
+ },
31
+ {
32
+ "alternativeShortcut": null,
33
+ "isActive": true,
34
+ "name": "Theme 5",
35
+ "shortcut": "mod+alt+Digit5",
36
+ "styleObject": "{\"textColor\":\"#d73636\",\"textAlignment\":\"left\",\"indentation\":\"_0\"}"
37
+ },
38
+ {
39
+ "alternativeShortcut": null,
40
+ "isActive": true,
41
+ "name": "Theme 6",
42
+ "shortcut": "mod+alt+Digit6",
43
+ "styleObject": "{\"border\":{\"thickness\":\"_2\",\"color\":\"#fb9a12\"},\"fontSize\":14,\"textAlignment\":\"center\",\"indentation\":\"_0\"}"
44
+ },
45
+ {
46
+ "alternativeShortcut": null,
47
+ "isActive": true,
48
+ "name": "Theme 7",
49
+ "shortcut": "mod+alt+Digit7",
50
+ "styleObject": "{\"border\":{\"thickness\":\"_2\",\"color\":\"#d73636\"},\"fontSize\":14,\"textAlignment\":\"center\",\"indentation\":\"_0\"}"
51
+ },
52
+ {
53
+ "alternativeShortcut": null,
54
+ "isActive": true,
55
+ "name": "Theme 8",
56
+ "shortcut": "mod+alt+Digit8",
57
+ "styleObject": "{\"border\":{\"thickness\":\"_2\",\"isSquared\":true},\"textColor\":\"#000000\",\"fillColor\":\"#ffffff\",\"indentation\":\"_0\",\"formattingOfTheEntireNote\":{\"isBold\":true}}"
58
+ },
59
+ {
60
+ "alternativeShortcut": null,
61
+ "isActive": true,
62
+ "name": "Theme 9",
63
+ "shortcut": "mod+alt+Digit9",
64
+ "styleObject": "{\"border\":{\"thickness\":\"_2\",\"color\":\"#d73636\",\"hasDropShadow\":true},\"customWidth\":179,\"textAlignment\":\"center\",\"fontSize\":19}"
65
+ },
66
+ {
67
+ "alternativeShortcut": null,
68
+ "isActive": true,
69
+ "name": "Theme 0",
70
+ "shortcut": "mod+alt+Digit0",
71
+ "styleObject": "{\"overwriteOptions\":{\"affectFontStyle\":true,\"affectBorder\":true,\"affectAlignment\":true,\"affectColor\":true,\"affectSize\":true,\"affectNoteBody\":true,\"affectFade\":true,\"affectSticky\":true}}"
72
+ }
73
+ ]
74
+ }
75
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "propro-utils",
3
- "version": "1.5.42",
3
+ "version": "1.5.46",
4
4
  "description": "Auth middleware for propro-auth",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -117,7 +117,7 @@ class AuthMiddleware {
117
117
  try {
118
118
  const response = await this.proxyToAuthServer(
119
119
  req,
120
- `/api/v1/auth/signup?returnTokens=${returnTokens}`,
120
+ `/api/v1/auth/signup`,
121
121
  req.body
122
122
  );
123
123