@symbo.ls/sdk 2.34.35 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +2 -143
  2. package/dist/cjs/config/environment.js +30 -98
  3. package/dist/cjs/index.js +24 -144
  4. package/dist/cjs/services/AIService.js +155 -0
  5. package/dist/cjs/services/AuthService.js +305 -738
  6. package/dist/cjs/services/BaseService.js +6 -158
  7. package/dist/cjs/services/BasedService.js +1185 -0
  8. package/dist/cjs/services/CoreService.js +1751 -0
  9. package/dist/cjs/services/SocketIOService.js +307 -0
  10. package/dist/cjs/services/SocketService.js +161 -0
  11. package/dist/cjs/services/SymstoryService.js +571 -0
  12. package/dist/cjs/services/index.js +16 -64
  13. package/dist/cjs/utils/TokenManager.js +30 -78
  14. package/dist/cjs/utils/basedQuerys.js +181 -0
  15. package/dist/cjs/utils/services.js +103 -301
  16. package/dist/cjs/utils/symstoryClient.js +259 -0
  17. package/dist/cjs/utils/validation.js +3 -0
  18. package/dist/esm/config/environment.js +30 -98
  19. package/dist/esm/index.js +8797 -49416
  20. package/dist/esm/services/AIService.js +185 -0
  21. package/dist/esm/services/AuthService.js +386 -1493
  22. package/dist/esm/services/BaseService.js +6 -757
  23. package/dist/esm/services/BasedService.js +5278 -0
  24. package/dist/esm/services/CoreService.js +2264 -0
  25. package/dist/esm/services/SocketIOService.js +470 -0
  26. package/dist/esm/services/SocketService.js +191 -0
  27. package/dist/esm/services/SymstoryService.js +7041 -0
  28. package/dist/esm/services/index.js +8690 -49015
  29. package/dist/esm/utils/TokenManager.js +30 -78
  30. package/dist/esm/utils/basedQuerys.js +163 -0
  31. package/dist/esm/utils/services.js +103 -301
  32. package/dist/esm/utils/symstoryClient.js +370 -0
  33. package/dist/esm/utils/validation.js +7 -4
  34. package/dist/node/config/environment.js +30 -98
  35. package/dist/node/index.js +32 -175
  36. package/dist/node/services/AIService.js +136 -0
  37. package/dist/node/services/AuthService.js +310 -742
  38. package/dist/node/services/BaseService.js +6 -148
  39. package/dist/node/services/BasedService.js +1156 -0
  40. package/dist/node/services/CoreService.js +1722 -0
  41. package/dist/node/services/SocketIOService.js +278 -0
  42. package/dist/node/services/SocketService.js +142 -0
  43. package/dist/node/services/SymstoryService.js +542 -0
  44. package/dist/node/services/index.js +16 -64
  45. package/dist/node/utils/TokenManager.js +30 -78
  46. package/dist/node/utils/basedQuerys.js +162 -0
  47. package/dist/node/utils/services.js +103 -301
  48. package/dist/node/utils/symstoryClient.js +230 -0
  49. package/dist/node/utils/validation.js +3 -0
  50. package/package.json +16 -35
  51. package/src/config/environment.js +28 -99
  52. package/src/index.js +36 -181
  53. package/src/services/AIService.js +150 -0
  54. package/src/services/AuthService.js +328 -874
  55. package/src/services/BaseService.js +6 -166
  56. package/src/services/BasedService.js +1301 -0
  57. package/src/services/CoreService.js +1943 -0
  58. package/src/services/SocketIOService.js +334 -0
  59. package/src/services/SocketService.js +168 -0
  60. package/src/services/SymstoryService.js +649 -0
  61. package/src/services/index.js +13 -80
  62. package/src/utils/TokenManager.js +33 -88
  63. package/src/utils/basedQuerys.js +164 -0
  64. package/src/utils/services.js +107 -326
  65. package/src/utils/symstoryClient.js +252 -0
  66. package/src/utils/validation.js +3 -0
  67. package/dist/cjs/services/AdminService.js +0 -351
  68. package/dist/cjs/services/BranchService.js +0 -484
  69. package/dist/cjs/services/CollabService.js +0 -743
  70. package/dist/cjs/services/DnsService.js +0 -340
  71. package/dist/cjs/services/FeatureFlagService.js +0 -175
  72. package/dist/cjs/services/FileService.js +0 -201
  73. package/dist/cjs/services/IntegrationService.js +0 -538
  74. package/dist/cjs/services/MetricsService.js +0 -62
  75. package/dist/cjs/services/PaymentService.js +0 -271
  76. package/dist/cjs/services/PlanService.js +0 -426
  77. package/dist/cjs/services/ProjectService.js +0 -1207
  78. package/dist/cjs/services/PullRequestService.js +0 -503
  79. package/dist/cjs/services/ScreenshotService.js +0 -304
  80. package/dist/cjs/services/SubscriptionService.js +0 -396
  81. package/dist/cjs/services/TrackingService.js +0 -661
  82. package/dist/cjs/services/WaitlistService.js +0 -148
  83. package/dist/cjs/state/RootStateManager.js +0 -65
  84. package/dist/cjs/state/rootEventBus.js +0 -74
  85. package/dist/cjs/utils/CollabClient.js +0 -223
  86. package/dist/cjs/utils/changePreprocessor.js +0 -199
  87. package/dist/cjs/utils/jsonDiff.js +0 -145
  88. package/dist/cjs/utils/ordering.js +0 -309
  89. package/dist/esm/services/AdminService.js +0 -1132
  90. package/dist/esm/services/BranchService.js +0 -1265
  91. package/dist/esm/services/CollabService.js +0 -26838
  92. package/dist/esm/services/DnsService.js +0 -1121
  93. package/dist/esm/services/FeatureFlagService.js +0 -956
  94. package/dist/esm/services/FileService.js +0 -982
  95. package/dist/esm/services/IntegrationService.js +0 -1319
  96. package/dist/esm/services/MetricsService.js +0 -843
  97. package/dist/esm/services/PaymentService.js +0 -1052
  98. package/dist/esm/services/PlanService.js +0 -1207
  99. package/dist/esm/services/ProjectService.js +0 -2526
  100. package/dist/esm/services/PullRequestService.js +0 -1284
  101. package/dist/esm/services/ScreenshotService.js +0 -1085
  102. package/dist/esm/services/SubscriptionService.js +0 -1177
  103. package/dist/esm/services/TrackingService.js +0 -18343
  104. package/dist/esm/services/WaitlistService.js +0 -929
  105. package/dist/esm/state/RootStateManager.js +0 -90
  106. package/dist/esm/state/rootEventBus.js +0 -56
  107. package/dist/esm/utils/CollabClient.js +0 -18901
  108. package/dist/esm/utils/changePreprocessor.js +0 -542
  109. package/dist/esm/utils/jsonDiff.js +0 -7011
  110. package/dist/esm/utils/ordering.js +0 -291
  111. package/dist/node/services/AdminService.js +0 -332
  112. package/dist/node/services/BranchService.js +0 -465
  113. package/dist/node/services/CollabService.js +0 -724
  114. package/dist/node/services/DnsService.js +0 -321
  115. package/dist/node/services/FeatureFlagService.js +0 -156
  116. package/dist/node/services/FileService.js +0 -182
  117. package/dist/node/services/IntegrationService.js +0 -519
  118. package/dist/node/services/MetricsService.js +0 -43
  119. package/dist/node/services/PaymentService.js +0 -252
  120. package/dist/node/services/PlanService.js +0 -407
  121. package/dist/node/services/ProjectService.js +0 -1188
  122. package/dist/node/services/PullRequestService.js +0 -484
  123. package/dist/node/services/ScreenshotService.js +0 -285
  124. package/dist/node/services/SubscriptionService.js +0 -377
  125. package/dist/node/services/TrackingService.js +0 -632
  126. package/dist/node/services/WaitlistService.js +0 -129
  127. package/dist/node/state/RootStateManager.js +0 -36
  128. package/dist/node/state/rootEventBus.js +0 -55
  129. package/dist/node/utils/CollabClient.js +0 -194
  130. package/dist/node/utils/changePreprocessor.js +0 -180
  131. package/dist/node/utils/jsonDiff.js +0 -116
  132. package/dist/node/utils/ordering.js +0 -290
  133. package/src/services/AdminService.js +0 -374
  134. package/src/services/BranchService.js +0 -536
  135. package/src/services/CollabService.js +0 -900
  136. package/src/services/DnsService.js +0 -366
  137. package/src/services/FeatureFlagService.js +0 -174
  138. package/src/services/FileService.js +0 -213
  139. package/src/services/IntegrationService.js +0 -548
  140. package/src/services/MetricsService.js +0 -40
  141. package/src/services/PaymentService.js +0 -287
  142. package/src/services/PlanService.js +0 -468
  143. package/src/services/ProjectService.js +0 -1366
  144. package/src/services/PullRequestService.js +0 -537
  145. package/src/services/ScreenshotService.js +0 -258
  146. package/src/services/SubscriptionService.js +0 -425
  147. package/src/services/TrackingService.js +0 -853
  148. package/src/services/WaitlistService.js +0 -130
  149. package/src/services/tests/BranchService/createBranch.test.js +0 -153
  150. package/src/services/tests/BranchService/deleteBranch.test.js +0 -173
  151. package/src/services/tests/BranchService/getBranchChanges.test.js +0 -146
  152. package/src/services/tests/BranchService/listBranches.test.js +0 -87
  153. package/src/services/tests/BranchService/mergeBranch.test.js +0 -210
  154. package/src/services/tests/BranchService/publishVersion.test.js +0 -183
  155. package/src/services/tests/BranchService/renameBranch.test.js +0 -240
  156. package/src/services/tests/BranchService/resetBranch.test.js +0 -152
  157. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +0 -67
  158. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +0 -75
  159. package/src/services/tests/FileService/createFileFormData.test.js +0 -74
  160. package/src/services/tests/FileService/getFileUrl.test.js +0 -69
  161. package/src/services/tests/FileService/updateProjectIcon.test.js +0 -109
  162. package/src/services/tests/FileService/uploadDocument.test.js +0 -36
  163. package/src/services/tests/FileService/uploadFile.test.js +0 -78
  164. package/src/services/tests/FileService/uploadFileWithValidation.test.js +0 -114
  165. package/src/services/tests/FileService/uploadImage.test.js +0 -36
  166. package/src/services/tests/FileService/uploadMultipleFiles.test.js +0 -111
  167. package/src/services/tests/FileService/validateFile.test.js +0 -63
  168. package/src/services/tests/PlanService/createPlan.test.js +0 -104
  169. package/src/services/tests/PlanService/createPlanWithValidation.test.js +0 -523
  170. package/src/services/tests/PlanService/deletePlan.test.js +0 -92
  171. package/src/services/tests/PlanService/getActivePlans.test.js +0 -123
  172. package/src/services/tests/PlanService/getAdminPlans.test.js +0 -84
  173. package/src/services/tests/PlanService/getPlan.test.js +0 -50
  174. package/src/services/tests/PlanService/getPlanByKey.test.js +0 -109
  175. package/src/services/tests/PlanService/getPlanWithValidation.test.js +0 -85
  176. package/src/services/tests/PlanService/getPlans.test.js +0 -53
  177. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +0 -109
  178. package/src/services/tests/PlanService/getPlansWithValidation.test.js +0 -48
  179. package/src/services/tests/PlanService/initializePlans.test.js +0 -75
  180. package/src/services/tests/PlanService/updatePlan.test.js +0 -111
  181. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +0 -556
  182. package/src/state/RootStateManager.js +0 -76
  183. package/src/state/rootEventBus.js +0 -67
  184. package/src/utils/CollabClient.js +0 -248
  185. package/src/utils/changePreprocessor.js +0 -239
  186. package/src/utils/jsonDiff.js +0 -144
  187. package/src/utils/ordering.js +0 -271
