@symbo.ls/sdk 3.2.3 → 3.2.7

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 (183) hide show
  1. package/README.md +141 -0
  2. package/dist/cjs/config/environment.js +94 -10
  3. package/dist/cjs/index.js +152 -12
  4. package/dist/cjs/services/AdminService.js +351 -0
  5. package/dist/cjs/services/AuthService.js +738 -305
  6. package/dist/cjs/services/BaseService.js +158 -6
  7. package/dist/cjs/services/BranchService.js +484 -0
  8. package/dist/cjs/services/CollabService.js +439 -116
  9. package/dist/cjs/services/DnsService.js +340 -0
  10. package/dist/cjs/services/FeatureFlagService.js +175 -0
  11. package/dist/cjs/services/FileService.js +201 -0
  12. package/dist/cjs/services/IntegrationService.js +538 -0
  13. package/dist/cjs/services/MetricsService.js +62 -0
  14. package/dist/cjs/services/PaymentService.js +271 -0
  15. package/dist/cjs/services/PlanService.js +426 -0
  16. package/dist/cjs/services/ProjectService.js +1207 -0
  17. package/dist/cjs/services/PullRequestService.js +503 -0
  18. package/dist/cjs/services/ScreenshotService.js +304 -0
  19. package/dist/cjs/services/SubscriptionService.js +396 -0
  20. package/dist/cjs/services/TrackingService.js +661 -0
  21. package/dist/cjs/services/WaitlistService.js +148 -0
  22. package/dist/cjs/services/index.js +60 -4
  23. package/dist/cjs/state/RootStateManager.js +2 -23
  24. package/dist/cjs/state/rootEventBus.js +9 -0
  25. package/dist/cjs/utils/CollabClient.js +78 -12
  26. package/dist/cjs/utils/TokenManager.js +16 -3
  27. package/dist/cjs/utils/changePreprocessor.js +199 -0
  28. package/dist/cjs/utils/jsonDiff.js +46 -4
  29. package/dist/cjs/utils/ordering.js +309 -0
  30. package/dist/cjs/utils/services.js +285 -128
  31. package/dist/cjs/utils/validation.js +0 -3
  32. package/dist/esm/config/environment.js +94 -10
  33. package/dist/esm/index.js +47862 -18248
  34. package/dist/esm/services/AdminService.js +1132 -0
  35. package/dist/esm/services/AuthService.js +1493 -386
  36. package/dist/esm/services/BaseService.js +757 -6
  37. package/dist/esm/services/BranchService.js +1265 -0
  38. package/dist/esm/services/CollabService.js +24956 -16089
  39. package/dist/esm/services/DnsService.js +1121 -0
  40. package/dist/esm/services/FeatureFlagService.js +956 -0
  41. package/dist/esm/services/FileService.js +982 -0
  42. package/dist/esm/services/IntegrationService.js +1319 -0
  43. package/dist/esm/services/MetricsService.js +843 -0
  44. package/dist/esm/services/PaymentService.js +1052 -0
  45. package/dist/esm/services/PlanService.js +1207 -0
  46. package/dist/esm/services/ProjectService.js +2526 -0
  47. package/dist/esm/services/PullRequestService.js +1284 -0
  48. package/dist/esm/services/ScreenshotService.js +1085 -0
  49. package/dist/esm/services/SubscriptionService.js +1177 -0
  50. package/dist/esm/services/TrackingService.js +18454 -0
  51. package/dist/esm/services/WaitlistService.js +929 -0
  52. package/dist/esm/services/index.js +47373 -18027
  53. package/dist/esm/state/RootStateManager.js +11 -23
  54. package/dist/esm/state/rootEventBus.js +9 -0
  55. package/dist/esm/utils/CollabClient.js +17526 -16120
  56. package/dist/esm/utils/TokenManager.js +16 -3
  57. package/dist/esm/utils/changePreprocessor.js +542 -0
  58. package/dist/esm/utils/jsonDiff.js +958 -43
  59. package/dist/esm/utils/ordering.js +291 -0
  60. package/dist/esm/utils/services.js +285 -128
  61. package/dist/esm/utils/validation.js +116 -50
  62. package/dist/node/config/environment.js +94 -10
  63. package/dist/node/index.js +183 -16
  64. package/dist/node/services/AdminService.js +332 -0
  65. package/dist/node/services/AuthService.js +742 -310
  66. package/dist/node/services/BaseService.js +148 -6
  67. package/dist/node/services/BranchService.js +465 -0
  68. package/dist/node/services/CollabService.js +439 -116
  69. package/dist/node/services/DnsService.js +321 -0
  70. package/dist/node/services/FeatureFlagService.js +156 -0
  71. package/dist/node/services/FileService.js +182 -0
  72. package/dist/node/services/IntegrationService.js +519 -0
  73. package/dist/node/services/MetricsService.js +43 -0
  74. package/dist/node/services/PaymentService.js +252 -0
  75. package/dist/node/services/PlanService.js +407 -0
  76. package/dist/node/services/ProjectService.js +1188 -0
  77. package/dist/node/services/PullRequestService.js +484 -0
  78. package/dist/node/services/ScreenshotService.js +285 -0
  79. package/dist/node/services/SubscriptionService.js +377 -0
  80. package/dist/node/services/TrackingService.js +632 -0
  81. package/dist/node/services/WaitlistService.js +129 -0
  82. package/dist/node/services/index.js +60 -4
  83. package/dist/node/state/RootStateManager.js +2 -23
  84. package/dist/node/state/rootEventBus.js +9 -0
  85. package/dist/node/utils/CollabClient.js +77 -11
  86. package/dist/node/utils/TokenManager.js +16 -3
  87. package/dist/node/utils/changePreprocessor.js +180 -0
  88. package/dist/node/utils/jsonDiff.js +46 -4
  89. package/dist/node/utils/ordering.js +290 -0
  90. package/dist/node/utils/services.js +285 -128
  91. package/dist/node/utils/validation.js +0 -3
  92. package/package.json +30 -18
  93. package/src/config/environment.js +95 -10
  94. package/src/index.js +190 -23
  95. package/src/services/AdminService.js +374 -0
  96. package/src/services/AuthService.js +874 -328
  97. package/src/services/BaseService.js +166 -6
  98. package/src/services/BranchService.js +536 -0
  99. package/src/services/CollabService.js +557 -148
  100. package/src/services/DnsService.js +366 -0
  101. package/src/services/FeatureFlagService.js +174 -0
  102. package/src/services/FileService.js +213 -0
  103. package/src/services/IntegrationService.js +548 -0
  104. package/src/services/MetricsService.js +40 -0
  105. package/src/services/PaymentService.js +287 -0
  106. package/src/services/PlanService.js +468 -0
  107. package/src/services/ProjectService.js +1366 -0
  108. package/src/services/PullRequestService.js +537 -0
  109. package/src/services/ScreenshotService.js +258 -0
  110. package/src/services/SubscriptionService.js +425 -0
  111. package/src/services/TrackingService.js +853 -0
  112. package/src/services/WaitlistService.js +130 -0
  113. package/src/services/index.js +79 -5
  114. package/src/services/tests/BranchService/createBranch.test.js +153 -0
  115. package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
  116. package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
  117. package/src/services/tests/BranchService/listBranches.test.js +87 -0
  118. package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
  119. package/src/services/tests/BranchService/publishVersion.test.js +183 -0
  120. package/src/services/tests/BranchService/renameBranch.test.js +240 -0
  121. package/src/services/tests/BranchService/resetBranch.test.js +152 -0
  122. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
  123. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
  124. package/src/services/tests/FileService/createFileFormData.test.js +74 -0
  125. package/src/services/tests/FileService/getFileUrl.test.js +69 -0
  126. package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
  127. package/src/services/tests/FileService/uploadDocument.test.js +36 -0
  128. package/src/services/tests/FileService/uploadFile.test.js +78 -0
  129. package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
  130. package/src/services/tests/FileService/uploadImage.test.js +36 -0
  131. package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
  132. package/src/services/tests/FileService/validateFile.test.js +63 -0
  133. package/src/services/tests/PlanService/createPlan.test.js +104 -0
  134. package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
  135. package/src/services/tests/PlanService/deletePlan.test.js +92 -0
  136. package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
  137. package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
  138. package/src/services/tests/PlanService/getPlan.test.js +50 -0
  139. package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
  140. package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
  141. package/src/services/tests/PlanService/getPlans.test.js +53 -0
  142. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
  143. package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
  144. package/src/services/tests/PlanService/initializePlans.test.js +75 -0
  145. package/src/services/tests/PlanService/updatePlan.test.js +111 -0
  146. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
  147. package/src/state/RootStateManager.js +37 -32
  148. package/src/state/rootEventBus.js +19 -0
  149. package/src/utils/CollabClient.js +99 -12
  150. package/src/utils/TokenManager.js +20 -3
  151. package/src/utils/changePreprocessor.js +239 -0
  152. package/src/utils/jsonDiff.js +40 -5
  153. package/src/utils/ordering.js +271 -0
  154. package/src/utils/services.js +306 -139
  155. package/src/utils/validation.js +0 -3
  156. package/dist/cjs/services/AIService.js +0 -155
  157. package/dist/cjs/services/BasedService.js +0 -1185
  158. package/dist/cjs/services/CoreService.js +0 -2295
  159. package/dist/cjs/services/SocketService.js +0 -309
  160. package/dist/cjs/services/SymstoryService.js +0 -571
  161. package/dist/cjs/utils/basedQuerys.js +0 -181
  162. package/dist/cjs/utils/symstoryClient.js +0 -259
  163. package/dist/esm/services/AIService.js +0 -185
  164. package/dist/esm/services/BasedService.js +0 -5262
  165. package/dist/esm/services/CoreService.js +0 -2827
  166. package/dist/esm/services/SocketService.js +0 -456
  167. package/dist/esm/services/SymstoryService.js +0 -7025
  168. package/dist/esm/utils/basedQuerys.js +0 -163
  169. package/dist/esm/utils/symstoryClient.js +0 -354
  170. package/dist/node/services/AIService.js +0 -136
  171. package/dist/node/services/BasedService.js +0 -1156
  172. package/dist/node/services/CoreService.js +0 -2266
  173. package/dist/node/services/SocketService.js +0 -280
  174. package/dist/node/services/SymstoryService.js +0 -542
  175. package/dist/node/utils/basedQuerys.js +0 -162
  176. package/dist/node/utils/symstoryClient.js +0 -230
  177. package/src/services/AIService.js +0 -150
  178. package/src/services/BasedService.js +0 -1302
  179. package/src/services/CoreService.js +0 -2548
  180. package/src/services/SocketService.js +0 -336
  181. package/src/services/SymstoryService.js +0 -649
  182. package/src/utils/basedQuerys.js +0 -164
  183. package/src/utils/symstoryClient.js +0 -252
