@symbo.ls/sdk 2.34.35 → 3.1.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 (187) hide show
  1. package/README.md +2 -143
  2. package/dist/cjs/config/environment.js +30 -98
  3. package/dist/cjs/index.js +24 -144
  4. package/dist/cjs/services/AIService.js +155 -0
  5. package/dist/cjs/services/AuthService.js +305 -738
  6. package/dist/cjs/services/BaseService.js +6 -158
  7. package/dist/cjs/services/BasedService.js +1185 -0
  8. package/dist/cjs/services/CoreService.js +1751 -0
  9. package/dist/cjs/services/SocketIOService.js +307 -0
  10. package/dist/cjs/services/SocketService.js +161 -0
  11. package/dist/cjs/services/SymstoryService.js +571 -0
  12. package/dist/cjs/services/index.js +16 -64
  13. package/dist/cjs/utils/TokenManager.js +30 -78
  14. package/dist/cjs/utils/basedQuerys.js +181 -0
  15. package/dist/cjs/utils/services.js +103 -301
  16. package/dist/cjs/utils/symstoryClient.js +259 -0
  17. package/dist/cjs/utils/validation.js +3 -0
  18. package/dist/esm/config/environment.js +30 -98
  19. package/dist/esm/index.js +8797 -49416
  20. package/dist/esm/services/AIService.js +185 -0
  21. package/dist/esm/services/AuthService.js +386 -1493
  22. package/dist/esm/services/BaseService.js +6 -757
  23. package/dist/esm/services/BasedService.js +5278 -0
  24. package/dist/esm/services/CoreService.js +2264 -0
  25. package/dist/esm/services/SocketIOService.js +470 -0
  26. package/dist/esm/services/SocketService.js +191 -0
  27. package/dist/esm/services/SymstoryService.js +7041 -0
  28. package/dist/esm/services/index.js +8690 -49015
  29. package/dist/esm/utils/TokenManager.js +30 -78
  30. package/dist/esm/utils/basedQuerys.js +163 -0
  31. package/dist/esm/utils/services.js +103 -301
  32. package/dist/esm/utils/symstoryClient.js +370 -0
  33. package/dist/esm/utils/validation.js +7 -4
  34. package/dist/node/config/environment.js +30 -98
  35. package/dist/node/index.js +32 -175
  36. package/dist/node/services/AIService.js +136 -0
  37. package/dist/node/services/AuthService.js +310 -742
  38. package/dist/node/services/BaseService.js +6 -148
  39. package/dist/node/services/BasedService.js +1156 -0
  40. package/dist/node/services/CoreService.js +1722 -0
  41. package/dist/node/services/SocketIOService.js +278 -0
  42. package/dist/node/services/SocketService.js +142 -0
  43. package/dist/node/services/SymstoryService.js +542 -0
  44. package/dist/node/services/index.js +16 -64
  45. package/dist/node/utils/TokenManager.js +30 -78
  46. package/dist/node/utils/basedQuerys.js +162 -0
  47. package/dist/node/utils/services.js +103 -301
  48. package/dist/node/utils/symstoryClient.js +230 -0
  49. package/dist/node/utils/validation.js +3 -0
  50. package/package.json +16 -35
  51. package/src/config/environment.js +28 -99
  52. package/src/index.js +36 -181
  53. package/src/services/AIService.js +150 -0
  54. package/src/services/AuthService.js +328 -874
  55. package/src/services/BaseService.js +6 -166
  56. package/src/services/BasedService.js +1301 -0
  57. package/src/services/CoreService.js +1943 -0
  58. package/src/services/SocketIOService.js +334 -0
  59. package/src/services/SocketService.js +168 -0
  60. package/src/services/SymstoryService.js +649 -0
  61. package/src/services/index.js +13 -80
  62. package/src/utils/TokenManager.js +33 -88
  63. package/src/utils/basedQuerys.js +164 -0
  64. package/src/utils/services.js +107 -326
  65. package/src/utils/symstoryClient.js +252 -0
  66. package/src/utils/validation.js +3 -0
  67. package/dist/cjs/services/AdminService.js +0 -351
  68. package/dist/cjs/services/BranchService.js +0 -484
  69. package/dist/cjs/services/CollabService.js +0 -743
  70. package/dist/cjs/services/DnsService.js +0 -340
  71. package/dist/cjs/services/FeatureFlagService.js +0 -175
  72. package/dist/cjs/services/FileService.js +0 -201
  73. package/dist/cjs/services/IntegrationService.js +0 -538
  74. package/dist/cjs/services/MetricsService.js +0 -62
  75. package/dist/cjs/services/PaymentService.js +0 -271
  76. package/dist/cjs/services/PlanService.js +0 -426
  77. package/dist/cjs/services/ProjectService.js +0 -1207
  78. package/dist/cjs/services/PullRequestService.js +0 -503
  79. package/dist/cjs/services/ScreenshotService.js +0 -304
  80. package/dist/cjs/services/SubscriptionService.js +0 -396
  81. package/dist/cjs/services/TrackingService.js +0 -661
  82. package/dist/cjs/services/WaitlistService.js +0 -148
  83. package/dist/cjs/state/RootStateManager.js +0 -65
  84. package/dist/cjs/state/rootEventBus.js +0 -74
  85. package/dist/cjs/utils/CollabClient.js +0 -223
  86. package/dist/cjs/utils/changePreprocessor.js +0 -199
  87. package/dist/cjs/utils/jsonDiff.js +0 -145
  88. package/dist/cjs/utils/ordering.js +0 -309
  89. package/dist/esm/services/AdminService.js +0 -1132
  90. package/dist/esm/services/BranchService.js +0 -1265
  91. package/dist/esm/services/CollabService.js +0 -26838
  92. package/dist/esm/services/DnsService.js +0 -1121
  93. package/dist/esm/services/FeatureFlagService.js +0 -956
  94. package/dist/esm/services/FileService.js +0 -982
  95. package/dist/esm/services/IntegrationService.js +0 -1319
  96. package/dist/esm/services/MetricsService.js +0 -843
  97. package/dist/esm/services/PaymentService.js +0 -1052
  98. package/dist/esm/services/PlanService.js +0 -1207
  99. package/dist/esm/services/ProjectService.js +0 -2526
  100. package/dist/esm/services/PullRequestService.js +0 -1284
  101. package/dist/esm/services/ScreenshotService.js +0 -1085
  102. package/dist/esm/services/SubscriptionService.js +0 -1177
  103. package/dist/esm/services/TrackingService.js +0 -18343
  104. package/dist/esm/services/WaitlistService.js +0 -929
  105. package/dist/esm/state/RootStateManager.js +0 -90
  106. package/dist/esm/state/rootEventBus.js +0 -56
  107. package/dist/esm/utils/CollabClient.js +0 -18901
  108. package/dist/esm/utils/changePreprocessor.js +0 -542
  109. package/dist/esm/utils/jsonDiff.js +0 -7011
  110. package/dist/esm/utils/ordering.js +0 -291
  111. package/dist/node/services/AdminService.js +0 -332
  112. package/dist/node/services/BranchService.js +0 -465
  113. package/dist/node/services/CollabService.js +0 -724
  114. package/dist/node/services/DnsService.js +0 -321
  115. package/dist/node/services/FeatureFlagService.js +0 -156
  116. package/dist/node/services/FileService.js +0 -182
  117. package/dist/node/services/IntegrationService.js +0 -519
  118. package/dist/node/services/MetricsService.js +0 -43
  119. package/dist/node/services/PaymentService.js +0 -252
  120. package/dist/node/services/PlanService.js +0 -407
  121. package/dist/node/services/ProjectService.js +0 -1188
  122. package/dist/node/services/PullRequestService.js +0 -484
  123. package/dist/node/services/ScreenshotService.js +0 -285
  124. package/dist/node/services/SubscriptionService.js +0 -377
  125. package/dist/node/services/TrackingService.js +0 -632
  126. package/dist/node/services/WaitlistService.js +0 -129
  127. package/dist/node/state/RootStateManager.js +0 -36
  128. package/dist/node/state/rootEventBus.js +0 -55
  129. package/dist/node/utils/CollabClient.js +0 -194
  130. package/dist/node/utils/changePreprocessor.js +0 -180
  131. package/dist/node/utils/jsonDiff.js +0 -116
  132. package/dist/node/utils/ordering.js +0 -290
  133. package/src/services/AdminService.js +0 -374
  134. package/src/services/BranchService.js +0 -536
  135. package/src/services/CollabService.js +0 -900
  136. package/src/services/DnsService.js +0 -366
  137. package/src/services/FeatureFlagService.js +0 -174
  138. package/src/services/FileService.js +0 -213
  139. package/src/services/IntegrationService.js +0 -548
  140. package/src/services/MetricsService.js +0 -40
  141. package/src/services/PaymentService.js +0 -287
  142. package/src/services/PlanService.js +0 -468
  143. package/src/services/ProjectService.js +0 -1366
  144. package/src/services/PullRequestService.js +0 -537
  145. package/src/services/ScreenshotService.js +0 -258
  146. package/src/services/SubscriptionService.js +0 -425
  147. package/src/services/TrackingService.js +0 -853
  148. package/src/services/WaitlistService.js +0 -130
  149. package/src/services/tests/BranchService/createBranch.test.js +0 -153
  150. package/src/services/tests/BranchService/deleteBranch.test.js +0 -173
  151. package/src/services/tests/BranchService/getBranchChanges.test.js +0 -146
  152. package/src/services/tests/BranchService/listBranches.test.js +0 -87
  153. package/src/services/tests/BranchService/mergeBranch.test.js +0 -210
  154. package/src/services/tests/BranchService/publishVersion.test.js +0 -183
  155. package/src/services/tests/BranchService/renameBranch.test.js +0 -240
  156. package/src/services/tests/BranchService/resetBranch.test.js +0 -152
  157. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +0 -67
  158. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +0 -75
  159. package/src/services/tests/FileService/createFileFormData.test.js +0 -74
  160. package/src/services/tests/FileService/getFileUrl.test.js +0 -69
  161. package/src/services/tests/FileService/updateProjectIcon.test.js +0 -109
  162. package/src/services/tests/FileService/uploadDocument.test.js +0 -36
  163. package/src/services/tests/FileService/uploadFile.test.js +0 -78
  164. package/src/services/tests/FileService/uploadFileWithValidation.test.js +0 -114
  165. package/src/services/tests/FileService/uploadImage.test.js +0 -36
  166. package/src/services/tests/FileService/uploadMultipleFiles.test.js +0 -111
  167. package/src/services/tests/FileService/validateFile.test.js +0 -63
  168. package/src/services/tests/PlanService/createPlan.test.js +0 -104
  169. package/src/services/tests/PlanService/createPlanWithValidation.test.js +0 -523
  170. package/src/services/tests/PlanService/deletePlan.test.js +0 -92
  171. package/src/services/tests/PlanService/getActivePlans.test.js +0 -123
  172. package/src/services/tests/PlanService/getAdminPlans.test.js +0 -84
  173. package/src/services/tests/PlanService/getPlan.test.js +0 -50
  174. package/src/services/tests/PlanService/getPlanByKey.test.js +0 -109
  175. package/src/services/tests/PlanService/getPlanWithValidation.test.js +0 -85
  176. package/src/services/tests/PlanService/getPlans.test.js +0 -53
  177. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +0 -109
  178. package/src/services/tests/PlanService/getPlansWithValidation.test.js +0 -48
  179. package/src/services/tests/PlanService/initializePlans.test.js +0 -75
  180. package/src/services/tests/PlanService/updatePlan.test.js +0 -111
  181. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +0 -556
  182. package/src/state/RootStateManager.js +0 -76
  183. package/src/state/rootEventBus.js +0 -67
  184. package/src/utils/CollabClient.js +0 -248
  185. package/src/utils/changePreprocessor.js +0 -239
  186. package/src/utils/jsonDiff.js +0 -144
  187. package/src/utils/ordering.js +0 -271