@@ -0,0 +1,542 @@
1
+ import { BaseService } from "./BaseService.js";
2
+ import symstory from "../utils/symstoryClient.js";
3
+ import * as utils from "@domql/utils";
4
+ import { validateParams } from "../utils/validation.js";
5
+ const { deepStringify, isFunction, isObjectLike } = utils.default || utils;
6
+ class SymstoryService extends BaseService {
7
+ constructor(config) {
8
+ super(config);
9
+ this._client = null;
10
+ this._cache = /* @__PURE__ */ new Map();
11
+ this._state = {};
12
+ this._socketService = this._context.services.socket;
13
+ this._undoStack = [];
14
+ this._redoStack = [];
15
+ }
16
+ async init() {
17
+ var _a, _b;
18
+ try {
19
+ const { appKey, authToken, state, socketUrl } = this._context || {};
20
+ if (!appKey) {
21
+ this._setReady(false);
22
+ return;
23
+ }
24
+ symstory.init(appKey, {
25
+ headers: {
26
+ ...authToken && { Authorization: `Bearer ${authToken}` }
27
+ }
28
+ });
29
+ this._client = symstory.client;
30
+ this._state = this._isObject(state) ? state : {};
31
+ if (socketUrl) {
32
+ await this._socketService.init();
33
+ }
34
+ this._info = {
35
+ config: {
36
+ appKey: `${appKey.substr(0, 4)}...${appKey.substr(-4)}`,
37
+ hasToken: Boolean(authToken),
38
+ hasState: Boolean(state),
39
+ hasSocket: this._socketService._socket !== null,
40
+ socketStatus: ((_b = (_a = this._socketService._info) == null ? void 0 : _a.config) == null ? void 0 : _b.status) || "disconnected",
41
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
42
+ }
43
+ };
44
+ this._setReady();
45
+ } catch (error) {
46
+ this._setError(error);
47
+ throw error;
48
+ }
49
+ }
50
+ // publish a new version
51
+ async publish({ version, type = "minor" } = {}) {
52
+ if (version) {
53
+ await this._client.publishVersion(version, { type });
54
+ } else {
55
+ await this.updateData([], { type });
56
+ }
57
+ }
58
+ // get changes between versions
59
+ async getChanges({ versionId, versionValue, branch } = {}) {
60
+ return this._client.getChanges({ versionId, versionValue, branch });
61
+ }
62
+ safeStringify(obj) {
63
+ const seen = /* @__PURE__ */ new WeakSet();
64
+ return JSON.stringify(obj, (key, value) => {
65
+ if (typeof value === "object" && value !== null) {
66
+ if (seen.has(value)) {
67
+ return;
68
+ }
69
+ seen.add(value);
70
+ }
71
+ return value;
72
+ });
73
+ }
74
+ // Update project data
75
+ async updateData(changes, options = {}, callback) {
76
+ var _a;
77
+ this._requireReady();
78
+ const {
79
+ type = "patch",
80
+ message = "",
81
+ branch = ((_a = this._context.symstory) == null ? void 0 : _a.branch) || "main",
82
+ fromSocket = false,
83
+ quietUpdate = false,
84
+ isUndo,
85
+ isRedo
86
+ } = options;
87
+ try {
88
+ const { state } = this._context;
89
+ if ("isOld" in state && state.isOld) {
90
+ return;
91
+ }
92
+ const updates = changes.map((change) => ({
93
+ change,
94
+ prev: state == null ? void 0 : state.getByPath(change[1])
95
+ }));
96
+ if (state && "setPathCollection" in state && !quietUpdate) {
97
+ await state.setPathCollection(changes, {
98
+ preventUpdate: true,
99
+ ...options
100
+ });
101
+ }
102
+ const filteredUpdates = updates.filter(({ change, prev }) => {
103
+ if (change && change.err) {
104
+ delete change.err;
105
+ }
106
+ if (prev && prev.err) {
107
+ delete prev.err;
108
+ }
109
+ return (
110
+ // eslint-disable-next-line no-undefined
111
+ change[3] !== void 0 || this.safeStringify(change[2]) !== this.safeStringify(prev)
112
+ );
113
+ });
114
+ if (!fromSocket && !isUndo) {
115
+ if (!isRedo) {
116
+ this._redoStack.length = 0;
117
+ }
118
+ this._undoStack.push({
119
+ updates: filteredUpdates,
120
+ options,
121
+ time: /* @__PURE__ */ new Date()
122
+ });
123
+ }
124
+ if (fromSocket) {
125
+ return;
126
+ }
127
+ const stringifiedData = changes.map(([action, path, change]) => {
128
+ if (isFunction(change)) {
129
+ return [action, path, (change == null ? void 0 : change.toString()) ?? change];
130
+ }
131
+ if (change && change.err) {
132
+ delete change.err;
133
+ }
134
+ return [
135
+ action,
136
+ path,
137
+ isObjectLike(change) ? deepStringify(change, Array.isArray(change) ? [] : {}) : change
138
+ ];
139
+ });
140
+ const res = await this._context.services.core.applyProjectChanges(
141
+ state.projectId,
142
+ stringifiedData,
143
+ {
144
+ type,
145
+ message,
146
+ branch
147
+ }
148
+ );
149
+ if (this._socketService._socket) {
150
+ this._socketService.send("change", {
151
+ type: "update",
152
+ changes: stringifiedData,
153
+ version: res == null ? void 0 : res.value
154
+ });
155
+ }
156
+ if (res == null ? void 0 : res.value) {
157
+ this._context.symstory = {
158
+ ...this._context.symstory,
159
+ version: res.value
160
+ };
161
+ if (state && "quietUpdate" in state) {
162
+ const { isVersionsOpen } = state;
163
+ if (isVersionsOpen) {
164
+ state.quietUpdate({ version: res.value });
165
+ } else {
166
+ state.version = res.value;
167
+ }
168
+ }
169
+ this._cache.clear();
170
+ }
171
+ if ("__element" in this._state && isFunction(callback)) {
172
+ await callback.call(this._state.__element, changes, res);
173
+ }
174
+ return res;
175
+ } catch (error) {
176
+ if (isFunction(callback)) {
177
+ callback(error);
178
+ }
179
+ throw new Error(`Failed to update data: ${error.message}`);
180
+ }
181
+ }
182
+ async undo() {
183
+ if (!this._undoStack.length) {
184
+ throw new Error("Nothing to undo");
185
+ }
186
+ const { updates, options } = this._undoStack.pop();
187
+ const changes = updates.map(({ change, prev }) => [
188
+ change[0],
189
+ change[1],
190
+ prev
191
+ ]);
192
+ this._redoStack.push({
193
+ updates: updates.map(({ change, prev }) => ({
194
+ change: [change[0], change[1], prev],
195
+ prev: change[2]
196
+ })),
197
+ options
198
+ });
199
+ await this.updateData(
200
+ changes,
201
+ { ...options, isUndo: true, message: `Undo: ${options.message || ""}` },
202
+ () => changes
203
+ );
204
+ return changes;
205
+ }
206
+ async redo() {
207
+ if (!this._redoStack.length) {
208
+ throw new Error("Nothing to redo");
209
+ }
210
+ const { updates, options } = this._redoStack.pop();
211
+ const changes = updates.map(({ change, prev }) => [
212
+ change[0],
213
+ change[1],
214
+ prev
215
+ ]);
216
+ await this.updateData(
217
+ changes,
218
+ { ...options, isRedo: true, message: `Redo: ${options.message || ""}` },
219
+ () => changes
220
+ );
221
+ return changes;
222
+ }
223
+ // Delete project data
224
+ async deleteData(path, options = {}, callback) {
225
+ this._requireReady();
226
+ try {
227
+ const changes = [["delete", path]];
228
+ return await this.updateData(changes, options, callback);
229
+ } catch (error) {
230
+ throw new Error(`Failed to delete data: ${error.message}`);
231
+ }
232
+ }
233
+ // Get project data
234
+ async getData(query, options = {}) {
235
+ var _a, _b, _c;
236
+ this._requireReady();
237
+ try {
238
+ const {
239
+ branch = ((_a = this._context.symstory) == null ? void 0 : _a.branch) || "main",
240
+ version = (_b = this._context.symstory) == null ? void 0 : _b.version,
241
+ bypassCache = false,
242
+ timeout = 3e4
243
+ } = options;
244
+ const cacheKey = !bypassCache && this._generateCacheKey(query, branch, version);
245
+ if (!bypassCache && cacheKey && this._cache.has(cacheKey)) {
246
+ return this._cache.get(cacheKey);
247
+ }
248
+ if (query && typeof query === "object") {
249
+ if (!query.$find && !query.$filter) {
250
+ throw new Error(
251
+ "Invalid query structure. Must include $find or $filter."
252
+ );
253
+ }
254
+ }
255
+ const controller = new AbortController();
256
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
257
+ try {
258
+ const result = await this._client.get(query, branch, version);
259
+ if (!bypassCache && cacheKey) {
260
+ (_c = this._cache) == null ? void 0 : _c.set(cacheKey, result);
261
+ }
262
+ return result;
263
+ } finally {
264
+ clearTimeout(timeoutId);
265
+ }
266
+ } catch (error) {
267
+ if (error.name === "AbortError") {
268
+ throw new Error(`Request timed out after ${options.timeout}ms`);
269
+ }
270
+ throw new Error(`Failed to get data: ${error.message}`);
271
+ }
272
+ }
273
+ // Helper method to check if a variable is a valid object
274
+ _isObject(variable) {
275
+ return variable !== null && typeof variable === "object" && !Array.isArray(variable);
276
+ }
277
+ // Helper method to generate cache key
278
+ _generateCacheKey(query, branch, version) {
279
+ if (!query) {
280
+ return null;
281
+ }
282
+ return JSON.stringify({
283
+ query,
284
+ branch,
285
+ version
286
+ });
287
+ }
288
+ // Helper method to clear cache
289
+ clearCache() {
290
+ this._cache.clear();
291
+ }
292
+ // Helper method to remove specific cache entry
293
+ removeCacheEntry(query, branch, version) {
294
+ const cacheKey = this._generateCacheKey(query, branch, version);
295
+ if (cacheKey) {
296
+ this._cache.delete(cacheKey);
297
+ }
298
+ }
299
+ // Branch Management
300
+ async getBranches() {
301
+ this._requireReady();
302
+ try {
303
+ return await this._client.getBranches();
304
+ } catch (error) {
305
+ throw new Error(`Failed to get branches: ${error.message}`);
306
+ }
307
+ }
308
+ async createBranch(branch, options = {}) {
309
+ this._requireReady();
310
+ if (!branch) {
311
+ throw new Error("Branch name is required.");
312
+ }
313
+ try {
314
+ return await this._client.createBranch(branch, options);
315
+ } catch (error) {
316
+ throw new Error(`Failed to create branch: ${error.message}`);
317
+ }
318
+ }
319
+ async editBranch(branch, options = {}) {
320
+ this._requireReady();
321
+ if (!branch) {
322
+ throw new Error("Branch name is required.");
323
+ }
324
+ try {
325
+ return await this._client.editBranch(branch, options);
326
+ } catch (error) {
327
+ throw new Error(`Failed to edit branch: ${error.message}`);
328
+ }
329
+ }
330
+ async deleteBranch(branch) {
331
+ this._requireReady();
332
+ if (!branch) {
333
+ throw new Error("Branch name is required.");
334
+ }
335
+ try {
336
+ return await this._client.deleteBranch(branch);
337
+ } catch (error) {
338
+ throw new Error(`Failed to delete branch: ${error.message}`);
339
+ }
340
+ }
341
+ async mergeBranch(branch, options = {}) {
342
+ this._requireReady();
343
+ if (!branch) {
344
+ throw new Error("Branch name is required.");
345
+ }
346
+ try {
347
+ return await this._client.mergeBranch(branch, options);
348
+ } catch (error) {
349
+ throw new Error(`Failed to merge branch: ${error.message}`);
350
+ }
351
+ }
352
+ async restoreVersion(version, options = {}) {
353
+ var _a, _b;
354
+ this._requireReady();
355
+ const { branch = (_a = this._context.symstory) == null ? void 0 : _a.branch } = options;
356
+ version ||= (_b = this._context.symstory) == null ? void 0 : _b.version;
357
+ try {
358
+ return await this._client.restoreVersion(version, { ...options, branch });
359
+ } catch (error) {
360
+ throw new Error(`Failed to restore version: ${error.message}`);
361
+ }
362
+ }
363
+ // Cleanup
364
+ destroy() {
365
+ this._client = null;
366
+ this._setReady(false);
367
+ }
368
+ // Data management methods
369
+ async getItem(query, options = {}) {
370
+ this._requireReady();
371
+ try {
372
+ return await this.getData(query, options);
373
+ } catch (error) {
374
+ throw new Error(`Failed to get item: ${error.message}`);
375
+ }
376
+ }
377
+ async addItem(type, data, options = {}, callback) {
378
+ this._requireReady();
379
+ try {
380
+ validateParams.type(type);
381
+ validateParams.data(data, type);
382
+ const { value, ...schema } = data;
383
+ return await this.updateData(
384
+ [
385
+ ["update", [type, data.key], value],
386
+ ["update", ["schema", type, data.key], schema],
387
+ ...options.additionalChanges || []
388
+ ],
389
+ {
390
+ message: `Created ${data.key} in ${type}`,
391
+ ...options
392
+ },
393
+ isFunction(options) ? options : callback
394
+ );
395
+ } catch (error) {
396
+ throw new Error(`Failed to add item: ${error.message}`);
397
+ }
398
+ }
399
+ async addMultipleItems(items, options = {}, callback) {
400
+ this._requireReady();
401
+ const updateData = [];
402
+ items.forEach((item) => {
403
+ const [type, data] = item;
404
+ const { value, ...schema } = data;
405
+ validateParams.type(type);
406
+ validateParams.data(data, type);
407
+ updateData.push(
408
+ ["update", [type, data.key], value],
409
+ ["update", ["schema", type, data.key], schema]
410
+ );
411
+ });
412
+ try {
413
+ return await this.updateData(
414
+ [...updateData, ...options.additionalChanges || []],
415
+ {
416
+ message: `Created ${updateData.length} items`,
417
+ ...options
418
+ },
419
+ isFunction(options) ? options : callback
420
+ );
421
+ } catch (error) {
422
+ throw new Error(`Failed to add item: ${error.message}`);
423
+ }
424
+ }
425
+ async updateItem(type, data, options = {}, callback) {
426
+ this._requireReady();
427
+ try {
428
+ validateParams.type(type);
429
+ validateParams.data(data, type);
430
+ const { value, ...schema } = data;
431
+ return await this.updateData(
432
+ [
433
+ ["update", [type, data.key], value],
434
+ ["update", ["schema", type, data.key], schema]
435
+ ],
436
+ {
437
+ message: `Updated ${data.key} in ${type}`,
438
+ ...options
439
+ },
440
+ isFunction(options) ? options : callback
441
+ );
442
+ } catch (error) {
443
+ throw new Error(`Failed to update item: ${error.message}`);
444
+ }
445
+ }
446
+ async set(path, value, options = {}, callback) {
447
+ this._requireReady();
448
+ if (!utils.isUndefined(path) || utils.isUndefined(value)) {
449
+ return new Error(`Path ${path} or ${value} value is not defined`);
450
+ }
451
+ try {
452
+ return await this.updateData(
453
+ [["update", path, value]],
454
+ {
455
+ message: `Updated ${utils.isArray(path) ? path.join(".") : path}`,
456
+ ...options
457
+ },
458
+ isFunction(options) ? options : callback
459
+ );
460
+ } catch (error) {
461
+ throw new Error(`Failed to update item: ${error.message}`);
462
+ }
463
+ }
464
+ async deleteItem(type, key, options = {}, callback) {
465
+ this._requireReady();
466
+ try {
467
+ validateParams.type(type);
468
+ validateParams.key(key, type);
469
+ return await this.updateData(
470
+ [
471
+ ["delete", [type, key]],
472
+ ["delete", ["schema", type, key]],
473
+ ...options.additionalChanges || []
474
+ ],
475
+ {
476
+ message: `Deleted ${key} from ${type}`,
477
+ ...options
478
+ },
479
+ isFunction(options) ? options : callback
480
+ );
481
+ } catch (error) {
482
+ throw new Error(`Failed to delete item: ${error.message}`);
483
+ }
484
+ }
485
+ // Helper methods
486
+ _createQuery(filters = []) {
487
+ return {
488
+ $find: {
489
+ $traverse: "children",
490
+ $filter: filters.filter(Boolean).map(([field, operator, value]) => ({
491
+ $field: field,
492
+ $operator: operator,
493
+ $value: value
494
+ }))
495
+ }
496
+ };
497
+ }
498
+ _checkRequiredContext() {
499
+ var _a, _b;
500
+ return Boolean(
501
+ ((_a = this._context) == null ? void 0 : _a.appKey) && ((_b = this._context) == null ? void 0 : _b.authToken) && this._client
502
+ );
503
+ }
504
+ isReady() {
505
+ if (this._checkRequiredContext()) {
506
+ this._setReady(true);
507
+ }
508
+ return this._ready;
509
+ }
510
+ async switchBranch(branch) {
511
+ this._requireReady();
512
+ try {
513
+ this.updateContext({
514
+ symstory: {
515
+ ...this._context.symstory,
516
+ branch,
517
+ version: null
518
+ }
519
+ });
520
+ return await this.getData();
521
+ } catch (error) {
522
+ throw new Error(`Failed to switch branch: ${error.message}`);
523
+ }
524
+ }
525
+ async switchVersion(version) {
526
+ this._requireReady();
527
+ try {
528
+ this.updateContext({
529
+ symstory: {
530
+ ...this._context.symstory,
531
+ version
532
+ }
533
+ });
534
+ return await this.getData();
535
+ } catch (error) {
536
+ throw new Error(`Failed to switch version: ${error.message}`);
537
+ }
538
+ }
539
+ }
540
+ export {
541
+ SymstoryService
542
+ };
@@ -1,71 +1,23 @@
1
+ import { SymstoryService } from "./SymstoryService.js";
1
2
  import { AuthService } from "./AuthService.js";