@@ -0,0 +1,374 @@
1
+ import { BaseService } from './BaseService.js'
2
+
3
+ export class AdminService extends BaseService {
4
+ // ==================== ADMIN METHODS ====================
5
+
6
+ /**
7
+ * Get admin users list with comprehensive filtering and search capabilities
8
+ * Requires admin or super_admin global role
9
+ */
10
+ async getAdminUsers (params = {}) {
11
+ this._requireReady('getAdminUsers')
12
+
13
+ const {
14
+ emails,
15
+ ids,
16
+ query,
17
+ status,
18
+ page = 1,
19
+ limit = 50,
20
+ sort = { field: 'createdAt', order: 'desc' }
21
+ } = params
22
+
23
+ const queryParams = new URLSearchParams()
24
+
25
+ // Add query parameters
26
+ if (emails) {
27
+ queryParams.append('emails', emails)
28
+ }
29
+ if (ids) {
30
+ queryParams.append('ids', ids)
31
+ }
32
+ if (query) {
33
+ queryParams.append('query', query)
34
+ }
35
+ if (status) {
36
+ queryParams.append('status', status)
37
+ }
38
+ if (page) {
39
+ queryParams.append('page', page.toString())
40
+ }
41
+ if (limit) {
42
+ queryParams.append('limit', limit.toString())
43
+ }
44
+ if (sort && sort.field) {
45
+ queryParams.append('sort[field]', sort.field)
46
+ queryParams.append('sort[order]', sort.order || 'desc')
47
+ }
48
+
49
+ const queryString = queryParams.toString()
50
+ const url = `/users/admin/users${queryString ? `?${queryString}` : ''}`
51
+
52
+ try {
53
+ const response = await this._request(url, {
54
+ method: 'GET',
55
+ methodName: 'getAdminUsers'
56
+ })
57
+ if (response.success) {
58
+ return response.data
59
+ }
60
+ throw new Error(response.message)
61
+ } catch (error) {
62
+ throw new Error(`Failed to get admin users: ${error.message}`, { cause: error })
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Assign projects to a specific user
68
+ * Requires admin or super_admin global role
69
+ */
70
+ async assignProjectsToUser (userId, options = {}) {
71
+ this._requireReady('assignProjectsToUser')
72
+
73
+ if (!userId) {
74
+ throw new Error('User ID is required')
75
+ }
76
+
77
+ const { projectIds, role = 'guest' } = options
78
+
79
+ const requestBody = {
80
+ userId,
81
+ role
82
+ }
83
+
84
+ // Only include projectIds if provided (otherwise assigns all projects)
85
+ if (projectIds && Array.isArray(projectIds)) {
86
+ requestBody.projectIds = projectIds
87
+ }
88
+
89
+ try {
90
+ const response = await this._request('/assign-projects', {
91
+ method: 'POST',
92
+ body: JSON.stringify(requestBody),
93
+ methodName: 'assignProjectsToUser'
94
+ })
95
+ if (response.success) {
96
+ return response.data
97
+ }
98
+ throw new Error(response.message)
99
+ } catch (error) {
100
+ throw new Error(`Failed to assign projects to user: ${error.message}`, { cause: error })
101
+ }
102
+ }
103
+
104
+ /**
105
+ * Update user information (admin only)
106
+ */
107
+ async updateUser (userId, userData) {
108
+ this._requireReady('updateUser')
109
+ if (!userId) {
110
+ throw new Error('User ID is required')
111
+ }
112
+ if (
113
+ !userData ||
114
+ typeof userData !== 'object' ||
115
+ Object.keys(userData).length === 0
116
+ ) {
117
+ throw new Error('userData must be a non-empty object')
118
+ }
119
+
120
+ try {
121
+ const response = await this._request(`/users/${userId}`, {
122
+ method: 'PATCH',
123
+ body: JSON.stringify(userData),
124
+ methodName: 'updateUser'
125
+ })
126
+ if (response.success) {
127
+ return response.data
128
+ }
129
+ throw new Error(response.message)
130
+ } catch (error) {
131
+ // Surface duplicate username conflict nicely
132
+ if (error.message?.includes('Duplicate')) {
133
+ throw new Error('Username already exists')
134
+ }
135
+ throw new Error(`Failed to update user: ${error.message}`, { cause: error })
136
+ }
137
+ }
138
+
139
+ // ==================== ADMIN HELPER METHODS ====================
140
+
141
+ /**
142
+ * Helper method for admin users search
143
+ */
144
+ async searchAdminUsers (searchQuery, options = {}) {
145
+ return await this.getAdminUsers({
146
+ query: searchQuery,
147
+ ...options
148
+ })
149
+ }
150
+
151
+ /**
152
+ * Helper method to get admin users by email list
153
+ */
154
+ async getAdminUsersByEmails (emails, options = {}) {
155
+ const emailList = Array.isArray(emails) ? emails.join(',') : emails
156
+ return await this.getAdminUsers({
157
+ emails: emailList,
158
+ ...options
159
+ })
160
+ }
161
+
162
+ /**
163
+ * Helper method to get admin users by ID list
164
+ */
165
+ async getAdminUsersByIds (ids, options = {}) {
166
+ const idList = Array.isArray(ids) ? ids.join(',') : ids
167
+ return await this.getAdminUsers({
168
+ ids: idList,
169
+ ...options
170
+ })
171
+ }
172
+
173
+ /**
174
+ * Helper method to assign specific projects to a user with a specific role
175
+ */
176
+ async assignSpecificProjectsToUser (userId, projectIds, role = 'guest') {
177
+ if (!Array.isArray(projectIds) || projectIds.length === 0) {
178
+ throw new Error('Project IDs must be a non-empty array')
179
+ }
180
+
181
+ return await this.assignProjectsToUser(userId, {
182
+ projectIds,
183
+ role
184
+ })
185
+ }
186
+
187
+ /**
188
+ * Helper method to assign all projects to a user with a specific role
189
+ */
190
+ async assignAllProjectsToUser (userId, role = 'guest') {
191
+ return await this.assignProjectsToUser(userId, {
192
+ role
193
+ })
194
+ }
195
+
196
+ /**
197
+ * Helper method to validate user data for updates
198
+ */
199
+ validateUserData (userData) {
200
+ const errors = []
201
+
202
+ if (!userData || typeof userData !== 'object') {
203
+ errors.push('User data must be an object')
204
+ return { isValid: false, errors }
205
+ }
206
+
207
+ // Validate email if provided
208
+ if (userData.email && typeof userData.email !== 'string') {
209
+ errors.push('Email must be a string')
210
+ } else if (userData.email && !this._isValidEmail(userData.email)) {
211
+ errors.push('Email must be a valid email address')
212
+ }
213
+
214
+ // Validate username if provided
215
+ if (userData.username && typeof userData.username !== 'string') {
216
+ errors.push('Username must be a string')
217
+ } else if (userData.username && userData.username.length < 3) {
218
+ errors.push('Username must be at least 3 characters long')
219
+ }
220
+
221
+ // Validate role if provided
222
+ if (userData.role && !['admin', 'user', 'guest'].includes(userData.role)) {
223
+ errors.push('Role must be one of: admin, user, guest')
224
+ }
225
+
226
+ // Validate status if provided
227
+ if (userData.status && !['active', 'inactive', 'suspended'].includes(userData.status)) {
228
+ errors.push('Status must be one of: active, inactive, suspended')
229
+ }
230
+
231
+ return {
232
+ isValid: errors.length === 0,
233
+ errors
234
+ }
235
+ }
236
+
237
+ /**
238
+ * Helper method to update user with validation
239
+ */
240
+ async updateUserWithValidation (userId, userData) {
241
+ const validation = this.validateUserData(userData)
242
+ if (!validation.isValid) {
243
+ throw new Error(`Validation failed: ${validation.errors.join(', ')}`)
244
+ }
245
+
246
+ return await this.updateUser(userId, userData)
247
+ }
248
+
249
+ /**
250
+ * Helper method to get user statistics
251
+ */
252
+ async getUserStats () {
253
+ try {
254
+ const users = await this.getAdminUsers({ limit: 1000 })
255
+
256
+ const stats = {
257
+ total: users.length,
258
+ active: 0,
259
+ inactive: 0,
260
+ suspended: 0,
261
+ admins: 0,
262
+ users: 0,
263
+ guests: 0
264
+ }
265
+
266
+ users.forEach(user => {
267
+ if (user.status === 'active') {stats.active++}
268
+ if (user.status === 'inactive') {stats.inactive++}
269
+ if (user.status === 'suspended') {stats.suspended++}
270
+ if (user.role === 'admin') {stats.admins++}
271
+ if (user.role === 'user') {stats.users++}
272
+ if (user.role === 'guest') {stats.guests++}
273
+ })
274
+
275
+ return stats
276
+ } catch (error) {
277
+ throw new Error(`Failed to get user stats: ${error.message}`, { cause: error })
278
+ }
279
+ }
280
+
281
+ /**
282
+ * Helper method to bulk update users
283
+ */
284
+ async bulkUpdateUsers (userUpdates) {
285
+ if (!Array.isArray(userUpdates) || userUpdates.length === 0) {
286
+ throw new Error('User updates must be a non-empty array')
287
+ }
288
+
289
+ const updatePromises = userUpdates.map(async update => {
290
+ try {
291
+ const result = await this.updateUser(update.userId, update.userData)
292
+ return {
293
+ userId: update.userId,
294
+ success: true,
295
+ data: result
296
+ }
297
+ } catch (error) {
298
+ return {
299
+ userId: update.userId,
300
+ success: false,
301
+ error: error.message
302
+ }
303
+ }
304
+ })
305
+
306
+ const results = await Promise.all(updatePromises)
307
+
308
+ return {
309
+ total: results.length,
310
+ successful: results.filter(r => r.success).length,
311
+ failed: results.filter(r => !r.success).length,
312
+ results
313
+ }
314
+ }
315
+
316
+ /**
317
+ * Helper method to get users by role
318
+ */
319
+ async getUsersByRole (role, options = {}) {
320
+ const users = await this.getAdminUsers(options)
321
+ return users.filter(user => user.role === role)
322
+ }
323
+
324
+ /**
325
+ * Helper method to get users by status
326
+ */
327
+ async getUsersByStatus (status, options = {}) {
328
+ const users = await this.getAdminUsers(options)
329
+ return users.filter(user => user.status === status)
330
+ }
331
+
332
+ /**
333
+ * Helper method to activate a user
334
+ */
335
+ async activateUser (userId) {
336
+ return await this.updateUser(userId, { status: 'active' })
337
+ }
338
+
339
+ /**
340
+ * Helper method to deactivate a user
341
+ */
342
+ async deactivateUser (userId) {
343
+ return await this.updateUser(userId, { status: 'inactive' })
344
+ }
345
+
346
+ /**
347
+ * Helper method to suspend a user
348
+ */
349
+ async suspendUser (userId) {
350
+ return await this.updateUser(userId, { status: 'suspended' })
351
+ }
352
+
353
+ /**
354
+ * Helper method to promote user to admin
355
+ */
356
+ async promoteToAdmin (userId) {
357
+ return await this.updateUser(userId, { role: 'admin' })
358
+ }
359
+
360
+ /**
361
+ * Helper method to demote user from admin
362
+ */
363
+ async demoteFromAdmin (userId) {
364
+ return await this.updateUser(userId, { role: 'user' })
365
+ }
366
+
367
+ /**
368
+ * Private helper to validate email format
369
+ */
370
+ _isValidEmail (email) {
371
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/u
372
+ return emailRegex.test(email)
373
+ }
374
+ }