@@ -1,291 +0,0 @@
1
- // src/utils/ordering.js
2
- function isObjectLike(val) {
3
- return val && typeof val === "object" && !Array.isArray(val);
4
- }
5
- function normalizePath(path) {
6
- if (Array.isArray(path)) {
7
- return path;
8
- }
9
- if (typeof path === "string") {
10
- return [path];
11
- }
12
- return [];
13
- }
14
- function getParentPathsFromTuples(tuples = []) {
15
- const seen = /* @__PURE__ */ new Set();
16
- const parents = [];
17
- const META_KEYS = /* @__PURE__ */ new Set([
18
- "style",
19
- "class",
20
- "text",
21
- "html",
22
- "content",
23
- "data",
24
- "attr",
25
- "state",
26
- "scope",
27
- "define",
28
- "on",
29
- "extend",
30
- "extends",
31
- "childExtend",
32
- "childExtends",
33
- "children",
34
- "component",
35
- "context",
36
- "tag",
37
- "key",
38
- "__order",
39
- "if"
40
- ]);
41
- for (let i = 0; i < tuples.length; i++) {
42
- const tuple = tuples[i];
43
- if (!Array.isArray(tuple) || tuple.length < 2) {
44
- continue;
45
- }
46
- const path = normalizePath(tuple[1]);
47
- if (!path.length) {
48
- continue;
49
- }
50
- if (path[0] === "schema") {
51
- continue;
52
- }
53
- const immediateParent = path.slice(0, -1);
54
- if (immediateParent.length) {
55
- const key = JSON.stringify(immediateParent);
56
- if (!seen.has(key)) {
57
- seen.add(key);
58
- parents.push(immediateParent);
59
- }
60
- }
61
- const last = path[path.length - 1];
62
- if (META_KEYS.has(last) && path.length >= 2) {
63
- const containerParent = path.slice(0, -2);
64
- if (containerParent.length) {
65
- const key2 = JSON.stringify(containerParent);
66
- if (!seen.has(key2)) {
67
- seen.add(key2);
68
- parents.push(containerParent);
69
- }
70
- }
71
- }
72
- for (let j = 0; j < path.length; j++) {
73
- const seg = path[j];
74
- if (!META_KEYS.has(seg)) {
75
- continue;
76
- }
77
- const containerParent2 = path.slice(0, j);
78
- if (!containerParent2.length) {
79
- continue;
80
- }
81
- const key3 = JSON.stringify(containerParent2);
82
- if (!seen.has(key3)) {
83
- seen.add(key3);
84
- parents.push(containerParent2);
85
- }
86
- }
87
- }
88
- return parents;
89
- }
90
- function computeOrdersFromState(root, parentPaths = []) {
91
- if (!root || typeof root.getByPath !== "function") {
92
- return [];
93
- }
94
- const orders = [];
95
- const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
96
- for (let i = 0; i < parentPaths.length; i++) {
97
- const parentPath = parentPaths[i];
98
- const obj = (() => {
99
- try {
100
- return root.getByPath(parentPath);
101
- } catch {
102
- return null;
103
- }
104
- })();
105
- if (!isObjectLike(obj)) {
106
- continue;
107
- }
108
- const keys = Object.keys(obj).filter((k) => !EXCLUDE_KEYS.has(k));
109
- orders.push({ path: parentPath, keys });
110
- }
111
- return orders;
112
- }
113
- function normaliseSchemaCode(code) {
114
- if (typeof code !== "string" || !code.length) {
115
- return "";
116
- }
117
- return code.replaceAll("/////n", "\n").replaceAll("/////tilde", "`");
118
- }
119
- function parseExportedObject(code) {
120
- const src = normaliseSchemaCode(code);
121
- if (!src) {
122
- return null;
123
- }
124
- const body = src.replace(/^\s*export\s+default\s*/u, "return ");
125
- try {
126
- return new Function(body)();
127
- } catch {
128
- return null;
129
- }
130
- }
131
- function extractTopLevelKeysFromCode(code) {
132
- const obj = parseExportedObject(code);
133
- if (!obj || typeof obj !== "object") {
134
- return [];
135
- }
136
- return Object.keys(obj);
137
- }
138
- function computeOrdersForTuples(root, tuples = []) {
139
- const pendingChildrenByContainer = /* @__PURE__ */ new Map();
140
- for (let i = 0; i < tuples.length; i++) {
141
- const t = tuples[i];
142
- if (!Array.isArray(t)) {
143
- continue;
144
- }
145
- const [action, path] = t;
146
- const p = normalizePath(path);
147
- if (!Array.isArray(p) || p.length < 2) {
148
- continue;
149
- }
150
- if (p[0] === "schema") {
151
- continue;
152
- }
153
- const containerPath = p.slice(0, -1);
154
- const childKey = p[p.length - 1];
155
- const key = JSON.stringify(containerPath);
156
- if (!pendingChildrenByContainer.has(key)) {
157
- pendingChildrenByContainer.set(key, /* @__PURE__ */ new Set());
158
- }
159
- if (action === "update" || action === "set") {
160
- pendingChildrenByContainer.get(key).add(childKey);
161
- }
162
- }
163
- const preferredOrderMap = /* @__PURE__ */ new Map();
164
- for (let i = 0; i < tuples.length; i++) {
165
- const t = tuples[i];
166
- if (!Array.isArray(t)) {
167
- continue;
168
- }
169
- const [action, path, value] = t;
170
- const p = normalizePath(path);
171
- if (action !== "update" || !Array.isArray(p) || p.length < 3) {
172
- continue;
173
- }
174
- if (p[0] !== "schema") {
175
- continue;
176
- }
177
- const [, type, key] = p;
178
- const containerPath = [type, key];
179
- const uses = value && Array.isArray(value.uses) ? value.uses : null;
180
- const code = value && value.code;
181
- const obj = (() => {
182
- try {
183
- return root && typeof root.getByPath === "function" ? root.getByPath(containerPath) : null;
184
- } catch {
185
- return null;
186
- }
187
- })();
188
- if (!obj) {
189
- continue;
190
- }
191
- const present = new Set(Object.keys(obj));
192
- const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
193
- const codeKeys = extractTopLevelKeysFromCode(code);
194
- let resolved = [];
195
- const pendingKey = JSON.stringify(containerPath);
196
- const pendingChildren = pendingChildrenByContainer.get(pendingKey) || /* @__PURE__ */ new Set();
197
- const eligible = /* @__PURE__ */ new Set([...present, ...pendingChildren]);
198
- if (Array.isArray(codeKeys) && codeKeys.length) {
199
- resolved = codeKeys.filter((k) => eligible.has(k) && !EXCLUDE_KEYS.has(k));
200
- }
201
- if (Array.isArray(uses) && uses.length) {
202
- for (let u = 0; u < uses.length; u++) {
203
- const keyName = uses[u];
204
- if (eligible.has(keyName) && !EXCLUDE_KEYS.has(keyName) && !resolved.includes(keyName)) {
205
- resolved.push(keyName);
206
- }
207
- }
208
- }
209
- if (pendingChildren.size) {
210
- for (const child of pendingChildren) {
211
- if (!EXCLUDE_KEYS.has(child) && !resolved.includes(child)) {
212
- resolved.push(child);
213
- }
214
- }
215
- }
216
- if (resolved.length) {
217
- preferredOrderMap.set(JSON.stringify(containerPath), { path: containerPath, keys: resolved });
218
- }
219
- }
220
- const parents = getParentPathsFromTuples(tuples);
221
- const orders = [];
222
- const seen = /* @__PURE__ */ new Set();
223
- preferredOrderMap.forEach((v) => {
224
- const k = JSON.stringify(v.path);
225
- if (!seen.has(k)) {
226
- seen.add(k);
227
- orders.push(v);
228
- }
229
- });
230
- const fallbackOrders = computeOrdersFromState(root, parents);
231
- for (let i = 0; i < fallbackOrders.length; i++) {
232
- const v = fallbackOrders[i];
233
- const k = JSON.stringify(v.path);
234
- if (seen.has(k)) {
235
- continue;
236
- }
237
- const pending = pendingChildrenByContainer.get(k);
238
- if (pending && pending.size) {
239
- const existingKeys = v.keys;
240
- const existingSet = new Set(existingKeys);
241
- const META_KEYS = /* @__PURE__ */ new Set([
242
- "style",
243
- "class",
244
- "text",
245
- "html",
246
- "content",
247
- "data",
248
- "attr",
249
- "state",
250
- "scope",
251
- "define",
252
- "on",
253
- "extend",
254
- "extends",
255
- "childExtend",
256
- "childExtends",
257
- "children",
258
- "component",
259
- "context",
260
- "tag",
261
- "key",
262
- "__order",
263
- "if"
264
- ]);
265
- let firstMetaIndex = existingKeys.length;
266
- for (let j = 0; j < existingKeys.length; j++) {
267
- if (META_KEYS.has(existingKeys[j])) {
268
- firstMetaIndex = j;
269
- break;
270
- }
271
- }
272
- for (const child of pending) {
273
- if (existingSet.has(child)) {
274
- continue;
275
- }
276
- const insertIndex = firstMetaIndex;
277
- existingKeys.splice(insertIndex, 0, child);
278
- existingSet.add(child);
279
- firstMetaIndex++;
280
- }
281
- }
282
- seen.add(k);
283
- orders.push(v);
284
- }
285
- return orders;
286
- }
287
- export {
288
- computeOrdersForTuples,
289
- computeOrdersFromState,
290
- getParentPathsFromTuples
291
- };
@@ -1,332 +0,0 @@
1
- import { BaseService } from "./BaseService.js";
2
- class AdminService extends BaseService {
3
- // ==================== ADMIN METHODS ====================
4
- /**
5
- * Get admin users list with comprehensive filtering and search capabilities
6
- * Requires admin or super_admin global role
7
- */
8
- async getAdminUsers(params = {}) {
9
- this._requireReady("getAdminUsers");
10
- const {
11
- emails,
12
- ids,
13
- query,
14
- status,
15
- page = 1,
16
- limit = 50,
17
- sort = { field: "createdAt", order: "desc" }
18
- } = params;
19
- const queryParams = new URLSearchParams();
20
- if (emails) {
21
- queryParams.append("emails", emails);
22
- }
23
- if (ids) {
24
- queryParams.append("ids", ids);
25
- }
26
- if (query) {
27
- queryParams.append("query", query);
28
- }
29
- if (status) {
30
- queryParams.append("status", status);
31
- }
32
- if (page) {
33
- queryParams.append("page", page.toString());
34
- }
35
- if (limit) {
36
- queryParams.append("limit", limit.toString());
37
- }
38
- if (sort && sort.field) {
39
- queryParams.append("sort[field]", sort.field);
40
- queryParams.append("sort[order]", sort.order || "desc");
41
- }
42
- const queryString = queryParams.toString();
43
- const url = `/users/admin/users${queryString ? `?${queryString}` : ""}`;
44
- try {
45
- const response = await this._request(url, {
46
- method: "GET",
47
- methodName: "getAdminUsers"
48
- });
49
- if (response.success) {
50
- return response.data;
51
- }
52
- throw new Error(response.message);
53
- } catch (error) {
54
- throw new Error(`Failed to get admin users: ${error.message}`, { cause: error });
55
- }
56
- }
57
- /**
58
- * Assign projects to a specific user
59
- * Requires admin or super_admin global role
60
- */
61
- async assignProjectsToUser(userId, options = {}) {
62
- this._requireReady("assignProjectsToUser");
63
- if (!userId) {
64
- throw new Error("User ID is required");
65
- }
66
- const { projectIds, role = "guest" } = options;
67
- const requestBody = {
68
- userId,
69
- role
70
- };
71
- if (projectIds && Array.isArray(projectIds)) {
72
- requestBody.projectIds = projectIds;
73
- }
74
- try {
75
- const response = await this._request("/assign-projects", {
76
- method: "POST",
77
- body: JSON.stringify(requestBody),
78
- methodName: "assignProjectsToUser"
79
- });
80
- if (response.success) {
81
- return response.data;
82
- }
83
- throw new Error(response.message);
84
- } catch (error) {
85
- throw new Error(`Failed to assign projects to user: ${error.message}`, { cause: error });
86
- }
87
- }
88
- /**
89
- * Update user information (admin only)
90
- */
91
- async updateUser(userId, userData) {
92
- var _a;
93
- this._requireReady("updateUser");
94
- if (!userId) {
95
- throw new Error("User ID is required");
96
- }
97
- if (!userData || typeof userData !== "object" || Object.keys(userData).length === 0) {
98
- throw new Error("userData must be a non-empty object");
99
- }
100
- try {
101
- const response = await this._request(`/users/${userId}`, {
102
- method: "PATCH",
103
- body: JSON.stringify(userData),
104
- methodName: "updateUser"
105
- });
106
- if (response.success) {
107
- return response.data;
108
- }
109
- throw new Error(response.message);
110
- } catch (error) {
111
- if ((_a = error.message) == null ? void 0 : _a.includes("Duplicate")) {
112
- throw new Error("Username already exists");
113
- }
114
- throw new Error(`Failed to update user: ${error.message}`, { cause: error });
115
- }
116
- }
117
- // ==================== ADMIN HELPER METHODS ====================
118
- /**
119
- * Helper method for admin users search
120
- */
121
- async searchAdminUsers(searchQuery, options = {}) {
122
- return await this.getAdminUsers({
123
- query: searchQuery,
124
- ...options
125
- });
126
- }
127
- /**
128
- * Helper method to get admin users by email list
129
- */
130
- async getAdminUsersByEmails(emails, options = {}) {
131
- const emailList = Array.isArray(emails) ? emails.join(",") : emails;
132
- return await this.getAdminUsers({
133
- emails: emailList,
134
- ...options
135
- });
136
- }
137
- /**
138
- * Helper method to get admin users by ID list
139
- */
140
- async getAdminUsersByIds(ids, options = {}) {
141
- const idList = Array.isArray(ids) ? ids.join(",") : ids;
142
- return await this.getAdminUsers({
143
- ids: idList,
144
- ...options
145
- });
146
- }
147
- /**
148
- * Helper method to assign specific projects to a user with a specific role
149
- */
150
- async assignSpecificProjectsToUser(userId, projectIds, role = "guest") {
151
- if (!Array.isArray(projectIds) || projectIds.length === 0) {
152
- throw new Error("Project IDs must be a non-empty array");
153
- }
154
- return await this.assignProjectsToUser(userId, {
155
- projectIds,
156
- role
157
- });
158
- }
159
- /**
160
- * Helper method to assign all projects to a user with a specific role
161
- */
162
- async assignAllProjectsToUser(userId, role = "guest") {
163
- return await this.assignProjectsToUser(userId, {
164
- role
165
- });
166
- }
167
- /**
168
- * Helper method to validate user data for updates
169
- */
170
- validateUserData(userData) {
171
- const errors = [];
172
- if (!userData || typeof userData !== "object") {
173
- errors.push("User data must be an object");
174
- return { isValid: false, errors };
175
- }
176
- if (userData.email && typeof userData.email !== "string") {
177
- errors.push("Email must be a string");
178
- } else if (userData.email && !this._isValidEmail(userData.email)) {
179
- errors.push("Email must be a valid email address");
180
- }
181
- if (userData.username && typeof userData.username !== "string") {
182
- errors.push("Username must be a string");
183
- } else if (userData.username && userData.username.length < 3) {
184
- errors.push("Username must be at least 3 characters long");
185
- }
186
- if (userData.role && !["admin", "user", "guest"].includes(userData.role)) {
187
- errors.push("Role must be one of: admin, user, guest");
188
- }
189
- if (userData.status && !["active", "inactive", "suspended"].includes(userData.status)) {
190
- errors.push("Status must be one of: active, inactive, suspended");
191
- }
192
- return {
193
- isValid: errors.length === 0,
194
- errors
195
- };
196
- }
197
- /**
198
- * Helper method to update user with validation
199
- */
200
- async updateUserWithValidation(userId, userData) {
201
- const validation = this.validateUserData(userData);
202
- if (!validation.isValid) {
203
- throw new Error(`Validation failed: ${validation.errors.join(", ")}`);
204
- }
205
- return await this.updateUser(userId, userData);
206
- }
207
- /**
208
- * Helper method to get user statistics
209
- */
210
- async getUserStats() {
211
- try {
212
- const users = await this.getAdminUsers({ limit: 1e3 });
213
- const stats = {
214
- total: users.length,
215
- active: 0,
216
- inactive: 0,
217
- suspended: 0,
218
- admins: 0,
219
- users: 0,
220
- guests: 0
221
- };
222
- users.forEach((user) => {
223
- if (user.status === "active") {
224
- stats.active++;
225
- }
226
- if (user.status === "inactive") {
227
- stats.inactive++;
228
- }
229
- if (user.status === "suspended") {
230
- stats.suspended++;
231
- }
232
- if (user.role === "admin") {
233
- stats.admins++;
234
- }
235
- if (user.role === "user") {
236
- stats.users++;
237
- }
238
- if (user.role === "guest") {
239
- stats.guests++;
240
- }
241
- });
242
- return stats;
243
- } catch (error) {
244
- throw new Error(`Failed to get user stats: ${error.message}`, { cause: error });
245
- }
246
- }
247
- /**
248
- * Helper method to bulk update users
249
- */
250
- async bulkUpdateUsers(userUpdates) {
251
- if (!Array.isArray(userUpdates) || userUpdates.length === 0) {
252
- throw new Error("User updates must be a non-empty array");
253
- }
254
- const updatePromises = userUpdates.map(async (update) => {
255
- try {
256
- const result = await this.updateUser(update.userId, update.userData);
257
- return {
258
- userId: update.userId,
259
- success: true,
260
- data: result
261
- };
262
- } catch (error) {
263
- return {
264
- userId: update.userId,
265
- success: false,
266
- error: error.message
267
- };
268
- }
269
- });
270
- const results = await Promise.all(updatePromises);
271
- return {
272
- total: results.length,
273
- successful: results.filter((r) => r.success).length,
274
- failed: results.filter((r) => !r.success).length,
275
- results
276
- };
277
- }
278
- /**
279
- * Helper method to get users by role
280
- */
281
- async getUsersByRole(role, options = {}) {
282
- const users = await this.getAdminUsers(options);
283
- return users.filter((user) => user.role === role);
284
- }
285
- /**
286
- * Helper method to get users by status
287
- */
288
- async getUsersByStatus(status, options = {}) {
289
- const users = await this.getAdminUsers(options);
290
- return users.filter((user) => user.status === status);
291
- }
292
- /**
293
- * Helper method to activate a user
294
- */
295
- async activateUser(userId) {
296
- return await this.updateUser(userId, { status: "active" });
297
- }
298
- /**
299
- * Helper method to deactivate a user
300
- */
301
- async deactivateUser(userId) {
302
- return await this.updateUser(userId, { status: "inactive" });
303
- }
304
- /**
305
- * Helper method to suspend a user
306
- */
307
- async suspendUser(userId) {
308
- return await this.updateUser(userId, { status: "suspended" });
309
- }
310
- /**
311
- * Helper method to promote user to admin
312
- */
313
- async promoteToAdmin(userId) {
314
- return await this.updateUser(userId, { role: "admin" });
315
- }
316
- /**
317
- * Helper method to demote user from admin
318
- */
319
- async demoteFromAdmin(userId) {
320
- return await this.updateUser(userId, { role: "user" });
321
- }
322
- /**
323
- * Private helper to validate email format
324
- */
325
- _isValidEmail(email) {
326
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/u;
327
- return emailRegex.test(email);
328
- }
329
- }
330
- export {
331
- AdminService
332
- };