2
- import { CollabService } from "./CollabService.js";
3
- import { ProjectService } from "./ProjectService.js";
4
- import { PlanService } from "./PlanService.js";
5
- import { SubscriptionService } from "./SubscriptionService.js";
6
- import { FileService } from "./FileService.js";
7
- import { PaymentService } from "./PaymentService.js";
8
- import { DnsService } from "./DnsService.js";
9
- import { BranchService } from "./BranchService.js";
10
- import { PullRequestService } from "./PullRequestService.js";
11
- import { AdminService } from "./AdminService.js";
12
- import { ScreenshotService } from "./ScreenshotService.js";
13
- import { TrackingService } from "./TrackingService.js";
14
- import { WaitlistService } from "./WaitlistService.js";
15
- import { MetricsService } from "./MetricsService.js";
16
- import { IntegrationService } from "./IntegrationService.js";
17
- import { FeatureFlagService } from "./FeatureFlagService.js";
3
+ import { AIService } from "./AIService.js";
4
+ import { SocketService } from "./SocketIOService.js";
5
+ import { CoreService } from "./CoreService.js";
18
6
  const createService = (ServiceClass, config) => new ServiceClass(config);
7
+ const createSymstoryService = (config) => createService(SymstoryService, config);
19
8
  const createAuthService = (config) => createService(AuthService, config);
