@symbo.ls/sdk 2.34.34 → 3.1.1

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 +13 -315
  2. package/dist/cjs/config/environment.js +50 -124
  3. package/dist/cjs/index.js +22 -169
  4. package/dist/cjs/services/AIService.js +155 -0
  5. package/dist/cjs/services/AuthService.js +277 -751
  6. package/dist/cjs/services/BaseService.js +6 -158
  7. package/dist/cjs/services/BasedService.js +679 -0
  8. package/dist/cjs/services/SocketIOService.js +309 -0
  9. package/dist/cjs/services/SocketService.js +161 -0
  10. package/dist/cjs/services/SymstoryService.js +485 -0
  11. package/dist/cjs/services/index.js +16 -64
  12. package/dist/cjs/utils/basedQuerys.js +61 -0
  13. package/dist/cjs/utils/permission.js +4 -4
  14. package/dist/cjs/utils/services.js +80 -301
  15. package/dist/cjs/utils/symstoryClient.js +228 -0
  16. package/dist/cjs/utils/validation.js +3 -0
  17. package/dist/esm/config/environment.js +50 -124
  18. package/dist/esm/index.js +11282 -49789
  19. package/dist/esm/services/AIService.js +185 -0
  20. package/dist/esm/services/AuthService.js +358 -1506
  21. package/dist/esm/services/BaseService.js +6 -757
  22. package/dist/esm/services/BasedService.js +4651 -0
  23. package/dist/esm/services/SocketIOService.js +467 -0
  24. package/dist/esm/services/SocketService.js +191 -0
  25. package/dist/esm/services/SymstoryService.js +6849 -0
  26. package/dist/esm/services/index.js +11188 -49352
  27. package/dist/esm/utils/basedQuerys.js +43 -0
  28. package/dist/esm/utils/permission.js +4 -4
  29. package/dist/esm/utils/services.js +80 -301
  30. package/dist/esm/utils/symstoryClient.js +334 -0
  31. package/dist/esm/utils/validation.js +26 -93
  32. package/dist/node/config/environment.js +50 -124
  33. package/dist/node/index.js +26 -202
  34. package/dist/node/services/AIService.js +136 -0
  35. package/dist/node/services/AuthService.js +278 -751
  36. package/dist/node/services/BaseService.js +6 -148
  37. package/dist/node/services/BasedService.js +650 -0
  38. package/dist/node/services/SocketIOService.js +280 -0
  39. package/dist/node/services/SocketService.js +142 -0
  40. package/dist/node/services/SymstoryService.js +456 -0
  41. package/dist/node/services/index.js +16 -64
  42. package/dist/node/utils/basedQuerys.js +42 -0
  43. package/dist/node/utils/permission.js +4 -4
  44. package/dist/node/utils/services.js +80 -301
  45. package/dist/node/utils/symstoryClient.js +199 -0
  46. package/dist/node/utils/validation.js +3 -0
  47. package/package.json +21 -43
  48. package/src/config/environment.js +50 -126
  49. package/src/index.js +24 -208
  50. package/src/services/AIService.js +150 -0
  51. package/src/services/AuthService.js +298 -893
  52. package/src/services/BaseService.js +6 -166
  53. package/src/services/BasedService.js +722 -0
  54. package/src/services/SocketIOService.js +356 -0
  55. package/src/services/SocketService.js +168 -0
  56. package/src/services/SymstoryService.js +563 -0
  57. package/src/services/index.js +13 -80
  58. package/src/utils/basedQuerys.js +41 -0
  59. package/src/utils/permission.js +4 -4
  60. package/src/utils/services.js +83 -325
  61. package/src/utils/symstoryClient.js +218 -0
  62. package/src/utils/validation.js +3 -0
  63. package/dist/cjs/services/AdminService.js +0 -351
  64. package/dist/cjs/services/BranchService.js +0 -484
  65. package/dist/cjs/services/CollabService.js +0 -743
  66. package/dist/cjs/services/DnsService.js +0 -340
  67. package/dist/cjs/services/FeatureFlagService.js +0 -175
  68. package/dist/cjs/services/FileService.js +0 -201
  69. package/dist/cjs/services/IntegrationService.js +0 -538
  70. package/dist/cjs/services/MetricsService.js +0 -62
  71. package/dist/cjs/services/PaymentService.js +0 -271
  72. package/dist/cjs/services/PlanService.js +0 -426
  73. package/dist/cjs/services/ProjectService.js +0 -1207
  74. package/dist/cjs/services/PullRequestService.js +0 -503
  75. package/dist/cjs/services/ScreenshotService.js +0 -304
  76. package/dist/cjs/services/SubscriptionService.js +0 -396
  77. package/dist/cjs/services/TrackingService.js +0 -661
  78. package/dist/cjs/services/WaitlistService.js +0 -148
  79. package/dist/cjs/state/RootStateManager.js +0 -65
  80. package/dist/cjs/state/rootEventBus.js +0 -74
  81. package/dist/cjs/utils/CollabClient.js +0 -223
  82. package/dist/cjs/utils/TokenManager.js +0 -422
  83. package/dist/cjs/utils/changePreprocessor.js +0 -199
  84. package/dist/cjs/utils/jsonDiff.js +0 -145
  85. package/dist/cjs/utils/ordering.js +0 -309
  86. package/dist/esm/services/AdminService.js +0 -1132
  87. package/dist/esm/services/BranchService.js +0 -1265
  88. package/dist/esm/services/CollabService.js +0 -26838
  89. package/dist/esm/services/DnsService.js +0 -1121
  90. package/dist/esm/services/FeatureFlagService.js +0 -956
  91. package/dist/esm/services/FileService.js +0 -982
  92. package/dist/esm/services/IntegrationService.js +0 -1319
  93. package/dist/esm/services/MetricsService.js +0 -843
  94. package/dist/esm/services/PaymentService.js +0 -1052
  95. package/dist/esm/services/PlanService.js +0 -1207
  96. package/dist/esm/services/ProjectService.js +0 -2526
  97. package/dist/esm/services/PullRequestService.js +0 -1284
  98. package/dist/esm/services/ScreenshotService.js +0 -1085
  99. package/dist/esm/services/SubscriptionService.js +0 -1177
  100. package/dist/esm/services/TrackingService.js +0 -18343
  101. package/dist/esm/services/WaitlistService.js +0 -929
  102. package/dist/esm/state/RootStateManager.js +0 -90
  103. package/dist/esm/state/rootEventBus.js +0 -56
  104. package/dist/esm/utils/CollabClient.js +0 -18901
  105. package/dist/esm/utils/TokenManager.js +0 -408
  106. package/dist/esm/utils/changePreprocessor.js +0 -542
  107. package/dist/esm/utils/jsonDiff.js +0 -7011
  108. package/dist/esm/utils/ordering.js +0 -291
  109. package/dist/node/services/AdminService.js +0 -332
  110. package/dist/node/services/BranchService.js +0 -465
  111. package/dist/node/services/CollabService.js +0 -724
  112. package/dist/node/services/DnsService.js +0 -321
  113. package/dist/node/services/FeatureFlagService.js +0 -156
  114. package/dist/node/services/FileService.js +0 -182
  115. package/dist/node/services/IntegrationService.js +0 -519
  116. package/dist/node/services/MetricsService.js +0 -43
  117. package/dist/node/services/PaymentService.js +0 -252
  118. package/dist/node/services/PlanService.js +0 -407
  119. package/dist/node/services/ProjectService.js +0 -1188
  120. package/dist/node/services/PullRequestService.js +0 -484
  121. package/dist/node/services/ScreenshotService.js +0 -285
  122. package/dist/node/services/SubscriptionService.js +0 -377
  123. package/dist/node/services/TrackingService.js +0 -632
  124. package/dist/node/services/WaitlistService.js +0 -129
  125. package/dist/node/state/RootStateManager.js +0 -36
  126. package/dist/node/state/rootEventBus.js +0 -55
  127. package/dist/node/utils/CollabClient.js +0 -194
  128. package/dist/node/utils/TokenManager.js +0 -403
  129. package/dist/node/utils/changePreprocessor.js +0 -180
  130. package/dist/node/utils/jsonDiff.js +0 -116
  131. package/dist/node/utils/ordering.js +0 -290
  132. package/src/services/AdminService.js +0 -374
  133. package/src/services/BranchService.js +0 -536
  134. package/src/services/CollabService.js +0 -900
  135. package/src/services/DnsService.js +0 -366
  136. package/src/services/FeatureFlagService.js +0 -174
  137. package/src/services/FileService.js +0 -213
  138. package/src/services/IntegrationService.js +0 -548
  139. package/src/services/MetricsService.js +0 -40
  140. package/src/services/PaymentService.js +0 -287
  141. package/src/services/PlanService.js +0 -468
  142. package/src/services/ProjectService.js +0 -1366
  143. package/src/services/PullRequestService.js +0 -537
  144. package/src/services/ScreenshotService.js +0 -258
  145. package/src/services/SubscriptionService.js +0 -425
  146. package/src/services/TrackingService.js +0 -853
  147. package/src/services/WaitlistService.js +0 -130
  148. package/src/services/tests/BranchService/createBranch.test.js +0 -153
  149. package/src/services/tests/BranchService/deleteBranch.test.js +0 -173
  150. package/src/services/tests/BranchService/getBranchChanges.test.js +0 -146
  151. package/src/services/tests/BranchService/listBranches.test.js +0 -87
  152. package/src/services/tests/BranchService/mergeBranch.test.js +0 -210
  153. package/src/services/tests/BranchService/publishVersion.test.js +0 -183
  154. package/src/services/tests/BranchService/renameBranch.test.js +0 -240
  155. package/src/services/tests/BranchService/resetBranch.test.js +0 -152
  156. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +0 -67
  157. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +0 -75
  158. package/src/services/tests/FileService/createFileFormData.test.js +0 -74
  159. package/src/services/tests/FileService/getFileUrl.test.js +0 -69
  160. package/src/services/tests/FileService/updateProjectIcon.test.js +0 -109
  161. package/src/services/tests/FileService/uploadDocument.test.js +0 -36
  162. package/src/services/tests/FileService/uploadFile.test.js +0 -78
  163. package/src/services/tests/FileService/uploadFileWithValidation.test.js +0 -114
  164. package/src/services/tests/FileService/uploadImage.test.js +0 -36
  165. package/src/services/tests/FileService/uploadMultipleFiles.test.js +0 -111
  166. package/src/services/tests/FileService/validateFile.test.js +0 -63
  167. package/src/services/tests/PlanService/createPlan.test.js +0 -104
  168. package/src/services/tests/PlanService/createPlanWithValidation.test.js +0 -523
  169. package/src/services/tests/PlanService/deletePlan.test.js +0 -92
  170. package/src/services/tests/PlanService/getActivePlans.test.js +0 -123
  171. package/src/services/tests/PlanService/getAdminPlans.test.js +0 -84
  172. package/src/services/tests/PlanService/getPlan.test.js +0 -50
  173. package/src/services/tests/PlanService/getPlanByKey.test.js +0 -109
  174. package/src/services/tests/PlanService/getPlanWithValidation.test.js +0 -85
  175. package/src/services/tests/PlanService/getPlans.test.js +0 -53
  176. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +0 -109
  177. package/src/services/tests/PlanService/getPlansWithValidation.test.js +0 -48
  178. package/src/services/tests/PlanService/initializePlans.test.js +0 -75
  179. package/src/services/tests/PlanService/updatePlan.test.js +0 -111
  180. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +0 -556
  181. package/src/state/RootStateManager.js +0 -76
  182. package/src/state/rootEventBus.js +0 -67
  183. package/src/utils/CollabClient.js +0 -248
  184. package/src/utils/TokenManager.js +0 -479
  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
- };