@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.
- package/README.md +141 -0
- package/dist/cjs/config/environment.js +94 -10
- package/dist/cjs/index.js +152 -12
- package/dist/cjs/services/AdminService.js +351 -0
- package/dist/cjs/services/AuthService.js +738 -305
- package/dist/cjs/services/BaseService.js +158 -6
- package/dist/cjs/services/BranchService.js +484 -0
- package/dist/cjs/services/CollabService.js +439 -116
- package/dist/cjs/services/DnsService.js +340 -0
- package/dist/cjs/services/FeatureFlagService.js +175 -0
- package/dist/cjs/services/FileService.js +201 -0
- package/dist/cjs/services/IntegrationService.js +538 -0
- package/dist/cjs/services/MetricsService.js +62 -0
- package/dist/cjs/services/PaymentService.js +271 -0
- package/dist/cjs/services/PlanService.js +426 -0
- package/dist/cjs/services/ProjectService.js +1207 -0
- package/dist/cjs/services/PullRequestService.js +503 -0
- package/dist/cjs/services/ScreenshotService.js +304 -0
- package/dist/cjs/services/SubscriptionService.js +396 -0
- package/dist/cjs/services/TrackingService.js +661 -0
- package/dist/cjs/services/WaitlistService.js +148 -0
- package/dist/cjs/services/index.js +60 -4
- package/dist/cjs/state/RootStateManager.js +2 -23
- package/dist/cjs/state/rootEventBus.js +9 -0
- package/dist/cjs/utils/CollabClient.js +78 -12
- package/dist/cjs/utils/TokenManager.js +16 -3
- package/dist/cjs/utils/changePreprocessor.js +199 -0
- package/dist/cjs/utils/jsonDiff.js +46 -4
- package/dist/cjs/utils/ordering.js +309 -0
- package/dist/cjs/utils/services.js +285 -128
- package/dist/cjs/utils/validation.js +0 -3
- package/dist/esm/config/environment.js +94 -10
- package/dist/esm/index.js +47862 -18248
- package/dist/esm/services/AdminService.js +1132 -0
- package/dist/esm/services/AuthService.js +1493 -386
- package/dist/esm/services/BaseService.js +757 -6
- package/dist/esm/services/BranchService.js +1265 -0
- package/dist/esm/services/CollabService.js +24956 -16089
- package/dist/esm/services/DnsService.js +1121 -0
- package/dist/esm/services/FeatureFlagService.js +956 -0
- package/dist/esm/services/FileService.js +982 -0
- package/dist/esm/services/IntegrationService.js +1319 -0
- package/dist/esm/services/MetricsService.js +843 -0
- package/dist/esm/services/PaymentService.js +1052 -0
- package/dist/esm/services/PlanService.js +1207 -0
- package/dist/esm/services/ProjectService.js +2526 -0
- package/dist/esm/services/PullRequestService.js +1284 -0
- package/dist/esm/services/ScreenshotService.js +1085 -0
- package/dist/esm/services/SubscriptionService.js +1177 -0
- package/dist/esm/services/TrackingService.js +18454 -0
- package/dist/esm/services/WaitlistService.js +929 -0
- package/dist/esm/services/index.js +47373 -18027
- package/dist/esm/state/RootStateManager.js +11 -23
- package/dist/esm/state/rootEventBus.js +9 -0
- package/dist/esm/utils/CollabClient.js +17526 -16120
- package/dist/esm/utils/TokenManager.js +16 -3
- package/dist/esm/utils/changePreprocessor.js +542 -0
- package/dist/esm/utils/jsonDiff.js +958 -43
- package/dist/esm/utils/ordering.js +291 -0
- package/dist/esm/utils/services.js +285 -128
- package/dist/esm/utils/validation.js +116 -50
- package/dist/node/config/environment.js +94 -10
- package/dist/node/index.js +183 -16
- package/dist/node/services/AdminService.js +332 -0
- package/dist/node/services/AuthService.js +742 -310
- package/dist/node/services/BaseService.js +148 -6
- package/dist/node/services/BranchService.js +465 -0
- package/dist/node/services/CollabService.js +439 -116
- package/dist/node/services/DnsService.js +321 -0
- package/dist/node/services/FeatureFlagService.js +156 -0
- package/dist/node/services/FileService.js +182 -0
- package/dist/node/services/IntegrationService.js +519 -0
- package/dist/node/services/MetricsService.js +43 -0
- package/dist/node/services/PaymentService.js +252 -0
- package/dist/node/services/PlanService.js +407 -0
- package/dist/node/services/ProjectService.js +1188 -0
- package/dist/node/services/PullRequestService.js +484 -0
- package/dist/node/services/ScreenshotService.js +285 -0
- package/dist/node/services/SubscriptionService.js +377 -0
- package/dist/node/services/TrackingService.js +632 -0
- package/dist/node/services/WaitlistService.js +129 -0
- package/dist/node/services/index.js +60 -4
- package/dist/node/state/RootStateManager.js +2 -23
- package/dist/node/state/rootEventBus.js +9 -0
- package/dist/node/utils/CollabClient.js +77 -11
- package/dist/node/utils/TokenManager.js +16 -3
- package/dist/node/utils/changePreprocessor.js +180 -0
- package/dist/node/utils/jsonDiff.js +46 -4
- package/dist/node/utils/ordering.js +290 -0
- package/dist/node/utils/services.js +285 -128
- package/dist/node/utils/validation.js +0 -3
- package/package.json +30 -18
- package/src/config/environment.js +95 -10
- package/src/index.js +190 -23
- package/src/services/AdminService.js +374 -0
- package/src/services/AuthService.js +874 -328
- package/src/services/BaseService.js +166 -6
- package/src/services/BranchService.js +536 -0
- package/src/services/CollabService.js +557 -148
- package/src/services/DnsService.js +366 -0
- package/src/services/FeatureFlagService.js +174 -0
- package/src/services/FileService.js +213 -0
- package/src/services/IntegrationService.js +548 -0
- package/src/services/MetricsService.js +40 -0
- package/src/services/PaymentService.js +287 -0
- package/src/services/PlanService.js +468 -0
- package/src/services/ProjectService.js +1366 -0
- package/src/services/PullRequestService.js +537 -0
- package/src/services/ScreenshotService.js +258 -0
- package/src/services/SubscriptionService.js +425 -0
- package/src/services/TrackingService.js +853 -0
- package/src/services/WaitlistService.js +130 -0
- package/src/services/index.js +79 -5
- package/src/services/tests/BranchService/createBranch.test.js +153 -0
- package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
- package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
- package/src/services/tests/BranchService/listBranches.test.js +87 -0
- package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
- package/src/services/tests/BranchService/publishVersion.test.js +183 -0
- package/src/services/tests/BranchService/renameBranch.test.js +240 -0
- package/src/services/tests/BranchService/resetBranch.test.js +152 -0
- package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
- package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
- package/src/services/tests/FileService/createFileFormData.test.js +74 -0
- package/src/services/tests/FileService/getFileUrl.test.js +69 -0
- package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
- package/src/services/tests/FileService/uploadDocument.test.js +36 -0
- package/src/services/tests/FileService/uploadFile.test.js +78 -0
- package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
- package/src/services/tests/FileService/uploadImage.test.js +36 -0
- package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
- package/src/services/tests/FileService/validateFile.test.js +63 -0
- package/src/services/tests/PlanService/createPlan.test.js +104 -0
- package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
- package/src/services/tests/PlanService/deletePlan.test.js +92 -0
- package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
- package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
- package/src/services/tests/PlanService/getPlan.test.js +50 -0
- package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
- package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
- package/src/services/tests/PlanService/getPlans.test.js +53 -0
- package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
- package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
- package/src/services/tests/PlanService/initializePlans.test.js +75 -0
- package/src/services/tests/PlanService/updatePlan.test.js +111 -0
- package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
- package/src/state/RootStateManager.js +37 -32
- package/src/state/rootEventBus.js +19 -0
- package/src/utils/CollabClient.js +99 -12
- package/src/utils/TokenManager.js +20 -3
- package/src/utils/changePreprocessor.js +239 -0
- package/src/utils/jsonDiff.js +40 -5
- package/src/utils/ordering.js +271 -0
- package/src/utils/services.js +306 -139
- package/src/utils/validation.js +0 -3
- package/dist/cjs/services/AIService.js +0 -155
- package/dist/cjs/services/BasedService.js +0 -1185
- package/dist/cjs/services/CoreService.js +0 -2295
- package/dist/cjs/services/SocketService.js +0 -309
- package/dist/cjs/services/SymstoryService.js +0 -571
- package/dist/cjs/utils/basedQuerys.js +0 -181
- package/dist/cjs/utils/symstoryClient.js +0 -259
- package/dist/esm/services/AIService.js +0 -185
- package/dist/esm/services/BasedService.js +0 -5262
- package/dist/esm/services/CoreService.js +0 -2827
- package/dist/esm/services/SocketService.js +0 -456
- package/dist/esm/services/SymstoryService.js +0 -7025
- package/dist/esm/utils/basedQuerys.js +0 -163
- package/dist/esm/utils/symstoryClient.js +0 -354
- package/dist/node/services/AIService.js +0 -136
- package/dist/node/services/BasedService.js +0 -1156
- package/dist/node/services/CoreService.js +0 -2266
- package/dist/node/services/SocketService.js +0 -280
- package/dist/node/services/SymstoryService.js +0 -542
- package/dist/node/utils/basedQuerys.js +0 -162
- package/dist/node/utils/symstoryClient.js +0 -230
- package/src/services/AIService.js +0 -150
- package/src/services/BasedService.js +0 -1302
- package/src/services/CoreService.js +0 -2548
- package/src/services/SocketService.js +0 -336
- package/src/services/SymstoryService.js +0 -649
- package/src/utils/basedQuerys.js +0 -164
- package/src/utils/symstoryClient.js +0 -252
|
@@ -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
|
-
};
|