@symbo.ls/sdk 3.2.3 → 3.2.6

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
@@ -1,542 +0,0 @@
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,162 +0,0 @@
1
- const buildProjectQuery = (projectId) => ({
2
- $id: projectId,
3
- $all: true,
4
- createdAt: true,
5
- updatedAt: true,
6
- package: true,
7
- schema: true,
8
- bucket: true,
9
- settings: true,
10
- tier: true,
11
- members: {
12
- $list: { $inherit: true },
13
- id: true,
14
- name: true,
15
- username: true,
16
- email: true,
17
- state: true,
18
- roles: {
19
- $list: { $inherit: true },
20
- $all: true
21
- }
22
- },
23
- users: {
24
- $list: { $inherit: true },
25
- $all: true
26
- }
27
- });
28
- const buildUserQuery = (userId) => ({
29
- $id: userId,
30
- name: true,
31
- username: true,
32
- email: true,
33
- state: true,
34
- roles: {
35
- $list: { $inherit: true },
36
- $all: true
37
- }
38
- });
39
- const buildGetUserDataQuery = (userId) => ({
40
- $id: userId,
41
- id: true,
42
- name: true,
43
- email: true,
44
- username: true,
45
- globalRole: true,
46
- updatedAt: true,
47
- createdAt: true,
48
- memberProjects: {
49
- $list: true,
50
- id: true,
51
- role: true,
52
- createdAt: true,
53
- updatedAt: true,
54
- project: {
55
- id: true,
56
- key: true,
57
- name: true,
58
- thumbnail: true,
59
- icon: true,
60
- tier: true,
61
- visibility: true,
62
- access: true,
63
- members: {
64
- $list: true,
65
- user: {
66
- id: true,
67
- name: true,
68
- email: true,
69
- globalRole: true
70
- },
71
- role: true,
72
- updatedAt: true,
73
- createdAt: true
74
- }
75
- }
76
- }
77
- });
78
- const buildGetProjectsByKeysQuery = (keys) => ({
79
- projects: {
80
- id: true,
81
- key: true,
82
- name: true,
83
- thumbnail: true,
84
- icon: true,
85
- tier: true,
86
- visibility: true,
87
- access: true,
88
- members: {
89
- $list: true,
90
- user: {
91
- id: true,
92
- name: true,
93
- email: true,
94
- globalRole: true
95
- },
96
- role: true,
97
- updatedAt: true,
98
- createdAt: true
99
- },
100
- $list: {
101
- $find: {
102
- $traverse: "children",
103
- $filter: [
104
- { $field: "type", $operator: "=", $value: "project" },
105
- { $field: "key", $operator: "=", $value: keys }
106
- ]
107
- }
108
- }
109
- }
110
- });
111
- const GetProjectFields = {
112
- id: true,
113
- name: true,
114
- key: true,
115
- tier: true,
116
- projectType: true,
117
- icon: true,
118
- package: true,
119
- seats: true,
120
- projectPassword: true,
121
- stripe: true,
122
- payments: {
123
- $list: true,
124
- id: true,
125
- name: true
126
- },
127
- access: true,
128
- isSharedLibrary: true,
129
- framework: true,
130
- designTool: true,
131
- language: true,
132
- visibility: true,
133
- domains: true,
134
- subscription: { id: true },
135
- members: {
136
- $list: true,
137
- user: { id: true, name: true, email: true },
138
- role: true
139
- }
140
- };
141
- const buildGetProjectDataQuery = (projectId) => ({
142
- $id: projectId,
143
- ...GetProjectFields
144
- });
145
- const buildGetProjectByKeyDataQuery = (key) => ({
146
- ...GetProjectFields,
147
- $find: {
148
- $traverse: "children",
149
- $filter: [
150
- { $field: "type", $operator: "=", $value: "project" },
151
- { $field: "key", $operator: "=", $value: key }
152
- ]
153
- }
154
- });
155
- export {
156
- buildGetProjectByKeyDataQuery,
157
- buildGetProjectDataQuery,
158
- buildGetProjectsByKeysQuery,
159
- buildGetUserDataQuery,
160
- buildProjectQuery,
161
- buildUserQuery
162
- };