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