20
- const createCollabService = (config) => createService(CollabService, config);
21
- const createProjectService = (config) => createService(ProjectService, config);
22
- const createPlanService = (config) => createService(PlanService, config);
23
- const createSubscriptionService = (config) => createService(SubscriptionService, config);
24
- const createFileService = (config) => createService(FileService, config);
25
- const createPaymentService = (config) => createService(PaymentService, config);
26
- const createDnsService = (config) => createService(DnsService, config);
27
- const createBranchService = (config) => createService(BranchService, config);
28
- const createPullRequestService = (config) => createService(PullRequestService, config);
29
- const createAdminService = (config) => createService(AdminService, config);
30
- const createScreenshotService = (config) => createService(ScreenshotService, config);
31
- const createTrackingService = (config) => createService(TrackingService, config);
32
- const createWaitlistService = (config) => createService(WaitlistService, config);
33
- const createMetricsService = (config) => createService(MetricsService, config);
34
- const createIntegrationService = (config) => createService(IntegrationService, config);
35
- const createFeatureFlagService = (config) => createService(FeatureFlagService, config);
9
+ const createAIService = (config) => createService(AIService, config);
10
+ const createSocketService = (config) => createService(SocketService, config);
11
+ const createCoreService = (config) => createService(CoreService, config);
36
12
  export {
37
- AdminService,
13
+ AIService,
38
14
  AuthService,
39
- BranchService,
40
- CollabService,
41
- DnsService,
42
- FeatureFlagService,
43
- FileService,
44
- IntegrationService,
45
- MetricsService,
46
- PaymentService,
47
- PlanService,
48
- ProjectService,
49
- PullRequestService,
50
- ScreenshotService,
51
- SubscriptionService,
52
- TrackingService,
53
- WaitlistService,
54
- createAdminService,
15
+ CoreService,
16
+ SocketService,
17
+ SymstoryService,
18
+ createAIService,
55
19
  createAuthService,
56
- createBranchService,
57
- createCollabService,
58
- createDnsService,
59
- createFeatureFlagService,
60
- createFileService,
61
- createIntegrationService,
62
- createMetricsService,
63
- createPaymentService,
64
- createPlanService,
65
- createProjectService,
66
- createPullRequestService,
67
- createScreenshotService,
68
- createSubscriptionService,
69
- createTrackingService,
70
- createWaitlistService
20
+ createCoreService,
21
+ createSocketService,
22
+ createSymstoryService
71
23
  };