@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.
- package/README.md +141 -0
- package/dist/cjs/config/environment.js +94 -10
- package/dist/cjs/index.js +152 -12
- package/dist/cjs/services/AdminService.js +351 -0
- package/dist/cjs/services/AuthService.js +738 -305
- package/dist/cjs/services/BaseService.js +158 -6
- package/dist/cjs/services/BranchService.js +484 -0
- package/dist/cjs/services/CollabService.js +439 -116
- package/dist/cjs/services/DnsService.js +340 -0
- package/dist/cjs/services/FeatureFlagService.js +175 -0
- package/dist/cjs/services/FileService.js +201 -0
- package/dist/cjs/services/IntegrationService.js +538 -0
- package/dist/cjs/services/MetricsService.js +62 -0
- package/dist/cjs/services/PaymentService.js +271 -0
- package/dist/cjs/services/PlanService.js +426 -0
- package/dist/cjs/services/ProjectService.js +1207 -0
- package/dist/cjs/services/PullRequestService.js +503 -0
- package/dist/cjs/services/ScreenshotService.js +304 -0
- package/dist/cjs/services/SubscriptionService.js +396 -0
- package/dist/cjs/services/TrackingService.js +661 -0
- package/dist/cjs/services/WaitlistService.js +148 -0
- package/dist/cjs/services/index.js +60 -4
- package/dist/cjs/state/RootStateManager.js +2 -23
- package/dist/cjs/state/rootEventBus.js +9 -0
- package/dist/cjs/utils/CollabClient.js +78 -12
- package/dist/cjs/utils/TokenManager.js +16 -3
- package/dist/cjs/utils/changePreprocessor.js +199 -0
- package/dist/cjs/utils/jsonDiff.js +46 -4
- package/dist/cjs/utils/ordering.js +309 -0
- package/dist/cjs/utils/services.js +285 -128
- package/dist/cjs/utils/validation.js +0 -3
- package/dist/esm/config/environment.js +94 -10
- package/dist/esm/index.js +47862 -18248
- package/dist/esm/services/AdminService.js +1132 -0
- package/dist/esm/services/AuthService.js +1493 -386
- package/dist/esm/services/BaseService.js +757 -6
- package/dist/esm/services/BranchService.js +1265 -0
- package/dist/esm/services/CollabService.js +24956 -16089
- package/dist/esm/services/DnsService.js +1121 -0
- package/dist/esm/services/FeatureFlagService.js +956 -0
- package/dist/esm/services/FileService.js +982 -0
- package/dist/esm/services/IntegrationService.js +1319 -0
- package/dist/esm/services/MetricsService.js +843 -0
- package/dist/esm/services/PaymentService.js +1052 -0
- package/dist/esm/services/PlanService.js +1207 -0
- package/dist/esm/services/ProjectService.js +2526 -0
- package/dist/esm/services/PullRequestService.js +1284 -0
- package/dist/esm/services/ScreenshotService.js +1085 -0
- package/dist/esm/services/SubscriptionService.js +1177 -0
- package/dist/esm/services/TrackingService.js +18454 -0
- package/dist/esm/services/WaitlistService.js +929 -0
- package/dist/esm/services/index.js +47373 -18027
- package/dist/esm/state/RootStateManager.js +11 -23
- package/dist/esm/state/rootEventBus.js +9 -0
- package/dist/esm/utils/CollabClient.js +17526 -16120
- package/dist/esm/utils/TokenManager.js +16 -3
- package/dist/esm/utils/changePreprocessor.js +542 -0
- package/dist/esm/utils/jsonDiff.js +958 -43
- package/dist/esm/utils/ordering.js +291 -0
- package/dist/esm/utils/services.js +285 -128
- package/dist/esm/utils/validation.js +116 -50
- package/dist/node/config/environment.js +94 -10
- package/dist/node/index.js +183 -16
- package/dist/node/services/AdminService.js +332 -0
- package/dist/node/services/AuthService.js +742 -310
- package/dist/node/services/BaseService.js +148 -6
- package/dist/node/services/BranchService.js +465 -0
- package/dist/node/services/CollabService.js +439 -116
- package/dist/node/services/DnsService.js +321 -0
- package/dist/node/services/FeatureFlagService.js +156 -0
- package/dist/node/services/FileService.js +182 -0
- package/dist/node/services/IntegrationService.js +519 -0
- package/dist/node/services/MetricsService.js +43 -0
- package/dist/node/services/PaymentService.js +252 -0
- package/dist/node/services/PlanService.js +407 -0
- package/dist/node/services/ProjectService.js +1188 -0
- package/dist/node/services/PullRequestService.js +484 -0
- package/dist/node/services/ScreenshotService.js +285 -0
- package/dist/node/services/SubscriptionService.js +377 -0
- package/dist/node/services/TrackingService.js +632 -0
- package/dist/node/services/WaitlistService.js +129 -0
- package/dist/node/services/index.js +60 -4
- package/dist/node/state/RootStateManager.js +2 -23
- package/dist/node/state/rootEventBus.js +9 -0
- package/dist/node/utils/CollabClient.js +77 -11
- package/dist/node/utils/TokenManager.js +16 -3
- package/dist/node/utils/changePreprocessor.js +180 -0
- package/dist/node/utils/jsonDiff.js +46 -4
- package/dist/node/utils/ordering.js +290 -0
- package/dist/node/utils/services.js +285 -128
- package/dist/node/utils/validation.js +0 -3
- package/package.json +30 -18
- package/src/config/environment.js +95 -10
- package/src/index.js +190 -23
- package/src/services/AdminService.js +374 -0
- package/src/services/AuthService.js +874 -328
- package/src/services/BaseService.js +166 -6
- package/src/services/BranchService.js +536 -0
- package/src/services/CollabService.js +557 -148
- package/src/services/DnsService.js +366 -0
- package/src/services/FeatureFlagService.js +174 -0
- package/src/services/FileService.js +213 -0
- package/src/services/IntegrationService.js +548 -0
- package/src/services/MetricsService.js +40 -0
- package/src/services/PaymentService.js +287 -0
- package/src/services/PlanService.js +468 -0
- package/src/services/ProjectService.js +1366 -0
- package/src/services/PullRequestService.js +537 -0
- package/src/services/ScreenshotService.js +258 -0
- package/src/services/SubscriptionService.js +425 -0
- package/src/services/TrackingService.js +853 -0
- package/src/services/WaitlistService.js +130 -0
- package/src/services/index.js +79 -5
- package/src/services/tests/BranchService/createBranch.test.js +153 -0
- package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
- package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
- package/src/services/tests/BranchService/listBranches.test.js +87 -0
- package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
- package/src/services/tests/BranchService/publishVersion.test.js +183 -0
- package/src/services/tests/BranchService/renameBranch.test.js +240 -0
- package/src/services/tests/BranchService/resetBranch.test.js +152 -0
- package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
- package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
- package/src/services/tests/FileService/createFileFormData.test.js +74 -0
- package/src/services/tests/FileService/getFileUrl.test.js +69 -0
- package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
- package/src/services/tests/FileService/uploadDocument.test.js +36 -0
- package/src/services/tests/FileService/uploadFile.test.js +78 -0
- package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
- package/src/services/tests/FileService/uploadImage.test.js +36 -0
- package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
- package/src/services/tests/FileService/validateFile.test.js +63 -0
- package/src/services/tests/PlanService/createPlan.test.js +104 -0
- package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
- package/src/services/tests/PlanService/deletePlan.test.js +92 -0
- package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
- package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
- package/src/services/tests/PlanService/getPlan.test.js +50 -0
- package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
- package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
- package/src/services/tests/PlanService/getPlans.test.js +53 -0
- package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
- package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
- package/src/services/tests/PlanService/initializePlans.test.js +75 -0
- package/src/services/tests/PlanService/updatePlan.test.js +111 -0
- package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
- package/src/state/RootStateManager.js +37 -32
- package/src/state/rootEventBus.js +19 -0
- package/src/utils/CollabClient.js +99 -12
- package/src/utils/TokenManager.js +20 -3
- package/src/utils/changePreprocessor.js +239 -0
- package/src/utils/jsonDiff.js +40 -5
- package/src/utils/ordering.js +271 -0
- package/src/utils/services.js +306 -139
- package/src/utils/validation.js +0 -3
- package/dist/cjs/services/AIService.js +0 -155
- package/dist/cjs/services/BasedService.js +0 -1185
- package/dist/cjs/services/CoreService.js +0 -2295
- package/dist/cjs/services/SocketService.js +0 -309
- package/dist/cjs/services/SymstoryService.js +0 -571
- package/dist/cjs/utils/basedQuerys.js +0 -181
- package/dist/cjs/utils/symstoryClient.js +0 -259
- package/dist/esm/services/AIService.js +0 -185
- package/dist/esm/services/BasedService.js +0 -5262
- package/dist/esm/services/CoreService.js +0 -2827
- package/dist/esm/services/SocketService.js +0 -456
- package/dist/esm/services/SymstoryService.js +0 -7025
- package/dist/esm/utils/basedQuerys.js +0 -163
- package/dist/esm/utils/symstoryClient.js +0 -354
- package/dist/node/services/AIService.js +0 -136
- package/dist/node/services/BasedService.js +0 -1156
- package/dist/node/services/CoreService.js +0 -2266
- package/dist/node/services/SocketService.js +0 -280
- package/dist/node/services/SymstoryService.js +0 -542
- package/dist/node/utils/basedQuerys.js +0 -162
- package/dist/node/utils/symstoryClient.js +0 -230
- package/src/services/AIService.js +0 -150
- package/src/services/BasedService.js +0 -1302
- package/src/services/CoreService.js +0 -2548
- package/src/services/SocketService.js +0 -336
- package/src/services/SymstoryService.js +0 -649
- package/src/utils/basedQuerys.js +0 -164
- package/src/utils/symstoryClient.js +0 -252
|
@@ -0,0 +1,1366 @@
|
|
|
1
|
+
import { BaseService } from './BaseService.js'
|
|
2
|
+
import { computeOrdersForTuples } from '../utils/ordering.js'
|
|
3
|
+
import { preprocessChanges } from '../utils/changePreprocessor.js'
|
|
4
|
+
import { deepStringifyFunctions } from '@domql/utils'
|
|
5
|
+
|
|
6
|
+
export class ProjectService extends BaseService {
|
|
7
|
+
// ==================== PROJECT METHODS ====================
|
|
8
|
+
|
|
9
|
+
async createProject (projectData) {
|
|
10
|
+
this._requireReady('createProject')
|
|
11
|
+
try {
|
|
12
|
+
const response = await this._request('/projects', {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
body: JSON.stringify(projectData),
|
|
15
|
+
methodName: 'createProject'
|
|
16
|
+
})
|
|
17
|
+
if (response.success) {
|
|
18
|
+
return response.data
|
|
19
|
+
}
|
|
20
|
+
throw new Error(response.message)
|
|
21
|
+
} catch (error) {
|
|
22
|
+
throw new Error(`Failed to create project: ${error.message}`, { cause: error })
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async getProjects (params = {}) {
|
|
27
|
+
this._requireReady('getProjects')
|
|
28
|
+
try {
|
|
29
|
+
const queryParams = new URLSearchParams()
|
|
30
|
+
|
|
31
|
+
// Add query parameters
|
|
32
|
+
Object.keys(params).forEach(key => {
|
|
33
|
+
if (params[key] != null) {
|
|
34
|
+
queryParams.append(key, params[key])
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const queryString = queryParams.toString()
|
|
39
|
+
const url = `/projects${queryString ? `?${queryString}` : ''}`
|
|
40
|
+
|
|
41
|
+
const response = await this._request(url, {
|
|
42
|
+
method: 'GET',
|
|
43
|
+
methodName: 'getProjects'
|
|
44
|
+
})
|
|
45
|
+
if (response.success) {
|
|
46
|
+
return response
|
|
47
|
+
}
|
|
48
|
+
throw new Error(response.message)
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw new Error(`Failed to get projects: ${error.message}`, { cause: error })
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Alias for getProjects for consistency with API naming
|
|
56
|
+
*/
|
|
57
|
+
async listProjects (params = {}) {
|
|
58
|
+
return await this.getProjects(params)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* List only public projects (no authentication required)
|
|
63
|
+
*/
|
|
64
|
+
async listPublicProjects (params = {}) {
|
|
65
|
+
try {
|
|
66
|
+
const queryParams = new URLSearchParams()
|
|
67
|
+
|
|
68
|
+
// Add query parameters
|
|
69
|
+
Object.keys(params).forEach(key => {
|
|
70
|
+
if (params[key] != null) {
|
|
71
|
+
queryParams.append(key, params[key])
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
const queryString = queryParams.toString()
|
|
76
|
+
const url = `/projects/public${queryString ? `?${queryString}` : ''}`
|
|
77
|
+
|
|
78
|
+
const response = await this._request(url, {
|
|
79
|
+
method: 'GET',
|
|
80
|
+
methodName: 'listPublicProjects'
|
|
81
|
+
})
|
|
82
|
+
if (response.success) {
|
|
83
|
+
return response.data
|
|
84
|
+
}
|
|
85
|
+
throw new Error(response.message)
|
|
86
|
+
} catch (error) {
|
|
87
|
+
throw new Error(`Failed to list public projects: ${error.message}`, { cause: error })
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async getProject (projectId) {
|
|
92
|
+
this._requireReady('getProject')
|
|
93
|
+
if (!projectId) {
|
|
94
|
+
throw new Error('Project ID is required')
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const response = await this._request(`/projects/${projectId}`, {
|
|
98
|
+
method: 'GET',
|
|
99
|
+
methodName: 'getProject'
|
|
100
|
+
})
|
|
101
|
+
if (response.success) {
|
|
102
|
+
const iconSrc = response.data.icon
|
|
103
|
+
? `${this._apiUrl}/core/files/public/${response.data.icon.id}/download`
|
|
104
|
+
: null
|
|
105
|
+
return {
|
|
106
|
+
...response.data,
|
|
107
|
+
icon: { src: iconSrc, ...response.data.icon }
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
throw new Error(response.message)
|
|
111
|
+
} catch (error) {
|
|
112
|
+
throw new Error(`Failed to get project: ${error.message}`, { cause: error })
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Get a public project by ID (no authentication required)
|
|
118
|
+
* Corresponds to router.get('/public/:projectId', ProjectController.getPublicProject)
|
|
119
|
+
*/
|
|
120
|
+
async getPublicProject (projectId) {
|
|
121
|
+
if (!projectId) {
|
|
122
|
+
throw new Error('Project ID is required')
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const response = await this._request(`/projects/public/${projectId}`, {
|
|
126
|
+
method: 'GET',
|
|
127
|
+
methodName: 'getPublicProject'
|
|
128
|
+
})
|
|
129
|
+
if (response.success) {
|
|
130
|
+
const iconSrc = response.data.icon
|
|
131
|
+
? `${this._apiUrl}/core/files/public/${response.data.icon.id}/download`
|
|
132
|
+
: null
|
|
133
|
+
return {
|
|
134
|
+
...response.data,
|
|
135
|
+
icon: { src: iconSrc, ...response.data.icon }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
throw new Error(response.message)
|
|
139
|
+
} catch (error) {
|
|
140
|
+
throw new Error(`Failed to get public project: ${error.message}`, { cause: error })
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async getProjectByKey (key) {
|
|
145
|
+
this._requireReady('getProjectByKey')
|
|
146
|
+
if (!key) {
|
|
147
|
+
throw new Error('Project key is required')
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
// Fetch project by key using new backend route
|
|
151
|
+
const response = await this._request(`/projects/key/${key}`, {
|
|
152
|
+
method: 'GET',
|
|
153
|
+
methodName: 'getProjectByKey'
|
|
154
|
+
})
|
|
155
|
+
if (response.success) {
|
|
156
|
+
const iconSrc = response.data.icon
|
|
157
|
+
? `${this._apiUrl}/core/files/public/${response.data.icon.id}/download`
|
|
158
|
+
: null
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
...response.data,
|
|
162
|
+
icon: { src: iconSrc, ...response.data.icon }
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
throw new Error(response.message)
|
|
167
|
+
} catch (error) {
|
|
168
|
+
throw new Error(`Failed to get project by key: ${error.message}`, { cause: error })
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Get current project data by key (no project ID required)
|
|
174
|
+
*/
|
|
175
|
+
async getProjectDataByKey (key, options = {}) {
|
|
176
|
+
this._requireReady('getProjectDataByKey')
|
|
177
|
+
if (!key) {
|
|
178
|
+
throw new Error('Project key is required')
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const {
|
|
182
|
+
branch = 'main',
|
|
183
|
+
version = 'latest',
|
|
184
|
+
includeHistory = false,
|
|
185
|
+
headers
|
|
186
|
+
} = options
|
|
187
|
+
|
|
188
|
+
const queryParams = new URLSearchParams({
|
|
189
|
+
branch,
|
|
190
|
+
version,
|
|
191
|
+
includeHistory: includeHistory.toString()
|
|
192
|
+
}).toString()
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
const response = await this._request(
|
|
196
|
+
`/projects/key/${key}/data?${queryParams}`,
|
|
197
|
+
{
|
|
198
|
+
method: 'GET',
|
|
199
|
+
methodName: 'getProjectDataByKey',
|
|
200
|
+
...(headers ? { headers } : {})
|
|
201
|
+
}
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
if (response.success) {
|
|
205
|
+
return response.data
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
throw new Error(response.message)
|
|
209
|
+
} catch (error) {
|
|
210
|
+
throw new Error(`Failed to get project data by key: ${error.message}`, { cause: error })
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async updateProject (projectId, data) {
|
|
215
|
+
this._requireReady('updateProject')
|
|
216
|
+
if (!projectId) {
|
|
217
|
+
throw new Error('Project ID is required')
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
const response = await this._request(`/projects/${projectId}`, {
|
|
221
|
+
method: 'PATCH',
|
|
222
|
+
body: JSON.stringify(data),
|
|
223
|
+
methodName: 'updateProject'
|
|
224
|
+
})
|
|
225
|
+
if (response.success) {
|
|
226
|
+
return response.data
|
|
227
|
+
}
|
|
228
|
+
throw new Error(response.message)
|
|
229
|
+
} catch (error) {
|
|
230
|
+
throw new Error(`Failed to update project: ${error.message}`, { cause: error })
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async updateProjectComponents (projectId, components) {
|
|
235
|
+
this._requireReady('updateProjectComponents')
|
|
236
|
+
if (!projectId) {
|
|
237
|
+
throw new Error('Project ID is required')
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
const response = await this._request(
|
|
241
|
+
`/projects/${projectId}/components`,
|
|
242
|
+
{
|
|
243
|
+
method: 'PATCH',
|
|
244
|
+
body: JSON.stringify({ components }),
|
|
245
|
+
methodName: 'updateProjectComponents'
|
|
246
|
+
}
|
|
247
|
+
)
|
|
248
|
+
if (response.success) {
|
|
249
|
+
return response.data
|
|
250
|
+
}
|
|
251
|
+
throw new Error(response.message)
|
|
252
|
+
} catch (error) {
|
|
253
|
+
throw new Error(`Failed to update project components: ${error.message}`, { cause: error })
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async updateProjectSettings (projectId, settings) {
|
|
258
|
+
this._requireReady('updateProjectSettings')
|
|
259
|
+
if (!projectId) {
|
|
260
|
+
throw new Error('Project ID is required')
|
|
261
|
+
}
|
|
262
|
+
try {
|
|
263
|
+
const response = await this._request(`/projects/${projectId}/settings`, {
|
|
264
|
+
method: 'PATCH',
|
|
265
|
+
body: JSON.stringify({ settings }),
|
|
266
|
+
methodName: 'updateProjectSettings'
|
|
267
|
+
})
|
|
268
|
+
if (response.success) {
|
|
269
|
+
return response.data
|
|
270
|
+
}
|
|
271
|
+
throw new Error(response.message)
|
|
272
|
+
} catch (error) {
|
|
273
|
+
throw new Error(`Failed to update project settings: ${error.message}`, { cause: error })
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
async updateProjectName (projectId, name) {
|
|
278
|
+
this._requireReady('updateProjectName')
|
|
279
|
+
if (!projectId) {
|
|
280
|
+
throw new Error('Project ID is required')
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
const response = await this._request(`/projects/${projectId}`, {
|
|
284
|
+
method: 'PATCH',
|
|
285
|
+
body: JSON.stringify({ name }),
|
|
286
|
+
methodName: 'updateProjectName'
|
|
287
|
+
})
|
|
288
|
+
if (response.success) {
|
|
289
|
+
return response.data
|
|
290
|
+
}
|
|
291
|
+
throw new Error(response.message)
|
|
292
|
+
} catch (error) {
|
|
293
|
+
throw new Error(`Failed to update project name: ${error.message}`, { cause: error })
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
async setProjectAccess (projectId, access) {
|
|
298
|
+
this._requireReady('setProjectAccess')
|
|
299
|
+
if (!projectId) {
|
|
300
|
+
throw new Error('Project ID is required')
|
|
301
|
+
}
|
|
302
|
+
if (!access) {
|
|
303
|
+
throw new Error('Access level is required')
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const allowedAccessValues = ['account', 'team', 'organization', 'public']
|
|
307
|
+
if (!allowedAccessValues.includes(access)) {
|
|
308
|
+
throw new Error(
|
|
309
|
+
`Invalid access value: ${access}. Must be one of: ${allowedAccessValues.join(', ')}`
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
const response = await this._request(`/projects/${projectId}`, {
|
|
315
|
+
method: 'PATCH',
|
|
316
|
+
body: JSON.stringify({ access }),
|
|
317
|
+
methodName: 'setProjectAccess'
|
|
318
|
+
})
|
|
319
|
+
if (response.success) {
|
|
320
|
+
return response.data
|
|
321
|
+
}
|
|
322
|
+
throw new Error(response.message)
|
|
323
|
+
} catch (error) {
|
|
324
|
+
throw new Error(`Failed to set project access: ${error.message}`, { cause: error })
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async setProjectVisibility (projectId, visibility) {
|
|
329
|
+
this._requireReady('setProjectVisibility')
|
|
330
|
+
if (!projectId) {
|
|
331
|
+
throw new Error('Project ID is required')
|
|
332
|
+
}
|
|
333
|
+
if (!visibility) {
|
|
334
|
+
throw new Error('Visibility is required')
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const allowedVisibilityValues = ['public', 'private', 'password-protected']
|
|
338
|
+
if (!allowedVisibilityValues.includes(visibility)) {
|
|
339
|
+
throw new Error(
|
|
340
|
+
`Invalid visibility value: ${visibility}. Must be one of: ${allowedVisibilityValues.join(', ')}`
|
|
341
|
+
)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
try {
|
|
345
|
+
const response = await this._request(`/projects/${projectId}`, {
|
|
346
|
+
method: 'PATCH',
|
|
347
|
+
body: JSON.stringify({ visibility }),
|
|
348
|
+
methodName: 'setProjectVisibility'
|
|
349
|
+
})
|
|
350
|
+
if (response.success) {
|
|
351
|
+
return response.data
|
|
352
|
+
}
|
|
353
|
+
throw new Error(response.message)
|
|
354
|
+
} catch (error) {
|
|
355
|
+
throw new Error(`Failed to set project visibility: ${error.message}`, { cause: error })
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
async updateProjectPackage (projectId, pkg) {
|
|
360
|
+
this._requireReady('updateProjectPackage')
|
|
361
|
+
if (!projectId) {
|
|
362
|
+
throw new Error('Project ID is required')
|
|
363
|
+
}
|
|
364
|
+
try {
|
|
365
|
+
// Updated endpoint and payload to align with new API (PATCH /projects/:projectId/package)
|
|
366
|
+
const response = await this._request(`/projects/${projectId}/package`, {
|
|
367
|
+
method: 'PATCH',
|
|
368
|
+
body: JSON.stringify({ package: pkg }),
|
|
369
|
+
methodName: 'updateProjectPackage'
|
|
370
|
+
})
|
|
371
|
+
if (response.success) {
|
|
372
|
+
return response.data
|
|
373
|
+
}
|
|
374
|
+
throw new Error(response.message)
|
|
375
|
+
} catch (error) {
|
|
376
|
+
throw new Error(`Failed to update project package: ${error.message}`, { cause: error })
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
async duplicateProject (projectId, newName, newKey, targetUserId) {
|
|
381
|
+
this._requireReady('duplicateProject')
|
|
382
|
+
if (!projectId) {
|
|
383
|
+
throw new Error('Project ID is required')
|
|
384
|
+
}
|
|
385
|
+
try {
|
|
386
|
+
const response = await this._request(`/projects/${projectId}/duplicate`, {
|
|
387
|
+
method: 'POST',
|
|
388
|
+
body: JSON.stringify({ name: newName, key: newKey, targetUserId }),
|
|
389
|
+
methodName: 'duplicateProject'
|
|
390
|
+
})
|
|
391
|
+
if (response.success) {
|
|
392
|
+
return response.data
|
|
393
|
+
}
|
|
394
|
+
throw new Error(response.message)
|
|
395
|
+
} catch (error) {
|
|
396
|
+
throw new Error(`Failed to duplicate project: ${error.message}`, { cause: error })
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
async removeProject (projectId) {
|
|
401
|
+
this._requireReady('removeProject')
|
|
402
|
+
if (!projectId) {
|
|
403
|
+
throw new Error('Project ID is required')
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
const response = await this._request(`/projects/${projectId}`, {
|
|
407
|
+
method: 'DELETE',
|
|
408
|
+
methodName: 'removeProject'
|
|
409
|
+
})
|
|
410
|
+
if (response.success) {
|
|
411
|
+
return response
|
|
412
|
+
}
|
|
413
|
+
throw new Error(response.message)
|
|
414
|
+
} catch (error) {
|
|
415
|
+
throw new Error(`Failed to remove project: ${error.message}`, { cause: error })
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
async checkProjectKeyAvailability (key) {
|
|
420
|
+
this._requireReady('checkProjectKeyAvailability')
|
|
421
|
+
if (!key) {
|
|
422
|
+
throw new Error('Project key is required')
|
|
423
|
+
}
|
|
424
|
+
try {
|
|
425
|
+
const response = await this._request(`/projects/check-key/${key}`, {
|
|
426
|
+
method: 'GET',
|
|
427
|
+
methodName: 'checkProjectKeyAvailability'
|
|
428
|
+
})
|
|
429
|
+
if (response.success) {
|
|
430
|
+
return response.data
|
|
431
|
+
}
|
|
432
|
+
throw new Error(response.message)
|
|
433
|
+
} catch (error) {
|
|
434
|
+
throw new Error(
|
|
435
|
+
`Failed to check project key availability: ${error.message}`,
|
|
436
|
+
{ cause: error }
|
|
437
|
+
)
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// ==================== PROJECT PERMISSION CONFIG METHODS ====================
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Fetch effective role → permissions configuration for a project.
|
|
445
|
+
* Mirrors ProjectController.getProjectRolePermissionsConfig.
|
|
446
|
+
*/
|
|
447
|
+
async getProjectRolePermissionsConfig (projectId, options = {}) {
|
|
448
|
+
this._requireReady('getProjectRolePermissionsConfig')
|
|
449
|
+
if (!projectId) {
|
|
450
|
+
throw new Error('Project ID is required')
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const { headers } = options
|
|
454
|
+
|
|
455
|
+
try {
|
|
456
|
+
const response = await this._request(`/projects/${projectId}/permissions`, {
|
|
457
|
+
method: 'GET',
|
|
458
|
+
...(headers ? { headers } : {}),
|
|
459
|
+
methodName: 'getProjectRolePermissionsConfig'
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
if (response && response.success) {
|
|
463
|
+
return response.data
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
throw new Error(response.message)
|
|
467
|
+
} catch (error) {
|
|
468
|
+
throw new Error(
|
|
469
|
+
`Failed to get project role permissions config: ${error.message}`,
|
|
470
|
+
{ cause: error }
|
|
471
|
+
)
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Update project-level role → permissions overrides.
|
|
477
|
+
* Mirrors ProjectController.updateProjectRolePermissionsConfig.
|
|
478
|
+
*/
|
|
479
|
+
async updateProjectRolePermissionsConfig (projectId, rolePermissions, options = {}) {
|
|
480
|
+
this._requireReady('updateProjectRolePermissionsConfig')
|
|
481
|
+
if (!projectId) {
|
|
482
|
+
throw new Error('Project ID is required')
|
|
483
|
+
}
|
|
484
|
+
if (!rolePermissions || typeof rolePermissions !== 'object') {
|
|
485
|
+
throw new Error('rolePermissions object is required')
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const { headers } = options
|
|
489
|
+
|
|
490
|
+
try {
|
|
491
|
+
const response = await this._request(`/projects/${projectId}/permissions`, {
|
|
492
|
+
method: 'PATCH',
|
|
493
|
+
body: JSON.stringify({ rolePermissions }),
|
|
494
|
+
...(headers ? { headers } : {}),
|
|
495
|
+
methodName: 'updateProjectRolePermissionsConfig'
|
|
496
|
+
})
|
|
497
|
+
|
|
498
|
+
if (response && response.success) {
|
|
499
|
+
return response.data
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
throw new Error(response.message)
|
|
503
|
+
} catch (error) {
|
|
504
|
+
throw new Error(
|
|
505
|
+
`Failed to update project role permissions config: ${error.message}`,
|
|
506
|
+
{ cause: error }
|
|
507
|
+
)
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// ==================== PROJECT MEMBER METHODS ====================
|
|
512
|
+
|
|
513
|
+
async getProjectMembers (projectId) {
|
|
514
|
+
this._requireReady('getProjectMembers')
|
|
515
|
+
if (!projectId) {
|
|
516
|
+
throw new Error('Project ID is required')
|
|
517
|
+
}
|
|
518
|
+
try {
|
|
519
|
+
const response = await this._request(`/projects/${projectId}/members`, {
|
|
520
|
+
method: 'GET',
|
|
521
|
+
methodName: 'getProjectMembers'
|
|
522
|
+
})
|
|
523
|
+
if (response.success) {
|
|
524
|
+
return response.data
|
|
525
|
+
}
|
|
526
|
+
throw new Error(response.message)
|
|
527
|
+
} catch (error) {
|
|
528
|
+
throw new Error(`Failed to get project members: ${error.message}`, { cause: error })
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
async inviteMember (projectId, email, role = 'guest', options = {}) {
|
|
533
|
+
this._requireReady('inviteMember')
|
|
534
|
+
if (!projectId || !email || !role) {
|
|
535
|
+
throw new Error('Project ID, email, and role are required')
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const { name, callbackUrl, headers } = options
|
|
539
|
+
|
|
540
|
+
// Default callbackUrl if not provided
|
|
541
|
+
const defaultCallbackUrl =
|
|
542
|
+
typeof window === 'undefined'
|
|
543
|
+
? 'https://app.symbols.com/accept-invite'
|
|
544
|
+
: `${window.location.origin}/accept-invite`
|
|
545
|
+
|
|
546
|
+
try {
|
|
547
|
+
const requestBody = {
|
|
548
|
+
email,
|
|
549
|
+
role,
|
|
550
|
+
callbackUrl: callbackUrl || defaultCallbackUrl
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// Add optional name if provided
|
|
554
|
+
if (name) {
|
|
555
|
+
requestBody.name = name
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
const response = await this._request(`/projects/${projectId}/invite`, {
|
|
559
|
+
method: 'POST',
|
|
560
|
+
body: JSON.stringify(requestBody),
|
|
561
|
+
...(headers ? { headers } : {}),
|
|
562
|
+
methodName: 'inviteMember'
|
|
563
|
+
})
|
|
564
|
+
if (response.success) {
|
|
565
|
+
return response.data
|
|
566
|
+
}
|
|
567
|
+
throw new Error(response.message)
|
|
568
|
+
} catch (error) {
|
|
569
|
+
throw new Error(`Failed to invite member: ${error.message}`, { cause: error })
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
* Create a magic invite link for a project.
|
|
575
|
+
* The backend returns a token and URL that can be shared directly.
|
|
576
|
+
*/
|
|
577
|
+
async createMagicInviteLink (projectId, options = {}) {
|
|
578
|
+
this._requireReady('createMagicInviteLink')
|
|
579
|
+
if (!projectId) {
|
|
580
|
+
throw new Error('Project ID is required')
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
const { headers } = options
|
|
584
|
+
|
|
585
|
+
try {
|
|
586
|
+
const response = await this._request(`/projects/${projectId}/invite-link`, {
|
|
587
|
+
method: 'POST',
|
|
588
|
+
...(headers ? { headers } : {}),
|
|
589
|
+
methodName: 'createMagicInviteLink'
|
|
590
|
+
})
|
|
591
|
+
|
|
592
|
+
if (response.success) {
|
|
593
|
+
return response.data
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
throw new Error(response.message)
|
|
597
|
+
} catch (error) {
|
|
598
|
+
throw new Error(`Failed to create magic invite link: ${error.message}`, { cause: error })
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
async acceptInvite (token) {
|
|
603
|
+
this._requireReady('acceptInvite')
|
|
604
|
+
if (!token) {
|
|
605
|
+
throw new Error('Invitation token is required')
|
|
606
|
+
}
|
|
607
|
+
try {
|
|
608
|
+
const response = await this._request('/projects/accept-invite', {
|
|
609
|
+
method: 'POST',
|
|
610
|
+
body: JSON.stringify({ token }),
|
|
611
|
+
methodName: 'acceptInvite'
|
|
612
|
+
})
|
|
613
|
+
if (response.success) {
|
|
614
|
+
return response.data
|
|
615
|
+
}
|
|
616
|
+
throw new Error(response.message)
|
|
617
|
+
} catch (error) {
|
|
618
|
+
throw new Error(`Failed to accept invite: ${error.message}`, { cause: error })
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
async updateMemberRole (projectId, memberId, role) {
|
|
623
|
+
this._requireReady('updateMemberRole')
|
|
624
|
+
if (!projectId || !memberId || !role) {
|
|
625
|
+
throw new Error('Project ID, member ID, and role are required')
|
|
626
|
+
}
|
|
627
|
+
try {
|
|
628
|
+
const response = await this._request(
|
|
629
|
+
`/projects/${projectId}/members/${memberId}`,
|
|
630
|
+
{
|
|
631
|
+
method: 'PATCH',
|
|
632
|
+
body: JSON.stringify({ role }),
|
|
633
|
+
methodName: 'updateMemberRole'
|
|
634
|
+
}
|
|
635
|
+
)
|
|
636
|
+
if (response.success) {
|
|
637
|
+
return response.data
|
|
638
|
+
}
|
|
639
|
+
throw new Error(response.message)
|
|
640
|
+
} catch (error) {
|
|
641
|
+
throw new Error(`Failed to update member role: ${error.message}`, { cause: error })
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
async removeMember (projectId, memberId) {
|
|
646
|
+
this._requireReady('removeMember')
|
|
647
|
+
if (!projectId || !memberId) {
|
|
648
|
+
throw new Error('Project ID and member ID are required')
|
|
649
|
+
}
|
|
650
|
+
try {
|
|
651
|
+
const response = await this._request(
|
|
652
|
+
`/projects/${projectId}/members/${memberId}`,
|
|
653
|
+
{
|
|
654
|
+
method: 'DELETE',
|
|
655
|
+
methodName: 'removeMember'
|
|
656
|
+
}
|
|
657
|
+
)
|
|
658
|
+
if (response.success) {
|
|
659
|
+
return response.data
|
|
660
|
+
}
|
|
661
|
+
throw new Error(response.message)
|
|
662
|
+
} catch (error) {
|
|
663
|
+
throw new Error(`Failed to remove member: ${error.message}`, { cause: error })
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// ==================== PROJECT LIBRARY METHODS ====================
|
|
668
|
+
|
|
669
|
+
async getAvailableLibraries (params = {}) {
|
|
670
|
+
this._requireReady('getAvailableLibraries')
|
|
671
|
+
const queryParams = new URLSearchParams(params).toString()
|
|
672
|
+
try {
|
|
673
|
+
const response = await this._request(
|
|
674
|
+
`/projects/libraries/available?${queryParams}`,
|
|
675
|
+
{
|
|
676
|
+
method: 'GET',
|
|
677
|
+
methodName: 'getAvailableLibraries'
|
|
678
|
+
}
|
|
679
|
+
)
|
|
680
|
+
if (response.success) {
|
|
681
|
+
return response.data
|
|
682
|
+
}
|
|
683
|
+
throw new Error(response.message)
|
|
684
|
+
} catch (error) {
|
|
685
|
+
throw new Error(`Failed to get available libraries: ${error.message}`, { cause: error })
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
async getProjectLibraries (projectId) {
|
|
690
|
+
this._requireReady('getProjectLibraries')
|
|
691
|
+
if (!projectId) {
|
|
692
|
+
throw new Error('Project ID is required')
|
|
693
|
+
}
|
|
694
|
+
try {
|
|
695
|
+
const response = await this._request(`/projects/${projectId}/libraries`, {
|
|
696
|
+
method: 'GET',
|
|
697
|
+
methodName: 'getProjectLibraries'
|
|
698
|
+
})
|
|
699
|
+
if (response.success) {
|
|
700
|
+
return response.data
|
|
701
|
+
}
|
|
702
|
+
throw new Error(response.message)
|
|
703
|
+
} catch (error) {
|
|
704
|
+
throw new Error(`Failed to get project libraries: ${error.message}`, { cause: error })
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
async addProjectLibraries (projectId, libraryIds) {
|
|
709
|
+
this._requireReady('addProjectLibraries')
|
|
710
|
+
if (!projectId || !libraryIds) {
|
|
711
|
+
throw new Error('Project ID and library IDs are required')
|
|
712
|
+
}
|
|
713
|
+
try {
|
|
714
|
+
const response = await this._request(`/projects/${projectId}/libraries`, {
|
|
715
|
+
method: 'POST',
|
|
716
|
+
body: JSON.stringify({ libraryIds }),
|
|
717
|
+
methodName: 'addProjectLibraries'
|
|
718
|
+
})
|
|
719
|
+
if (response.success) {
|
|
720
|
+
return response
|
|
721
|
+
}
|
|
722
|
+
throw new Error(response.message)
|
|
723
|
+
} catch (error) {
|
|
724
|
+
throw new Error(`Failed to add project libraries: ${error.message}`, { cause: error })
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
async removeProjectLibraries (projectId, libraryIds) {
|
|
729
|
+
this._requireReady('removeProjectLibraries')
|
|
730
|
+
if (!projectId || !libraryIds) {
|
|
731
|
+
throw new Error('Project ID and library IDs are required')
|
|
732
|
+
}
|
|
733
|
+
try {
|
|
734
|
+
const response = await this._request(`/projects/${projectId}/libraries`, {
|
|
735
|
+
method: 'DELETE',
|
|
736
|
+
body: JSON.stringify({ libraryIds }),
|
|
737
|
+
methodName: 'removeProjectLibraries'
|
|
738
|
+
})
|
|
739
|
+
if (response.success) {
|
|
740
|
+
return response
|
|
741
|
+
}
|
|
742
|
+
throw new Error(response.message)
|
|
743
|
+
} catch (error) {
|
|
744
|
+
throw new Error(`Failed to remove project libraries: ${error.message}`, { cause: error })
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// ==================== PROJECT DATA METHODS (SYMSTORY REPLACEMENT) ====================
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Apply changes to a project, creating a new version
|
|
752
|
+
* Replaces: SymstoryService.updateData()
|
|
753
|
+
*/
|
|
754
|
+
async applyProjectChanges (projectId, changes, options = {}) {
|
|
755
|
+
this._requireReady('applyProjectChanges')
|
|
756
|
+
if (!projectId) {
|
|
757
|
+
throw new Error('Project ID is required')
|
|
758
|
+
}
|
|
759
|
+
if (!Array.isArray(changes)) {
|
|
760
|
+
throw new Error('Changes must be an array')
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
const { message, branch = 'main', type = 'patch', headers } = options
|
|
764
|
+
|
|
765
|
+
// Preprocess into granular changes and derive orders using current state if available
|
|
766
|
+
const state = this._context && this._context.state
|
|
767
|
+
const { granularChanges, orders: preprocessorOrders } = preprocessChanges(state, changes, options)
|
|
768
|
+
const derivedOrders = options.orders || (preprocessorOrders && preprocessorOrders.length
|
|
769
|
+
? preprocessorOrders
|
|
770
|
+
: (state ? computeOrdersForTuples(state, granularChanges) : []))
|
|
771
|
+
|
|
772
|
+
const stringify = (val) => deepStringifyFunctions(val, Array.isArray(val) ? [] : {})
|
|
773
|
+
|
|
774
|
+
try {
|
|
775
|
+
const response = await this._request(`/projects/${projectId}/changes`, {
|
|
776
|
+
method: 'POST',
|
|
777
|
+
body: JSON.stringify({
|
|
778
|
+
changes: stringify(changes),
|
|
779
|
+
granularChanges: stringify(granularChanges),
|
|
780
|
+
message,
|
|
781
|
+
branch,
|
|
782
|
+
type,
|
|
783
|
+
...(derivedOrders && derivedOrders.length ? { orders: derivedOrders } : {})
|
|
784
|
+
}),
|
|
785
|
+
...(headers ? { headers } : {}),
|
|
786
|
+
methodName: 'applyProjectChanges'
|
|
787
|
+
})
|
|
788
|
+
|
|
789
|
+
if (response.success) {
|
|
790
|
+
return response.data
|
|
791
|
+
}
|
|
792
|
+
throw new Error(response.message)
|
|
793
|
+
} catch (error) {
|
|
794
|
+
throw new Error(`Failed to apply project changes: ${error.message}`, { cause: error })
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* Get current project data for a specific branch
|
|
800
|
+
* Replaces: SymstoryService.getData()
|
|
801
|
+
*/
|
|
802
|
+
async getProjectData (projectId, options = {}) {
|
|
803
|
+
this._requireReady('getProjectData')
|
|
804
|
+
if (!projectId) {
|
|
805
|
+
throw new Error('Project ID is required')
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
const {
|
|
809
|
+
branch = 'main',
|
|
810
|
+
version = 'latest',
|
|
811
|
+
includeHistory = false,
|
|
812
|
+
headers
|
|
813
|
+
} = options
|
|
814
|
+
|
|
815
|
+
const queryParams = new URLSearchParams({
|
|
816
|
+
branch,
|
|
817
|
+
version,
|
|
818
|
+
includeHistory: includeHistory.toString()
|
|
819
|
+
}).toString()
|
|
820
|
+
|
|
821
|
+
try {
|
|
822
|
+
const response = await this._request(
|
|
823
|
+
`/projects/${projectId}/data?${queryParams}`,
|
|
824
|
+
{
|
|
825
|
+
method: 'GET',
|
|
826
|
+
methodName: 'getProjectData',
|
|
827
|
+
...(headers ? { headers } : {})
|
|
828
|
+
}
|
|
829
|
+
)
|
|
830
|
+
if (response.success) {
|
|
831
|
+
return response.data
|
|
832
|
+
}
|
|
833
|
+
throw new Error(response.message)
|
|
834
|
+
} catch (error) {
|
|
835
|
+
throw new Error(`Failed to get project data: ${error.message}`, { cause: error })
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* Get project versions with pagination
|
|
841
|
+
*/
|
|
842
|
+
async getProjectVersions (projectId, options = {}) {
|
|
843
|
+
this._requireReady('getProjectVersions')
|
|
844
|
+
if (!projectId) {
|
|
845
|
+
throw new Error('Project ID is required')
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
const { branch = 'main', page = 1, limit = 50, headers } = options
|
|
849
|
+
|
|
850
|
+
const queryParams = new URLSearchParams({
|
|
851
|
+
branch,
|
|
852
|
+
page: page.toString(),
|
|
853
|
+
limit: limit.toString()
|
|
854
|
+
}).toString()
|
|
855
|
+
|
|
856
|
+
try {
|
|
857
|
+
const response = await this._request(
|
|
858
|
+
`/projects/${projectId}/versions?${queryParams}`,
|
|
859
|
+
{
|
|
860
|
+
method: 'GET',
|
|
861
|
+
methodName: 'getProjectVersions',
|
|
862
|
+
...(headers ? { headers } : {})
|
|
863
|
+
}
|
|
864
|
+
)
|
|
865
|
+
if (response.success) {
|
|
866
|
+
return response.data
|
|
867
|
+
}
|
|
868
|
+
throw new Error(response.message)
|
|
869
|
+
} catch (error) {
|
|
870
|
+
throw new Error(`Failed to get project versions: ${error.message}`, { cause: error })
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// ==================== PROJECT ENVIRONMENT METHODS ====================
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* List all environments for a project along with plan limits and activation state.
|
|
878
|
+
* Mirrors ProjectController.listEnvironments.
|
|
879
|
+
*/
|
|
880
|
+
async listEnvironments (projectId, options = {}) {
|
|
881
|
+
this._requireReady('listEnvironments')
|
|
882
|
+
if (!projectId) {
|
|
883
|
+
throw new Error('Project ID is required')
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
const { headers } = options
|
|
887
|
+
|
|
888
|
+
try {
|
|
889
|
+
const response = await this._request(`/projects/${projectId}/environments`, {
|
|
890
|
+
method: 'GET',
|
|
891
|
+
...(headers ? { headers } : {}),
|
|
892
|
+
methodName: 'listEnvironments'
|
|
893
|
+
})
|
|
894
|
+
|
|
895
|
+
if (response && response.success) {
|
|
896
|
+
return response.data
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
throw new Error(response.message)
|
|
900
|
+
} catch (error) {
|
|
901
|
+
throw new Error(`Failed to list environments: ${error.message}`, { cause: error })
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/**
|
|
906
|
+
* Activate multi-environment support for a project.
|
|
907
|
+
* Optional `force` will reconfigure DNS/TLS even if already active.
|
|
908
|
+
* Mirrors ProjectController.activateMultipleEnvironments.
|
|
909
|
+
*/
|
|
910
|
+
async activateMultipleEnvironments (projectId, options = {}) {
|
|
911
|
+
this._requireReady('activateMultipleEnvironments')
|
|
912
|
+
if (!projectId) {
|
|
913
|
+
throw new Error('Project ID is required')
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
const { force = false, headers } = options
|
|
917
|
+
|
|
918
|
+
try {
|
|
919
|
+
const response = await this._request(`/projects/${projectId}/environments/activate`, {
|
|
920
|
+
method: 'POST',
|
|
921
|
+
body: JSON.stringify({ ...(force ? { force: true } : {}) }),
|
|
922
|
+
...(headers ? { headers } : {}),
|
|
923
|
+
methodName: 'activateMultipleEnvironments'
|
|
924
|
+
})
|
|
925
|
+
|
|
926
|
+
if (response && response.success) {
|
|
927
|
+
return response.data
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
throw new Error(response.message)
|
|
931
|
+
} catch (error) {
|
|
932
|
+
throw new Error(
|
|
933
|
+
`Failed to activate multiple environments: ${error.message}`,
|
|
934
|
+
{ cause: error }
|
|
935
|
+
)
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Create or update (upsert) an environment config for a project.
|
|
941
|
+
* Mirrors ProjectController.upsertEnvironment.
|
|
942
|
+
*/
|
|
943
|
+
async upsertEnvironment (projectId, envKey, config, options = {}) {
|
|
944
|
+
this._requireReady('upsertEnvironment')
|
|
945
|
+
if (!projectId) {
|
|
946
|
+
throw new Error('Project ID is required')
|
|
947
|
+
}
|
|
948
|
+
if (!envKey) {
|
|
949
|
+
throw new Error('Environment key is required')
|
|
950
|
+
}
|
|
951
|
+
if (!config || typeof config !== 'object') {
|
|
952
|
+
throw new Error('Environment config object is required')
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
const { headers } = options
|
|
956
|
+
|
|
957
|
+
try {
|
|
958
|
+
const response = await this._request(`/projects/${projectId}/environments`, {
|
|
959
|
+
method: 'POST',
|
|
960
|
+
body: JSON.stringify({ envKey, config }),
|
|
961
|
+
...(headers ? { headers } : {}),
|
|
962
|
+
methodName: 'upsertEnvironment'
|
|
963
|
+
})
|
|
964
|
+
|
|
965
|
+
if (response && response.success) {
|
|
966
|
+
return response.data
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
throw new Error(response.message)
|
|
970
|
+
} catch (error) {
|
|
971
|
+
throw new Error(`Failed to upsert environment: ${error.message}`, { cause: error })
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* Update an existing environment config.
|
|
977
|
+
* Mirrors ProjectController.updateEnvironment.
|
|
978
|
+
*/
|
|
979
|
+
async updateEnvironment (projectId, envKey, updates, options = {}) {
|
|
980
|
+
this._requireReady('updateEnvironment')
|
|
981
|
+
if (!projectId) {
|
|
982
|
+
throw new Error('Project ID is required')
|
|
983
|
+
}
|
|
984
|
+
if (!envKey) {
|
|
985
|
+
throw new Error('Environment key is required')
|
|
986
|
+
}
|
|
987
|
+
if (!updates || typeof updates !== 'object') {
|
|
988
|
+
throw new Error('Environment updates object is required')
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
const { headers } = options
|
|
992
|
+
|
|
993
|
+
try {
|
|
994
|
+
const response = await this._request(
|
|
995
|
+
`/projects/${projectId}/environments/${encodeURIComponent(envKey)}`,
|
|
996
|
+
{
|
|
997
|
+
method: 'PATCH',
|
|
998
|
+
body: JSON.stringify(updates),
|
|
999
|
+
...(headers ? { headers } : {}),
|
|
1000
|
+
methodName: 'updateEnvironment'
|
|
1001
|
+
}
|
|
1002
|
+
)
|
|
1003
|
+
|
|
1004
|
+
if (response && response.success) {
|
|
1005
|
+
return response.data
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
throw new Error(response.message)
|
|
1009
|
+
} catch (error) {
|
|
1010
|
+
throw new Error(`Failed to update environment: ${error.message}`, { cause: error })
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Publish a project to a specific environment (set its effective mode/version/branch).
|
|
1016
|
+
* Mirrors ProjectController.publishToEnvironment.
|
|
1017
|
+
*/
|
|
1018
|
+
async publishToEnvironment (projectId, envKey, payload, options = {}) {
|
|
1019
|
+
this._requireReady('publishToEnvironment')
|
|
1020
|
+
if (!projectId) {
|
|
1021
|
+
throw new Error('Project ID is required')
|
|
1022
|
+
}
|
|
1023
|
+
if (!envKey) {
|
|
1024
|
+
throw new Error('Environment key is required')
|
|
1025
|
+
}
|
|
1026
|
+
if (!payload || typeof payload !== 'object') {
|
|
1027
|
+
throw new Error('Publish payload is required')
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
const { headers } = options
|
|
1031
|
+
|
|
1032
|
+
try {
|
|
1033
|
+
const response = await this._request(
|
|
1034
|
+
`/projects/${projectId}/environments/${encodeURIComponent(envKey)}/publish`,
|
|
1035
|
+
{
|
|
1036
|
+
method: 'POST',
|
|
1037
|
+
body: JSON.stringify(payload),
|
|
1038
|
+
...(headers ? { headers } : {}),
|
|
1039
|
+
methodName: 'publishToEnvironment'
|
|
1040
|
+
}
|
|
1041
|
+
)
|
|
1042
|
+
|
|
1043
|
+
if (response && response.success) {
|
|
1044
|
+
return response.data
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
throw new Error(response.message)
|
|
1048
|
+
} catch (error) {
|
|
1049
|
+
throw new Error(`Failed to publish to environment: ${error.message}`, { cause: error })
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* Delete an environment from a project.
|
|
1055
|
+
* Mirrors ProjectController.deleteEnvironment.
|
|
1056
|
+
*/
|
|
1057
|
+
async deleteEnvironment (projectId, envKey, options = {}) {
|
|
1058
|
+
this._requireReady('deleteEnvironment')
|
|
1059
|
+
if (!projectId) {
|
|
1060
|
+
throw new Error('Project ID is required')
|
|
1061
|
+
}
|
|
1062
|
+
if (!envKey) {
|
|
1063
|
+
throw new Error('Environment key is required')
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
const { headers } = options
|
|
1067
|
+
|
|
1068
|
+
try {
|
|
1069
|
+
const response = await this._request(
|
|
1070
|
+
`/projects/${projectId}/environments/${encodeURIComponent(envKey)}`,
|
|
1071
|
+
{
|
|
1072
|
+
method: 'DELETE',
|
|
1073
|
+
...(headers ? { headers } : {}),
|
|
1074
|
+
methodName: 'deleteEnvironment'
|
|
1075
|
+
}
|
|
1076
|
+
)
|
|
1077
|
+
|
|
1078
|
+
if (response && response.success) {
|
|
1079
|
+
return response.data
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
throw new Error(response.message)
|
|
1083
|
+
} catch (error) {
|
|
1084
|
+
throw new Error(`Failed to delete environment: ${error.message}`, { cause: error })
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Promote content between environments (simple pipeline).
|
|
1090
|
+
* Mirrors ProjectController.promoteEnvironment.
|
|
1091
|
+
*/
|
|
1092
|
+
async promoteEnvironment (projectId, fromEnvKey, toEnvKey, options = {}) {
|
|
1093
|
+
this._requireReady('promoteEnvironment')
|
|
1094
|
+
if (!projectId) {
|
|
1095
|
+
throw new Error('Project ID is required')
|
|
1096
|
+
}
|
|
1097
|
+
if (!fromEnvKey || !toEnvKey) {
|
|
1098
|
+
throw new Error('Both fromEnvKey and toEnvKey are required')
|
|
1099
|
+
}
|
|
1100
|
+
if (fromEnvKey === toEnvKey) {
|
|
1101
|
+
throw new Error('fromEnvKey and toEnvKey must be different')
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
const { headers } = options
|
|
1105
|
+
|
|
1106
|
+
try {
|
|
1107
|
+
const response = await this._request(`/projects/${projectId}/pipeline/promote`, {
|
|
1108
|
+
method: 'POST',
|
|
1109
|
+
body: JSON.stringify({ from: fromEnvKey, to: toEnvKey }),
|
|
1110
|
+
...(headers ? { headers } : {}),
|
|
1111
|
+
methodName: 'promoteEnvironment'
|
|
1112
|
+
})
|
|
1113
|
+
|
|
1114
|
+
if (response && response.success) {
|
|
1115
|
+
return response.data
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
throw new Error(response.message)
|
|
1119
|
+
} catch (error) {
|
|
1120
|
+
throw new Error(`Failed to promote environment: ${error.message}`, { cause: error })
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
/**
|
|
1125
|
+
* Restore project to a previous version
|
|
1126
|
+
* Replaces: SymstoryService.restoreVersion()
|
|
1127
|
+
*/
|
|
1128
|
+
async restoreProjectVersion (projectId, version, options = {}) {
|
|
1129
|
+
this._requireReady('restoreProjectVersion')
|
|
1130
|
+
if (!projectId) {
|
|
1131
|
+
throw new Error('Project ID is required')
|
|
1132
|
+
}
|
|
1133
|
+
if (!version) {
|
|
1134
|
+
throw new Error('Version is required')
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
const { message, branch = 'main', type = 'patch', headers } = options
|
|
1138
|
+
|
|
1139
|
+
try {
|
|
1140
|
+
const response = await this._request(`/projects/${projectId}/restore`, {
|
|
1141
|
+
method: 'POST',
|
|
1142
|
+
body: JSON.stringify({
|
|
1143
|
+
version,
|
|
1144
|
+
message,
|
|
1145
|
+
branch,
|
|
1146
|
+
type
|
|
1147
|
+
}),
|
|
1148
|
+
...(headers ? { headers } : {}),
|
|
1149
|
+
methodName: 'restoreProjectVersion'
|
|
1150
|
+
})
|
|
1151
|
+
if (response.success) {
|
|
1152
|
+
return response.data
|
|
1153
|
+
}
|
|
1154
|
+
throw new Error(response.message)
|
|
1155
|
+
} catch (error) {
|
|
1156
|
+
throw new Error(`Failed to restore project version: ${error.message}`, { cause: error })
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* Helper method to update a single item in the project
|
|
1162
|
+
* Convenience wrapper around applyProjectChanges
|
|
1163
|
+
*/
|
|
1164
|
+
async updateProjectItem (projectId, path, value, options = {}) {
|
|
1165
|
+
const changes = [['update', path, value]]
|
|
1166
|
+
const message =
|
|
1167
|
+
options.message ||
|
|
1168
|
+
`Updated ${Array.isArray(path) ? path.join('.') : path}`
|
|
1169
|
+
|
|
1170
|
+
return await this.applyProjectChanges(projectId, changes, {
|
|
1171
|
+
...options,
|
|
1172
|
+
message
|
|
1173
|
+
})
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* Helper method to delete an item from the project
|
|
1178
|
+
* Convenience wrapper around applyProjectChanges
|
|
1179
|
+
*/
|
|
1180
|
+
async deleteProjectItem (projectId, path, options = {}) {
|
|
1181
|
+
const changes = [['delete', path]]
|
|
1182
|
+
const message =
|
|
1183
|
+
options.message ||
|
|
1184
|
+
`Deleted ${Array.isArray(path) ? path.join('.') : path}`
|
|
1185
|
+
|
|
1186
|
+
return await this.applyProjectChanges(projectId, changes, {
|
|
1187
|
+
...options,
|
|
1188
|
+
message
|
|
1189
|
+
})
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
/**
|
|
1193
|
+
* Helper method to set a value in the project (alias for update)
|
|
1194
|
+
* Convenience wrapper around applyProjectChanges
|
|
1195
|
+
*/
|
|
1196
|
+
async setProjectValue (projectId, path, value, options = {}) {
|
|
1197
|
+
const changes = [['set', path, value]]
|
|
1198
|
+
const message =
|
|
1199
|
+
options.message || `Set ${Array.isArray(path) ? path.join('.') : path}`
|
|
1200
|
+
|
|
1201
|
+
return await this.applyProjectChanges(projectId, changes, {
|
|
1202
|
+
...options,
|
|
1203
|
+
message
|
|
1204
|
+
})
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
/**
|
|
1208
|
+
* Helper method to add multiple items to the project
|
|
1209
|
+
* Convenience wrapper around applyProjectChanges
|
|
1210
|
+
*/
|
|
1211
|
+
async addProjectItems (projectId, items, options = {}) {
|
|
1212
|
+
const changes = items
|
|
1213
|
+
.map(item => {
|
|
1214
|
+
const [type, data] = item
|
|
1215
|
+
const { value, ...schema } = data
|
|
1216
|
+
return [
|
|
1217
|
+
['update', [type, data.key], value],
|
|
1218
|
+
['update', ['schema', type, data.key], schema]
|
|
1219
|
+
]
|
|
1220
|
+
})
|
|
1221
|
+
.flat()
|
|
1222
|
+
|
|
1223
|
+
const message = options.message || `Added ${items.length} items`
|
|
1224
|
+
|
|
1225
|
+
return await this.applyProjectChanges(projectId, changes, {
|
|
1226
|
+
...options,
|
|
1227
|
+
message
|
|
1228
|
+
})
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
/**
|
|
1232
|
+
* Helper method to get specific data from project by path
|
|
1233
|
+
* Convenience wrapper that gets project data and extracts specific path
|
|
1234
|
+
*/
|
|
1235
|
+
async getProjectItemByPath (projectId, path, options = {}) {
|
|
1236
|
+
const projectData = await this.getProjectData(projectId, options)
|
|
1237
|
+
|
|
1238
|
+
if (!projectData?.data) {
|
|
1239
|
+
return null
|
|
1240
|
+
}
|
|
1241
|
+
|
|
1242
|
+
// Navigate to the specific path in the data
|
|
1243
|
+
let current = projectData.data
|
|
1244
|
+
const pathArray = Array.isArray(path) ? path : [path]
|
|
1245
|
+
|
|
1246
|
+
for (const segment of pathArray) {
|
|
1247
|
+
if (current && typeof current === 'object' && segment in current) {
|
|
1248
|
+
current = current[segment]
|
|
1249
|
+
} else {
|
|
1250
|
+
return null
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
return current
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
// ==================== FAVORITE PROJECT METHODS ====================
|
|
1258
|
+
|
|
1259
|
+
async getFavoriteProjects () {
|
|
1260
|
+
this._requireReady('getFavoriteProjects')
|
|
1261
|
+
try {
|
|
1262
|
+
const response = await this._request('/users/favorites', {
|
|
1263
|
+
method: 'GET',
|
|
1264
|
+
methodName: 'getFavoriteProjects'
|
|
1265
|
+
})
|
|
1266
|
+
|
|
1267
|
+
if (response.success) {
|
|
1268
|
+
// Ensure each project has proper icon src like other project lists
|
|
1269
|
+
return (response.data || []).map(project => ({
|
|
1270
|
+
isFavorite: true,
|
|
1271
|
+
...project,
|
|
1272
|
+
...(project.icon && {
|
|
1273
|
+
icon: {
|
|
1274
|
+
src: `${this._apiUrl}/core/files/public/${project.icon.id}/download`,
|
|
1275
|
+
...project.icon
|
|
1276
|
+
}
|
|
1277
|
+
})
|
|
1278
|
+
}))
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
throw new Error(response.message)
|
|
1282
|
+
} catch (error) {
|
|
1283
|
+
throw new Error(`Failed to get favorite projects: ${error.message}`, { cause: error })
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
async addFavoriteProject (projectId) {
|
|
1288
|
+
this._requireReady('addFavoriteProject')
|
|
1289
|
+
if (!projectId) {
|
|
1290
|
+
throw new Error('Project ID is required')
|
|
1291
|
+
}
|
|
1292
|
+
try {
|
|
1293
|
+
const response = await this._request(`/users/favorites/${projectId}`, {
|
|
1294
|
+
method: 'POST',
|
|
1295
|
+
methodName: 'addFavoriteProject'
|
|
1296
|
+
})
|
|
1297
|
+
|
|
1298
|
+
if (response.success) {
|
|
1299
|
+
return response.data
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
throw new Error(response.message)
|
|
1303
|
+
} catch (error) {
|
|
1304
|
+
throw new Error(`Failed to add favorite project: ${error.message}`, { cause: error })
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
async removeFavoriteProject (projectId) {
|
|
1309
|
+
this._requireReady('removeFavoriteProject')
|
|
1310
|
+
if (!projectId) {
|
|
1311
|
+
throw new Error('Project ID is required')
|
|
1312
|
+
}
|
|
1313
|
+
try {
|
|
1314
|
+
const response = await this._request(`/users/favorites/${projectId}`, {
|
|
1315
|
+
method: 'DELETE',
|
|
1316
|
+
methodName: 'removeFavoriteProject'
|
|
1317
|
+
})
|
|
1318
|
+
|
|
1319
|
+
if (response.success) {
|
|
1320
|
+
return response.message || 'Project removed from favorites'
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
throw new Error(response.message)
|
|
1324
|
+
} catch (error) {
|
|
1325
|
+
throw new Error(`Failed to remove favorite project: ${error.message}`, { cause: error })
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
// ==================== RECENT PROJECT METHODS ====================
|
|
1330
|
+
|
|
1331
|
+
async getRecentProjects (options = {}) {
|
|
1332
|
+
this._requireReady('getRecentProjects')
|
|
1333
|
+
|
|
1334
|
+
const { limit = 20, headers } = options
|
|
1335
|
+
const queryString = new URLSearchParams({
|
|
1336
|
+
limit: limit.toString()
|
|
1337
|
+
}).toString()
|
|
1338
|
+
const url = `/users/projects/recent${queryString ? `?${queryString}` : ''}`
|
|
1339
|
+
|
|
1340
|
+
try {
|
|
1341
|
+
const response = await this._request(url, {
|
|
1342
|
+
method: 'GET',
|
|
1343
|
+
...(headers ? { headers } : {}),
|
|
1344
|
+
methodName: 'getRecentProjects'
|
|
1345
|
+
})
|
|
1346
|
+
|
|
1347
|
+
if (response.success) {
|
|
1348
|
+
// Map icon src similar to other project lists
|
|
1349
|
+
return (response.data || []).map(item => ({
|
|
1350
|
+
...item.project,
|
|
1351
|
+
...(item.project &&
|
|
1352
|
+
item.project.icon && {
|
|
1353
|
+
icon: {
|
|
1354
|
+
src: `${this._apiUrl}/core/files/public/${item.project.icon.id}/download`,
|
|
1355
|
+
...item.project.icon
|
|
1356
|
+
}
|
|
1357
|
+
})
|
|
1358
|
+
}))
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
throw new Error(response.message)
|
|
1362
|
+
} catch (error) {
|
|
1363
|
+
throw new Error(`Failed to get recent projects: ${error.message}`, { cause: error })
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
}
|