@symbo.ls/sdk 3.2.3 → 3.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +141 -0
- package/dist/cjs/config/environment.js +94 -10
- package/dist/cjs/index.js +152 -12
- package/dist/cjs/services/AdminService.js +351 -0
- package/dist/cjs/services/AuthService.js +738 -305
- package/dist/cjs/services/BaseService.js +158 -6
- package/dist/cjs/services/BranchService.js +484 -0
- package/dist/cjs/services/CollabService.js +439 -116
- package/dist/cjs/services/DnsService.js +340 -0
- package/dist/cjs/services/FeatureFlagService.js +175 -0
- package/dist/cjs/services/FileService.js +201 -0
- package/dist/cjs/services/IntegrationService.js +538 -0
- package/dist/cjs/services/MetricsService.js +62 -0
- package/dist/cjs/services/PaymentService.js +271 -0
- package/dist/cjs/services/PlanService.js +426 -0
- package/dist/cjs/services/ProjectService.js +1207 -0
- package/dist/cjs/services/PullRequestService.js +503 -0
- package/dist/cjs/services/ScreenshotService.js +304 -0
- package/dist/cjs/services/SubscriptionService.js +396 -0
- package/dist/cjs/services/TrackingService.js +661 -0
- package/dist/cjs/services/WaitlistService.js +148 -0
- package/dist/cjs/services/index.js +60 -4
- package/dist/cjs/state/RootStateManager.js +2 -23
- package/dist/cjs/state/rootEventBus.js +9 -0
- package/dist/cjs/utils/CollabClient.js +78 -12
- package/dist/cjs/utils/TokenManager.js +16 -3
- package/dist/cjs/utils/changePreprocessor.js +199 -0
- package/dist/cjs/utils/jsonDiff.js +46 -4
- package/dist/cjs/utils/ordering.js +309 -0
- package/dist/cjs/utils/services.js +285 -128
- package/dist/cjs/utils/validation.js +0 -3
- package/dist/esm/config/environment.js +94 -10
- package/dist/esm/index.js +47862 -18248
- package/dist/esm/services/AdminService.js +1132 -0
- package/dist/esm/services/AuthService.js +1493 -386
- package/dist/esm/services/BaseService.js +757 -6
- package/dist/esm/services/BranchService.js +1265 -0
- package/dist/esm/services/CollabService.js +24956 -16089
- package/dist/esm/services/DnsService.js +1121 -0
- package/dist/esm/services/FeatureFlagService.js +956 -0
- package/dist/esm/services/FileService.js +982 -0
- package/dist/esm/services/IntegrationService.js +1319 -0
- package/dist/esm/services/MetricsService.js +843 -0
- package/dist/esm/services/PaymentService.js +1052 -0
- package/dist/esm/services/PlanService.js +1207 -0
- package/dist/esm/services/ProjectService.js +2526 -0
- package/dist/esm/services/PullRequestService.js +1284 -0
- package/dist/esm/services/ScreenshotService.js +1085 -0
- package/dist/esm/services/SubscriptionService.js +1177 -0
- package/dist/esm/services/TrackingService.js +18454 -0
- package/dist/esm/services/WaitlistService.js +929 -0
- package/dist/esm/services/index.js +47373 -18027
- package/dist/esm/state/RootStateManager.js +11 -23
- package/dist/esm/state/rootEventBus.js +9 -0
- package/dist/esm/utils/CollabClient.js +17526 -16120
- package/dist/esm/utils/TokenManager.js +16 -3
- package/dist/esm/utils/changePreprocessor.js +542 -0
- package/dist/esm/utils/jsonDiff.js +958 -43
- package/dist/esm/utils/ordering.js +291 -0
- package/dist/esm/utils/services.js +285 -128
- package/dist/esm/utils/validation.js +116 -50
- package/dist/node/config/environment.js +94 -10
- package/dist/node/index.js +183 -16
- package/dist/node/services/AdminService.js +332 -0
- package/dist/node/services/AuthService.js +742 -310
- package/dist/node/services/BaseService.js +148 -6
- package/dist/node/services/BranchService.js +465 -0
- package/dist/node/services/CollabService.js +439 -116
- package/dist/node/services/DnsService.js +321 -0
- package/dist/node/services/FeatureFlagService.js +156 -0
- package/dist/node/services/FileService.js +182 -0
- package/dist/node/services/IntegrationService.js +519 -0
- package/dist/node/services/MetricsService.js +43 -0
- package/dist/node/services/PaymentService.js +252 -0
- package/dist/node/services/PlanService.js +407 -0
- package/dist/node/services/ProjectService.js +1188 -0
- package/dist/node/services/PullRequestService.js +484 -0
- package/dist/node/services/ScreenshotService.js +285 -0
- package/dist/node/services/SubscriptionService.js +377 -0
- package/dist/node/services/TrackingService.js +632 -0
- package/dist/node/services/WaitlistService.js +129 -0
- package/dist/node/services/index.js +60 -4
- package/dist/node/state/RootStateManager.js +2 -23
- package/dist/node/state/rootEventBus.js +9 -0
- package/dist/node/utils/CollabClient.js +77 -11
- package/dist/node/utils/TokenManager.js +16 -3
- package/dist/node/utils/changePreprocessor.js +180 -0
- package/dist/node/utils/jsonDiff.js +46 -4
- package/dist/node/utils/ordering.js +290 -0
- package/dist/node/utils/services.js +285 -128
- package/dist/node/utils/validation.js +0 -3
- package/package.json +30 -18
- package/src/config/environment.js +95 -10
- package/src/index.js +190 -23
- package/src/services/AdminService.js +374 -0
- package/src/services/AuthService.js +874 -328
- package/src/services/BaseService.js +166 -6
- package/src/services/BranchService.js +536 -0
- package/src/services/CollabService.js +557 -148
- package/src/services/DnsService.js +366 -0
- package/src/services/FeatureFlagService.js +174 -0
- package/src/services/FileService.js +213 -0
- package/src/services/IntegrationService.js +548 -0
- package/src/services/MetricsService.js +40 -0
- package/src/services/PaymentService.js +287 -0
- package/src/services/PlanService.js +468 -0
- package/src/services/ProjectService.js +1366 -0
- package/src/services/PullRequestService.js +537 -0
- package/src/services/ScreenshotService.js +258 -0
- package/src/services/SubscriptionService.js +425 -0
- package/src/services/TrackingService.js +853 -0
- package/src/services/WaitlistService.js +130 -0
- package/src/services/index.js +79 -5
- package/src/services/tests/BranchService/createBranch.test.js +153 -0
- package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
- package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
- package/src/services/tests/BranchService/listBranches.test.js +87 -0
- package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
- package/src/services/tests/BranchService/publishVersion.test.js +183 -0
- package/src/services/tests/BranchService/renameBranch.test.js +240 -0
- package/src/services/tests/BranchService/resetBranch.test.js +152 -0
- package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
- package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
- package/src/services/tests/FileService/createFileFormData.test.js +74 -0
- package/src/services/tests/FileService/getFileUrl.test.js +69 -0
- package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
- package/src/services/tests/FileService/uploadDocument.test.js +36 -0
- package/src/services/tests/FileService/uploadFile.test.js +78 -0
- package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
- package/src/services/tests/FileService/uploadImage.test.js +36 -0
- package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
- package/src/services/tests/FileService/validateFile.test.js +63 -0
- package/src/services/tests/PlanService/createPlan.test.js +104 -0
- package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
- package/src/services/tests/PlanService/deletePlan.test.js +92 -0
- package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
- package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
- package/src/services/tests/PlanService/getPlan.test.js +50 -0
- package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
- package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
- package/src/services/tests/PlanService/getPlans.test.js +53 -0
- package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
- package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
- package/src/services/tests/PlanService/initializePlans.test.js +75 -0
- package/src/services/tests/PlanService/updatePlan.test.js +111 -0
- package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
- package/src/state/RootStateManager.js +37 -32
- package/src/state/rootEventBus.js +19 -0
- package/src/utils/CollabClient.js +99 -12
- package/src/utils/TokenManager.js +20 -3
- package/src/utils/changePreprocessor.js +239 -0
- package/src/utils/jsonDiff.js +40 -5
- package/src/utils/ordering.js +271 -0
- package/src/utils/services.js +306 -139
- package/src/utils/validation.js +0 -3
- package/dist/cjs/services/AIService.js +0 -155
- package/dist/cjs/services/BasedService.js +0 -1185
- package/dist/cjs/services/CoreService.js +0 -2295
- package/dist/cjs/services/SocketService.js +0 -309
- package/dist/cjs/services/SymstoryService.js +0 -571
- package/dist/cjs/utils/basedQuerys.js +0 -181
- package/dist/cjs/utils/symstoryClient.js +0 -259
- package/dist/esm/services/AIService.js +0 -185
- package/dist/esm/services/BasedService.js +0 -5262
- package/dist/esm/services/CoreService.js +0 -2827
- package/dist/esm/services/SocketService.js +0 -456
- package/dist/esm/services/SymstoryService.js +0 -7025
- package/dist/esm/utils/basedQuerys.js +0 -163
- package/dist/esm/utils/symstoryClient.js +0 -354
- package/dist/node/services/AIService.js +0 -136
- package/dist/node/services/BasedService.js +0 -1156
- package/dist/node/services/CoreService.js +0 -2266
- package/dist/node/services/SocketService.js +0 -280
- package/dist/node/services/SymstoryService.js +0 -542
- package/dist/node/utils/basedQuerys.js +0 -162
- package/dist/node/utils/symstoryClient.js +0 -230
- package/src/services/AIService.js +0 -150
- package/src/services/BasedService.js +0 -1302
- package/src/services/CoreService.js +0 -2548
- package/src/services/SocketService.js +0 -336
- package/src/services/SymstoryService.js +0 -649
- package/src/utils/basedQuerys.js +0 -164
- package/src/utils/symstoryClient.js +0 -252
|
@@ -1,2295 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var CoreService_exports = {};
|
|
29
|
-
__export(CoreService_exports, {
|
|
30
|
-
CoreService: () => CoreService
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(CoreService_exports);
|
|
33
|
-
var import_BaseService = require("./BaseService.js");
|
|
34
|
-
var import_environment = __toESM(require("../config/environment.js"), 1);
|
|
35
|
-
var import_TokenManager = require("../utils/TokenManager.js");
|
|
36
|
-
class CoreService extends import_BaseService.BaseService {
|
|
37
|
-
constructor(config) {
|
|
38
|
-
super(config);
|
|
39
|
-
this._client = null;
|
|
40
|
-
this._initialized = false;
|
|
41
|
-
this._apiUrl = null;
|
|
42
|
-
this._tokenManager = null;
|
|
43
|
-
}
|
|
44
|
-
init({ context }) {
|
|
45
|
-
try {
|
|
46
|
-
const { appKey, authToken } = context || this._context;
|
|
47
|
-
this._apiUrl = import_environment.default.apiUrl;
|
|
48
|
-
if (!this._apiUrl) {
|
|
49
|
-
throw new Error("Core service base URL not configured");
|
|
50
|
-
}
|
|
51
|
-
this._tokenManager = (0, import_TokenManager.getTokenManager)({
|
|
52
|
-
apiUrl: this._apiUrl,
|
|
53
|
-
onTokenRefresh: (tokens) => {
|
|
54
|
-
this.updateContext({ authToken: tokens.accessToken });
|
|
55
|
-
},
|
|
56
|
-
onTokenExpired: () => {
|
|
57
|
-
this.updateContext({ authToken: null });
|
|
58
|
-
},
|
|
59
|
-
onTokenError: (error) => {
|
|
60
|
-
console.error("Token management error:", error);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
if (authToken && !this._tokenManager.hasTokens()) {
|
|
64
|
-
this._tokenManager.setTokens({ access_token: authToken });
|
|
65
|
-
}
|
|
66
|
-
this._info = {
|
|
67
|
-
config: {
|
|
68
|
-
apiUrl: this._apiUrl,
|
|
69
|
-
appKey: appKey ? `${appKey.substr(0, 4)}...${appKey.substr(-4)}` : null,
|
|
70
|
-
hasToken: Boolean(authToken)
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
this._initialized = true;
|
|
74
|
-
this._setReady();
|
|
75
|
-
} catch (error) {
|
|
76
|
-
this._setError(error);
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
// Helper to check if method requires initialization
|
|
81
|
-
_requiresInit(methodName) {
|
|
82
|
-
const noInitMethods = /* @__PURE__ */ new Set([
|
|
83
|
-
"register",
|
|
84
|
-
"login",
|
|
85
|
-
"googleAuth",
|
|
86
|
-
"googleAuthCallback",
|
|
87
|
-
"githubAuth",
|
|
88
|
-
"requestPasswordReset",
|
|
89
|
-
"confirmPasswordReset",
|
|
90
|
-
"confirmRegistration",
|
|
91
|
-
"verifyEmail",
|
|
92
|
-
"listPublicProjects",
|
|
93
|
-
"getPublicProject",
|
|
94
|
-
"getHealthStatus"
|
|
95
|
-
]);
|
|
96
|
-
return !noInitMethods.has(methodName);
|
|
97
|
-
}
|
|
98
|
-
// Override _requireReady to be more flexible
|
|
99
|
-
_requireReady(methodName) {
|
|
100
|
-
if (this._requiresInit(methodName) && !this._initialized) {
|
|
101
|
-
throw new Error("Core service not initialized");
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
// Debug method to check token status
|
|
105
|
-
getTokenDebugInfo() {
|
|
106
|
-
if (!this._tokenManager) {
|
|
107
|
-
return {
|
|
108
|
-
tokenManagerExists: false,
|
|
109
|
-
error: "TokenManager not initialized"
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
const tokenStatus = this._tokenManager.getTokenStatus();
|
|
113
|
-
const { tokens } = this._tokenManager;
|
|
114
|
-
return {
|
|
115
|
-
tokenManagerExists: true,
|
|
116
|
-
tokenStatus,
|
|
117
|
-
hasAccessToken: Boolean(tokens.accessToken),
|
|
118
|
-
hasRefreshToken: Boolean(tokens.refreshToken),
|
|
119
|
-
accessTokenPreview: tokens.accessToken ? `${tokens.accessToken.substring(0, 20)}...` : null,
|
|
120
|
-
expiresAt: tokens.expiresAt,
|
|
121
|
-
timeToExpiry: tokenStatus.timeToExpiry,
|
|
122
|
-
authHeader: this._tokenManager.getAuthHeader()
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
// Helper method to check if user is authenticated
|
|
126
|
-
isAuthenticated() {
|
|
127
|
-
if (!this._tokenManager) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
return this._tokenManager.hasTokens();
|
|
131
|
-
}
|
|
132
|
-
// Helper method to check if user has valid tokens
|
|
133
|
-
hasValidTokens() {
|
|
134
|
-
if (!this._tokenManager) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
return this._tokenManager.hasTokens() && this._tokenManager.isAccessTokenValid();
|
|
138
|
-
}
|
|
139
|
-
// Helper method to make HTTP requests
|
|
140
|
-
async _request(endpoint, options = {}) {
|
|
141
|
-
const url = `${this._apiUrl}/core${endpoint}`;
|
|
142
|
-
const defaultHeaders = {};
|
|
143
|
-
if (!(options.body instanceof FormData)) {
|
|
144
|
-
defaultHeaders["Content-Type"] = "application/json";
|
|
145
|
-
}
|
|
146
|
-
if (this._requiresInit(options.methodName) && this._tokenManager) {
|
|
147
|
-
try {
|
|
148
|
-
const validToken = await this._tokenManager.ensureValidToken();
|
|
149
|
-
if (validToken) {
|
|
150
|
-
const authHeader = this._tokenManager.getAuthHeader();
|
|
151
|
-
if (authHeader) {
|
|
152
|
-
defaultHeaders.Authorization = authHeader;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
} catch (error) {
|
|
156
|
-
console.warn("Token management failed, proceeding without authentication:", error);
|
|
157
|
-
}
|
|
158
|
-
} else if (this._requiresInit(options.methodName)) {
|
|
159
|
-
const { authToken } = this._context;
|
|
160
|
-
if (authToken) {
|
|
161
|
-
defaultHeaders.Authorization = `Bearer ${authToken}`;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
try {
|
|
165
|
-
const response = await fetch(url, {
|
|
166
|
-
...options,
|
|
167
|
-
headers: {
|
|
168
|
-
...defaultHeaders,
|
|
169
|
-
...options.headers
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
if (!response.ok) {
|
|
173
|
-
let error = { message: `HTTP ${response.status}: ${response.statusText}` };
|
|
174
|
-
try {
|
|
175
|
-
error = await response.json();
|
|
176
|
-
} catch {
|
|
177
|
-
}
|
|
178
|
-
throw new Error(error.message || error.error || "Request failed");
|
|
179
|
-
}
|
|
180
|
-
return response.status === 204 ? null : response.json();
|
|
181
|
-
} catch (error) {
|
|
182
|
-
throw new Error(`Request failed: ${error.message}`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
// ==================== AUTH METHODS ====================
|
|
186
|
-
async register(userData) {
|
|
187
|
-
try {
|
|
188
|
-
const response = await this._request("/auth/register", {
|
|
189
|
-
method: "POST",
|
|
190
|
-
body: JSON.stringify(userData),
|
|
191
|
-
methodName: "register"
|
|
192
|
-
});
|
|
193
|
-
if (response.success) {
|
|
194
|
-
return response.data;
|
|
195
|
-
}
|
|
196
|
-
throw new Error(response.message);
|
|
197
|
-
} catch (error) {
|
|
198
|
-
throw new Error(`Registration failed: ${error.message}`);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
async login(email, password) {
|
|
202
|
-
var _a;
|
|
203
|
-
try {
|
|
204
|
-
const response = await this._request("/auth/login", {
|
|
205
|
-
method: "POST",
|
|
206
|
-
body: JSON.stringify({ email, password }),
|
|
207
|
-
methodName: "login"
|
|
208
|
-
});
|
|
209
|
-
if (response.success && response.data && response.data.tokens) {
|
|
210
|
-
const { tokens } = response.data;
|
|
211
|
-
const tokenData = {
|
|
212
|
-
access_token: tokens.accessToken,
|
|
213
|
-
refresh_token: tokens.refreshToken,
|
|
214
|
-
expires_in: (_a = tokens.accessTokenExp) == null ? void 0 : _a.expiresIn,
|
|
215
|
-
token_type: "Bearer"
|
|
216
|
-
};
|
|
217
|
-
if (this._tokenManager) {
|
|
218
|
-
this._tokenManager.setTokens(tokenData);
|
|
219
|
-
}
|
|
220
|
-
this.updateContext({ authToken: tokens.accessToken });
|
|
221
|
-
}
|
|
222
|
-
if (response.success) {
|
|
223
|
-
return response.data;
|
|
224
|
-
}
|
|
225
|
-
throw new Error(response.message);
|
|
226
|
-
} catch (error) {
|
|
227
|
-
throw new Error(`Login failed: ${error.message}`);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
async logout() {
|
|
231
|
-
this._requireReady("logout");
|
|
232
|
-
try {
|
|
233
|
-
await this._request("/auth/logout", {
|
|
234
|
-
method: "POST",
|
|
235
|
-
methodName: "logout"
|
|
236
|
-
});
|
|
237
|
-
if (this._tokenManager) {
|
|
238
|
-
this._tokenManager.clearTokens();
|
|
239
|
-
}
|
|
240
|
-
this.updateContext({ authToken: null });
|
|
241
|
-
} catch (error) {
|
|
242
|
-
if (this._tokenManager) {
|
|
243
|
-
this._tokenManager.clearTokens();
|
|
244
|
-
}
|
|
245
|
-
this.updateContext({ authToken: null });
|
|
246
|
-
throw new Error(`Logout failed: ${error.message}`);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
async refreshToken(refreshToken) {
|
|
250
|
-
try {
|
|
251
|
-
const response = await this._request("/auth/refresh", {
|
|
252
|
-
method: "POST",
|
|
253
|
-
body: JSON.stringify({ refreshToken }),
|
|
254
|
-
methodName: "refreshToken"
|
|
255
|
-
});
|
|
256
|
-
if (response.success) {
|
|
257
|
-
return response.data;
|
|
258
|
-
}
|
|
259
|
-
throw new Error(response.message);
|
|
260
|
-
} catch (error) {
|
|
261
|
-
throw new Error(`Token refresh failed: ${error.message}`);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
async googleAuth(idToken) {
|
|
265
|
-
var _a;
|
|
266
|
-
try {
|
|
267
|
-
const response = await this._request("/auth/google", {
|
|
268
|
-
method: "POST",
|
|
269
|
-
body: JSON.stringify({ idToken }),
|
|
270
|
-
methodName: "googleAuth"
|
|
271
|
-
});
|
|
272
|
-
if (response.success && response.data && response.data.tokens) {
|
|
273
|
-
const { tokens } = response.data;
|
|
274
|
-
const tokenData = {
|
|
275
|
-
access_token: tokens.accessToken,
|
|
276
|
-
refresh_token: tokens.refreshToken,
|
|
277
|
-
expires_in: (_a = tokens.accessTokenExp) == null ? void 0 : _a.expiresIn,
|
|
278
|
-
token_type: "Bearer"
|
|
279
|
-
};
|
|
280
|
-
if (this._tokenManager) {
|
|
281
|
-
this._tokenManager.setTokens(tokenData);
|
|
282
|
-
}
|
|
283
|
-
this.updateContext({ authToken: tokens.accessToken });
|
|
284
|
-
}
|
|
285
|
-
if (response.success) {
|
|
286
|
-
return response.data;
|
|
287
|
-
}
|
|
288
|
-
throw new Error(response.message);
|
|
289
|
-
} catch (error) {
|
|
290
|
-
throw new Error(`Google auth failed: ${error.message}`);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
async githubAuth(code) {
|
|
294
|
-
var _a;
|
|
295
|
-
try {
|
|
296
|
-
const response = await this._request("/auth/github", {
|
|
297
|
-
method: "POST",
|
|
298
|
-
body: JSON.stringify({ code }),
|
|
299
|
-
methodName: "githubAuth"
|
|
300
|
-
});
|
|
301
|
-
if (response.success && response.data && response.data.tokens) {
|
|
302
|
-
const { tokens } = response.data;
|
|
303
|
-
const tokenData = {
|
|
304
|
-
access_token: tokens.accessToken,
|
|
305
|
-
refresh_token: tokens.refreshToken,
|
|
306
|
-
expires_in: (_a = tokens.accessTokenExp) == null ? void 0 : _a.expiresIn,
|
|
307
|
-
token_type: "Bearer"
|
|
308
|
-
};
|
|
309
|
-
if (this._tokenManager) {
|
|
310
|
-
this._tokenManager.setTokens(tokenData);
|
|
311
|
-
}
|
|
312
|
-
this.updateContext({ authToken: tokens.accessToken });
|
|
313
|
-
}
|
|
314
|
-
if (response.success) {
|
|
315
|
-
return response.data;
|
|
316
|
-
}
|
|
317
|
-
throw new Error(response.message);
|
|
318
|
-
} catch (error) {
|
|
319
|
-
throw new Error(`GitHub auth failed: ${error.message}`);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
async googleAuthCallback(code, redirectUri) {
|
|
323
|
-
var _a;
|
|
324
|
-
try {
|
|
325
|
-
const response = await this._request("/auth/google/callback", {
|
|
326
|
-
method: "POST",
|
|
327
|
-
body: JSON.stringify({ code, redirectUri }),
|
|
328
|
-
methodName: "googleAuthCallback"
|
|
329
|
-
});
|
|
330
|
-
if (response.success && response.data && response.data.tokens) {
|
|
331
|
-
const { tokens } = response.data;
|
|
332
|
-
const tokenData = {
|
|
333
|
-
access_token: tokens.accessToken,
|
|
334
|
-
refresh_token: tokens.refreshToken,
|
|
335
|
-
expires_in: (_a = tokens.accessTokenExp) == null ? void 0 : _a.expiresIn,
|
|
336
|
-
token_type: "Bearer"
|
|
337
|
-
};
|
|
338
|
-
if (this._tokenManager) {
|
|
339
|
-
this._tokenManager.setTokens(tokenData);
|
|
340
|
-
}
|
|
341
|
-
this.updateContext({ authToken: tokens.accessToken });
|
|
342
|
-
}
|
|
343
|
-
if (response.success) {
|
|
344
|
-
return response.data;
|
|
345
|
-
}
|
|
346
|
-
throw new Error(response.message);
|
|
347
|
-
} catch (error) {
|
|
348
|
-
throw new Error(`Google auth callback failed: ${error.message}`);
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
async requestPasswordReset(email) {
|
|
352
|
-
try {
|
|
353
|
-
const response = await this._request("/auth/request-password-reset", {
|
|
354
|
-
method: "POST",
|
|
355
|
-
body: JSON.stringify({ email }),
|
|
356
|
-
methodName: "requestPasswordReset"
|
|
357
|
-
});
|
|
358
|
-
if (response.success) {
|
|
359
|
-
return response.data;
|
|
360
|
-
}
|
|
361
|
-
throw new Error(response.message);
|
|
362
|
-
} catch (error) {
|
|
363
|
-
throw new Error(`Password reset request failed: ${error.message}`);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
async confirmPasswordReset(token, password) {
|
|
367
|
-
try {
|
|
368
|
-
const response = await this._request("/auth/reset-password-confirm", {
|
|
369
|
-
method: "POST",
|
|
370
|
-
body: JSON.stringify({ token, password }),
|
|
371
|
-
methodName: "confirmPasswordReset"
|
|
372
|
-
});
|
|
373
|
-
if (response.success) {
|
|
374
|
-
return response.data;
|
|
375
|
-
}
|
|
376
|
-
throw new Error(response.message);
|
|
377
|
-
} catch (error) {
|
|
378
|
-
throw new Error(`Password reset confirmation failed: ${error.message}`);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
async confirmRegistration(token) {
|
|
382
|
-
try {
|
|
383
|
-
const response = await this._request("/auth/register-confirmation", {
|
|
384
|
-
method: "POST",
|
|
385
|
-
body: JSON.stringify({ token }),
|
|
386
|
-
methodName: "confirmRegistration"
|
|
387
|
-
});
|
|
388
|
-
if (response.success) {
|
|
389
|
-
return response.data;
|
|
390
|
-
}
|
|
391
|
-
throw new Error(response.message);
|
|
392
|
-
} catch (error) {
|
|
393
|
-
throw new Error(`Registration confirmation failed: ${error.message}`);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
async requestPasswordChange() {
|
|
397
|
-
this._requireReady("requestPasswordChange");
|
|
398
|
-
try {
|
|
399
|
-
const response = await this._request("/auth/request-password-change", {
|
|
400
|
-
method: "POST",
|
|
401
|
-
methodName: "requestPasswordChange"
|
|
402
|
-
});
|
|
403
|
-
if (response.success) {
|
|
404
|
-
return response.data;
|
|
405
|
-
}
|
|
406
|
-
throw new Error(response.message);
|
|
407
|
-
} catch (error) {
|
|
408
|
-
throw new Error(`Password change request failed: ${error.message}`);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
async confirmPasswordChange(currentPassword, newPassword, code) {
|
|
412
|
-
this._requireReady("confirmPasswordChange");
|
|
413
|
-
try {
|
|
414
|
-
const response = await this._request("/auth/confirm-password-change", {
|
|
415
|
-
method: "POST",
|
|
416
|
-
body: JSON.stringify({ currentPassword, newPassword, code }),
|
|
417
|
-
methodName: "confirmPasswordChange"
|
|
418
|
-
});
|
|
419
|
-
if (response.success) {
|
|
420
|
-
return response.data;
|
|
421
|
-
}
|
|
422
|
-
throw new Error(response.message);
|
|
423
|
-
} catch (error) {
|
|
424
|
-
throw new Error(`Password change confirmation failed: ${error.message}`);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
async getMe() {
|
|
428
|
-
this._requireReady("getMe");
|
|
429
|
-
try {
|
|
430
|
-
const response = await this._request("/auth/me", {
|
|
431
|
-
method: "GET",
|
|
432
|
-
methodName: "getMe"
|
|
433
|
-
});
|
|
434
|
-
if (response.success) {
|
|
435
|
-
return response.data;
|
|
436
|
-
}
|
|
437
|
-
throw new Error(response.message);
|
|
438
|
-
} catch (error) {
|
|
439
|
-
throw new Error(`Failed to get user profile: ${error.message}`);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Get stored authentication state (backward compatibility method)
|
|
444
|
-
* Replaces AuthService.getStoredAuthState()
|
|
445
|
-
*/
|
|
446
|
-
async getStoredAuthState() {
|
|
447
|
-
try {
|
|
448
|
-
if (!this._tokenManager) {
|
|
449
|
-
return {
|
|
450
|
-
userId: false,
|
|
451
|
-
authToken: false
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
const tokenStatus = this._tokenManager.getTokenStatus();
|
|
455
|
-
if (!tokenStatus.hasTokens) {
|
|
456
|
-
return {
|
|
457
|
-
userId: false,
|
|
458
|
-
authToken: false
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
if (!tokenStatus.isValid && tokenStatus.hasRefreshToken) {
|
|
462
|
-
try {
|
|
463
|
-
await this._tokenManager.ensureValidToken();
|
|
464
|
-
} catch (error) {
|
|
465
|
-
console.warn("[CoreService] Token refresh failed:", error.message);
|
|
466
|
-
if (error.message.includes("401") || error.message.includes("403") || error.message.includes("invalid") || error.message.includes("expired")) {
|
|
467
|
-
this._tokenManager.clearTokens();
|
|
468
|
-
return {
|
|
469
|
-
userId: false,
|
|
470
|
-
authToken: false,
|
|
471
|
-
error: `Authentication failed: ${error.message}`
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
|
-
return {
|
|
475
|
-
userId: false,
|
|
476
|
-
authToken: this._tokenManager.getAccessToken(),
|
|
477
|
-
error: `Network error during token refresh: ${error.message}`,
|
|
478
|
-
hasTokens: true
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
const currentAccessToken = this._tokenManager.getAccessToken();
|
|
483
|
-
if (!currentAccessToken) {
|
|
484
|
-
return {
|
|
485
|
-
userId: false,
|
|
486
|
-
authToken: false
|
|
487
|
-
};
|
|
488
|
-
}
|
|
489
|
-
try {
|
|
490
|
-
const currentUser = await this.getMe();
|
|
491
|
-
return {
|
|
492
|
-
userId: currentUser.user.id,
|
|
493
|
-
authToken: currentAccessToken,
|
|
494
|
-
...currentUser,
|
|
495
|
-
error: null
|
|
496
|
-
};
|
|
497
|
-
} catch (error) {
|
|
498
|
-
console.warn("[CoreService] Failed to get user data:", error.message);
|
|
499
|
-
if (error.message.includes("401") || error.message.includes("403")) {
|
|
500
|
-
this._tokenManager.clearTokens();
|
|
501
|
-
return {
|
|
502
|
-
userId: false,
|
|
503
|
-
authToken: false,
|
|
504
|
-
error: `Authentication failed: ${error.message}`
|
|
505
|
-
};
|
|
506
|
-
}
|
|
507
|
-
return {
|
|
508
|
-
userId: false,
|
|
509
|
-
authToken: currentAccessToken,
|
|
510
|
-
error: `Failed to get user data: ${error.message}`,
|
|
511
|
-
hasTokens: true
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
} catch (error) {
|
|
515
|
-
console.error("[CoreService] Unexpected error in getStoredAuthState:", error);
|
|
516
|
-
return {
|
|
517
|
-
userId: false,
|
|
518
|
-
authToken: false,
|
|
519
|
-
error: `Failed to get stored auth state: ${error.message}`
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
// ==================== USER METHODS ====================
|
|
524
|
-
async getUserProfile() {
|
|
525
|
-
this._requireReady("getUserProfile");
|
|
526
|
-
try {
|
|
527
|
-
const response = await this._request("/users/profile", {
|
|
528
|
-
method: "GET",
|
|
529
|
-
methodName: "getUserProfile"
|
|
530
|
-
});
|
|
531
|
-
if (response.success) {
|
|
532
|
-
return response.data;
|
|
533
|
-
}
|
|
534
|
-
throw new Error(response.message);
|
|
535
|
-
} catch (error) {
|
|
536
|
-
throw new Error(`Failed to get user profile: ${error.message}`);
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
async updateUserProfile(profileData) {
|
|
540
|
-
this._requireReady("updateUserProfile");
|
|
541
|
-
try {
|
|
542
|
-
const response = await this._request("/users/profile", {
|
|
543
|
-
method: "PATCH",
|
|
544
|
-
body: JSON.stringify(profileData),
|
|
545
|
-
methodName: "updateUserProfile"
|
|
546
|
-
});
|
|
547
|
-
if (response.success) {
|
|
548
|
-
return response.data;
|
|
549
|
-
}
|
|
550
|
-
throw new Error(response.message);
|
|
551
|
-
} catch (error) {
|
|
552
|
-
throw new Error(`Failed to update user profile: ${error.message}`);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
async getUserProjects() {
|
|
556
|
-
this._requireReady("getUserProjects");
|
|
557
|
-
try {
|
|
558
|
-
const response = await this._request("/users/projects", {
|
|
559
|
-
method: "GET",
|
|
560
|
-
methodName: "getUserProjects"
|
|
561
|
-
});
|
|
562
|
-
if (response.success) {
|
|
563
|
-
return response.data.map((project) => ({
|
|
564
|
-
...project,
|
|
565
|
-
...project.icon && { icon: { src: `${this._apiUrl}/core/files/public/${project.icon.id}/download`, ...project.icon } }
|
|
566
|
-
}));
|
|
567
|
-
}
|
|
568
|
-
throw new Error(response.message);
|
|
569
|
-
} catch (error) {
|
|
570
|
-
throw new Error(`Failed to get user projects: ${error.message}`);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
async getUser(userId) {
|
|
574
|
-
this._requireReady("getUser");
|
|
575
|
-
if (!userId) {
|
|
576
|
-
throw new Error("User ID is required");
|
|
577
|
-
}
|
|
578
|
-
try {
|
|
579
|
-
const response = await this._request(`/users/${userId}`, {
|
|
580
|
-
method: "GET",
|
|
581
|
-
methodName: "getUser"
|
|
582
|
-
});
|
|
583
|
-
if (response.success) {
|
|
584
|
-
return response.data;
|
|
585
|
-
}
|
|
586
|
-
throw new Error(response.message);
|
|
587
|
-
} catch (error) {
|
|
588
|
-
throw new Error(`Failed to get user: ${error.message}`);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
async getUserByEmail(email) {
|
|
592
|
-
this._requireReady("getUserByEmail");
|
|
593
|
-
if (!email) {
|
|
594
|
-
throw new Error("Email is required");
|
|
595
|
-
}
|
|
596
|
-
try {
|
|
597
|
-
const response = await this._request("/auth/user", {
|
|
598
|
-
method: "GET",
|
|
599
|
-
headers: {
|
|
600
|
-
"X-User-Email": email
|
|
601
|
-
},
|
|
602
|
-
methodName: "getUserByEmail"
|
|
603
|
-
});
|
|
604
|
-
if (response.success) {
|
|
605
|
-
return response.data;
|
|
606
|
-
}
|
|
607
|
-
throw new Error(response.message);
|
|
608
|
-
} catch (error) {
|
|
609
|
-
throw new Error(`Failed to get user by email: ${error.message}`);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
// ==================== PROJECT METHODS ====================
|
|
613
|
-
async createProject(projectData) {
|
|
614
|
-
this._requireReady("createProject");
|
|
615
|
-
try {
|
|
616
|
-
const response = await this._request("/projects", {
|
|
617
|
-
method: "POST",
|
|
618
|
-
body: JSON.stringify(projectData),
|
|
619
|
-
methodName: "createProject"
|
|
620
|
-
});
|
|
621
|
-
if (response.success) {
|
|
622
|
-
return response.data;
|
|
623
|
-
}
|
|
624
|
-
throw new Error(response.message);
|
|
625
|
-
} catch (error) {
|
|
626
|
-
throw new Error(`Failed to create project: ${error.message}`);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
async getProjects(params = {}) {
|
|
630
|
-
this._requireReady("getProjects");
|
|
631
|
-
try {
|
|
632
|
-
const queryParams = new URLSearchParams();
|
|
633
|
-
Object.keys(params).forEach((key) => {
|
|
634
|
-
if (params[key] != null) {
|
|
635
|
-
queryParams.append(key, params[key]);
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
const queryString = queryParams.toString();
|
|
639
|
-
const url = `/projects${queryString ? `?${queryString}` : ""}`;
|
|
640
|
-
const response = await this._request(url, {
|
|
641
|
-
method: "GET",
|
|
642
|
-
methodName: "getProjects"
|
|
643
|
-
});
|
|
644
|
-
if (response.success) {
|
|
645
|
-
return response;
|
|
646
|
-
}
|
|
647
|
-
throw new Error(response.message);
|
|
648
|
-
} catch (error) {
|
|
649
|
-
throw new Error(`Failed to get projects: ${error.message}`);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
/**
|
|
653
|
-
* Alias for getProjects for consistency with API naming
|
|
654
|
-
*/
|
|
655
|
-
async listProjects(params = {}) {
|
|
656
|
-
return await this.getProjects(params);
|
|
657
|
-
}
|
|
658
|
-
/**
|
|
659
|
-
* List only public projects (no authentication required)
|
|
660
|
-
*/
|
|
661
|
-
async listPublicProjects(params = {}) {
|
|
662
|
-
try {
|
|
663
|
-
const queryParams = new URLSearchParams();
|
|
664
|
-
Object.keys(params).forEach((key) => {
|
|
665
|
-
if (params[key] != null) {
|
|
666
|
-
queryParams.append(key, params[key]);
|
|
667
|
-
}
|
|
668
|
-
});
|
|
669
|
-
const queryString = queryParams.toString();
|
|
670
|
-
const url = `/projects/public${queryString ? `?${queryString}` : ""}`;
|
|
671
|
-
const response = await this._request(url, {
|
|
672
|
-
method: "GET",
|
|
673
|
-
methodName: "listPublicProjects"
|
|
674
|
-
});
|
|
675
|
-
if (response.success) {
|
|
676
|
-
return response.data;
|
|
677
|
-
}
|
|
678
|
-
throw new Error(response.message);
|
|
679
|
-
} catch (error) {
|
|
680
|
-
throw new Error(`Failed to list public projects: ${error.message}`);
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
async getProject(projectId) {
|
|
684
|
-
this._requireReady("getProject");
|
|
685
|
-
if (!projectId) {
|
|
686
|
-
throw new Error("Project ID is required");
|
|
687
|
-
}
|
|
688
|
-
try {
|
|
689
|
-
const response = await this._request(`/projects/${projectId}`, {
|
|
690
|
-
method: "GET",
|
|
691
|
-
methodName: "getProject"
|
|
692
|
-
});
|
|
693
|
-
if (response.success) {
|
|
694
|
-
const iconSrc = response.data.icon ? `${this._apiUrl}/core/files/public/${response.data.icon.id}/download` : null;
|
|
695
|
-
return {
|
|
696
|
-
...response.data,
|
|
697
|
-
icon: { src: iconSrc, ...response.data.icon }
|
|
698
|
-
};
|
|
699
|
-
}
|
|
700
|
-
throw new Error(response.message);
|
|
701
|
-
} catch (error) {
|
|
702
|
-
throw new Error(`Failed to get project: ${error.message}`);
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
/**
|
|
706
|
-
* Get a public project by ID (no authentication required)
|
|
707
|
-
* Corresponds to router.get('/public/:projectId', ProjectController.getPublicProject)
|
|
708
|
-
*/
|
|
709
|
-
async getPublicProject(projectId) {
|
|
710
|
-
if (!projectId) {
|
|
711
|
-
throw new Error("Project ID is required");
|
|
712
|
-
}
|
|
713
|
-
try {
|
|
714
|
-
const response = await this._request(`/projects/public/${projectId}`, {
|
|
715
|
-
method: "GET",
|
|
716
|
-
methodName: "getPublicProject"
|
|
717
|
-
});
|
|
718
|
-
if (response.success) {
|
|
719
|
-
const iconSrc = response.data.icon ? `${this._apiUrl}/core/files/public/${response.data.icon.id}/download` : null;
|
|
720
|
-
return {
|
|
721
|
-
...response.data,
|
|
722
|
-
icon: { src: iconSrc, ...response.data.icon }
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
throw new Error(response.message);
|
|
726
|
-
} catch (error) {
|
|
727
|
-
throw new Error(`Failed to get public project: ${error.message}`);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
async getProjectByKey(key) {
|
|
731
|
-
this._requireReady("getProjectByKey");
|
|
732
|
-
if (!key) {
|
|
733
|
-
throw new Error("Project key is required");
|
|
734
|
-
}
|
|
735
|
-
try {
|
|
736
|
-
const response = await this._request(`/projects/check-key/${key}`, {
|
|
737
|
-
method: "GET",
|
|
738
|
-
methodName: "getProjectByKey"
|
|
739
|
-
});
|
|
740
|
-
if (response.success) {
|
|
741
|
-
return response.data;
|
|
742
|
-
}
|
|
743
|
-
throw new Error(response.message);
|
|
744
|
-
} catch (error) {
|
|
745
|
-
throw new Error(`Failed to get project by key: ${error.message}`);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
async updateProject(projectId, data) {
|
|
749
|
-
this._requireReady("updateProject");
|
|
750
|
-
if (!projectId) {
|
|
751
|
-
throw new Error("Project ID is required");
|
|
752
|
-
}
|
|
753
|
-
try {
|
|
754
|
-
const response = await this._request(`/projects/${projectId}`, {
|
|
755
|
-
method: "PATCH",
|
|
756
|
-
body: JSON.stringify(data),
|
|
757
|
-
methodName: "updateProject"
|
|
758
|
-
});
|
|
759
|
-
if (response.success) {
|
|
760
|
-
return response.data;
|
|
761
|
-
}
|
|
762
|
-
throw new Error(response.message);
|
|
763
|
-
} catch (error) {
|
|
764
|
-
throw new Error(`Failed to update project: ${error.message}`);
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
async updateProjectComponents(projectId, components) {
|
|
768
|
-
this._requireReady("updateProjectComponents");
|
|
769
|
-
if (!projectId) {
|
|
770
|
-
throw new Error("Project ID is required");
|
|
771
|
-
}
|
|
772
|
-
try {
|
|
773
|
-
const response = await this._request(`/projects/${projectId}/components`, {
|
|
774
|
-
method: "PATCH",
|
|
775
|
-
body: JSON.stringify({ components }),
|
|
776
|
-
methodName: "updateProjectComponents"
|
|
777
|
-
});
|
|
778
|
-
if (response.success) {
|
|
779
|
-
return response.data;
|
|
780
|
-
}
|
|
781
|
-
throw new Error(response.message);
|
|
782
|
-
} catch (error) {
|
|
783
|
-
throw new Error(`Failed to update project components: ${error.message}`);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
async updateProjectSettings(projectId, settings) {
|
|
787
|
-
this._requireReady("updateProjectSettings");
|
|
788
|
-
if (!projectId) {
|
|
789
|
-
throw new Error("Project ID is required");
|
|
790
|
-
}
|
|
791
|
-
try {
|
|
792
|
-
const response = await this._request(`/projects/${projectId}/settings`, {
|
|
793
|
-
method: "PATCH",
|
|
794
|
-
body: JSON.stringify({ settings }),
|
|
795
|
-
methodName: "updateProjectSettings"
|
|
796
|
-
});
|
|
797
|
-
if (response.success) {
|
|
798
|
-
return response.data;
|
|
799
|
-
}
|
|
800
|
-
throw new Error(response.message);
|
|
801
|
-
} catch (error) {
|
|
802
|
-
throw new Error(`Failed to update project settings: ${error.message}`);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
async updateProjectName(projectId, name) {
|
|
806
|
-
this._requireReady("updateProjectName");
|
|
807
|
-
if (!projectId) {
|
|
808
|
-
throw new Error("Project ID is required");
|
|
809
|
-
}
|
|
810
|
-
try {
|
|
811
|
-
const response = await this._request(`/projects/${projectId}`, {
|
|
812
|
-
method: "PATCH",
|
|
813
|
-
body: JSON.stringify({ name }),
|
|
814
|
-
methodName: "updateProjectName"
|
|
815
|
-
});
|
|
816
|
-
if (response.success) {
|
|
817
|
-
return response.data;
|
|
818
|
-
}
|
|
819
|
-
throw new Error(response.message);
|
|
820
|
-
} catch (error) {
|
|
821
|
-
throw new Error(`Failed to update project name: ${error.message}`);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
async updateProjectPackage(projectId, pkg) {
|
|
825
|
-
this._requireReady("updateProjectPackage");
|
|
826
|
-
if (!projectId) {
|
|
827
|
-
throw new Error("Project ID is required");
|
|
828
|
-
}
|
|
829
|
-
try {
|
|
830
|
-
const response = await this._request(`/projects/${projectId}/tier`, {
|
|
831
|
-
method: "PATCH",
|
|
832
|
-
body: JSON.stringify({ tier: pkg }),
|
|
833
|
-
methodName: "updateProjectPackage"
|
|
834
|
-
});
|
|
835
|
-
if (response.success) {
|
|
836
|
-
return response.data;
|
|
837
|
-
}
|
|
838
|
-
throw new Error(response.message);
|
|
839
|
-
} catch (error) {
|
|
840
|
-
throw new Error(`Failed to update project package: ${error.message}`);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
async duplicateProject(projectId, newName, newKey, targetUserId) {
|
|
844
|
-
this._requireReady("duplicateProject");
|
|
845
|
-
if (!projectId) {
|
|
846
|
-
throw new Error("Project ID is required");
|
|
847
|
-
}
|
|
848
|
-
try {
|
|
849
|
-
const response = await this._request(`/projects/${projectId}/duplicate`, {
|
|
850
|
-
method: "POST",
|
|
851
|
-
body: JSON.stringify({ name: newName, key: newKey, targetUserId }),
|
|
852
|
-
methodName: "duplicateProject"
|
|
853
|
-
});
|
|
854
|
-
if (response.success) {
|
|
855
|
-
return response.data;
|
|
856
|
-
}
|
|
857
|
-
throw new Error(response.message);
|
|
858
|
-
} catch (error) {
|
|
859
|
-
throw new Error(`Failed to duplicate project: ${error.message}`);
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
async removeProject(projectId) {
|
|
863
|
-
this._requireReady("removeProject");
|
|
864
|
-
if (!projectId) {
|
|
865
|
-
throw new Error("Project ID is required");
|
|
866
|
-
}
|
|
867
|
-
try {
|
|
868
|
-
const response = await this._request(`/projects/${projectId}`, {
|
|
869
|
-
method: "DELETE",
|
|
870
|
-
methodName: "removeProject"
|
|
871
|
-
});
|
|
872
|
-
if (response.success) {
|
|
873
|
-
return response.data;
|
|
874
|
-
}
|
|
875
|
-
throw new Error(response.message);
|
|
876
|
-
} catch (error) {
|
|
877
|
-
throw new Error(`Failed to remove project: ${error.message}`);
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
async checkProjectKeyAvailability(key) {
|
|
881
|
-
this._requireReady("checkProjectKeyAvailability");
|
|
882
|
-
if (!key) {
|
|
883
|
-
throw new Error("Project key is required");
|
|
884
|
-
}
|
|
885
|
-
try {
|
|
886
|
-
const response = await this._request(`/projects/check-key/${key}`, {
|
|
887
|
-
method: "GET",
|
|
888
|
-
methodName: "checkProjectKeyAvailability"
|
|
889
|
-
});
|
|
890
|
-
if (response.success) {
|
|
891
|
-
return response.data;
|
|
892
|
-
}
|
|
893
|
-
throw new Error(response.message);
|
|
894
|
-
} catch (error) {
|
|
895
|
-
throw new Error(`Failed to check project key availability: ${error.message}`);
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
// ==================== PROJECT MEMBER METHODS ====================
|
|
899
|
-
async getProjectMembers(projectId) {
|
|
900
|
-
this._requireReady("getProjectMembers");
|
|
901
|
-
if (!projectId) {
|
|
902
|
-
throw new Error("Project ID is required");
|
|
903
|
-
}
|
|
904
|
-
try {
|
|
905
|
-
const response = await this._request(`/projects/${projectId}/members`, {
|
|
906
|
-
method: "GET",
|
|
907
|
-
methodName: "getProjectMembers"
|
|
908
|
-
});
|
|
909
|
-
if (response.success) {
|
|
910
|
-
return response.data;
|
|
911
|
-
}
|
|
912
|
-
throw new Error(response.message);
|
|
913
|
-
} catch (error) {
|
|
914
|
-
throw new Error(`Failed to get project members: ${error.message}`);
|
|
915
|
-
}
|
|
916
|
-
}
|
|
917
|
-
async inviteMember(projectId, email, role = "guest", options = {}) {
|
|
918
|
-
this._requireReady("inviteMember");
|
|
919
|
-
if (!projectId || !email || !role) {
|
|
920
|
-
throw new Error("Project ID, email, and role are required");
|
|
921
|
-
}
|
|
922
|
-
const { name, callbackUrl } = options;
|
|
923
|
-
const defaultCallbackUrl = typeof window === "undefined" ? "https://app.symbols.com/accept-invite" : `${window.location.origin}/accept-invite`;
|
|
924
|
-
try {
|
|
925
|
-
const requestBody = {
|
|
926
|
-
email,
|
|
927
|
-
role,
|
|
928
|
-
callbackUrl: callbackUrl || defaultCallbackUrl
|
|
929
|
-
};
|
|
930
|
-
if (name) {
|
|
931
|
-
requestBody.name = name;
|
|
932
|
-
}
|
|
933
|
-
const response = await this._request(`/projects/${projectId}/invite`, {
|
|
934
|
-
method: "POST",
|
|
935
|
-
body: JSON.stringify(requestBody),
|
|
936
|
-
methodName: "inviteMember"
|
|
937
|
-
});
|
|
938
|
-
if (response.success) {
|
|
939
|
-
return response.data;
|
|
940
|
-
}
|
|
941
|
-
throw new Error(response.message);
|
|
942
|
-
} catch (error) {
|
|
943
|
-
throw new Error(`Failed to invite member: ${error.message}`);
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
async acceptInvite(token) {
|
|
947
|
-
this._requireReady("acceptInvite");
|
|
948
|
-
if (!token) {
|
|
949
|
-
throw new Error("Invitation token is required");
|
|
950
|
-
}
|
|
951
|
-
try {
|
|
952
|
-
const response = await this._request("/projects/accept-invite", {
|
|
953
|
-
method: "POST",
|
|
954
|
-
body: JSON.stringify({ token }),
|
|
955
|
-
methodName: "acceptInvite"
|
|
956
|
-
});
|
|
957
|
-
if (response.success) {
|
|
958
|
-
return response.data;
|
|
959
|
-
}
|
|
960
|
-
throw new Error(response.message);
|
|
961
|
-
} catch (error) {
|
|
962
|
-
throw new Error(`Failed to accept invite: ${error.message}`);
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
async updateMemberRole(projectId, memberId, role) {
|
|
966
|
-
this._requireReady("updateMemberRole");
|
|
967
|
-
if (!projectId || !memberId || !role) {
|
|
968
|
-
throw new Error("Project ID, member ID, and role are required");
|
|
969
|
-
}
|
|
970
|
-
try {
|
|
971
|
-
const response = await this._request(`/projects/${projectId}/members/${memberId}`, {
|
|
972
|
-
method: "PATCH",
|
|
973
|
-
body: JSON.stringify({ role }),
|
|
974
|
-
methodName: "updateMemberRole"
|
|
975
|
-
});
|
|
976
|
-
if (response.success) {
|
|
977
|
-
return response.data;
|
|
978
|
-
}
|
|
979
|
-
throw new Error(response.message);
|
|
980
|
-
} catch (error) {
|
|
981
|
-
throw new Error(`Failed to update member role: ${error.message}`);
|
|
982
|
-
}
|
|
983
|
-
}
|
|
984
|
-
async removeMember(projectId, memberId) {
|
|
985
|
-
this._requireReady("removeMember");
|
|
986
|
-
if (!projectId || !memberId) {
|
|
987
|
-
throw new Error("Project ID and member ID are required");
|
|
988
|
-
}
|
|
989
|
-
try {
|
|
990
|
-
const response = await this._request(`/projects/${projectId}/members/${memberId}`, {
|
|
991
|
-
method: "DELETE",
|
|
992
|
-
methodName: "removeMember"
|
|
993
|
-
});
|
|
994
|
-
if (response.success) {
|
|
995
|
-
return response.data;
|
|
996
|
-
}
|
|
997
|
-
throw new Error(response.message);
|
|
998
|
-
} catch (error) {
|
|
999
|
-
throw new Error(`Failed to remove member: ${error.message}`);
|
|
1000
|
-
}
|
|
1001
|
-
}
|
|
1002
|
-
// ==================== PROJECT LIBRARY METHODS ====================
|
|
1003
|
-
async getAvailableLibraries(params = {}) {
|
|
1004
|
-
this._requireReady("getAvailableLibraries");
|
|
1005
|
-
const queryParams = new URLSearchParams(params).toString();
|
|
1006
|
-
try {
|
|
1007
|
-
const response = await this._request(`/projects/libraries/available?${queryParams}`, {
|
|
1008
|
-
method: "GET",
|
|
1009
|
-
methodName: "getAvailableLibraries"
|
|
1010
|
-
});
|
|
1011
|
-
if (response.success) {
|
|
1012
|
-
return response.data;
|
|
1013
|
-
}
|
|
1014
|
-
throw new Error(response.message);
|
|
1015
|
-
} catch (error) {
|
|
1016
|
-
throw new Error(`Failed to get available libraries: ${error.message}`);
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
async getProjectLibraries(projectId) {
|
|
1020
|
-
this._requireReady("getProjectLibraries");
|
|
1021
|
-
if (!projectId) {
|
|
1022
|
-
throw new Error("Project ID is required");
|
|
1023
|
-
}
|
|
1024
|
-
try {
|
|
1025
|
-
const response = await this._request(`/projects/${projectId}/libraries`, {
|
|
1026
|
-
method: "GET",
|
|
1027
|
-
methodName: "getProjectLibraries"
|
|
1028
|
-
});
|
|
1029
|
-
if (response.success) {
|
|
1030
|
-
return response.data;
|
|
1031
|
-
}
|
|
1032
|
-
throw new Error(response.message);
|
|
1033
|
-
} catch (error) {
|
|
1034
|
-
throw new Error(`Failed to get project libraries: ${error.message}`);
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
async addProjectLibraries(projectId, libraryIds) {
|
|
1038
|
-
this._requireReady("addProjectLibraries");
|
|
1039
|
-
if (!projectId || !libraryIds) {
|
|
1040
|
-
throw new Error("Project ID and library IDs are required");
|
|
1041
|
-
}
|
|
1042
|
-
try {
|
|
1043
|
-
const response = await this._request(`/projects/${projectId}/libraries`, {
|
|
1044
|
-
method: "POST",
|
|
1045
|
-
body: JSON.stringify({ libraryIds }),
|
|
1046
|
-
methodName: "addProjectLibraries"
|
|
1047
|
-
});
|
|
1048
|
-
if (response.success) {
|
|
1049
|
-
return response.data;
|
|
1050
|
-
}
|
|
1051
|
-
throw new Error(response.message);
|
|
1052
|
-
} catch (error) {
|
|
1053
|
-
throw new Error(`Failed to add project libraries: ${error.message}`);
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
async removeProjectLibraries(projectId, libraryIds) {
|
|
1057
|
-
this._requireReady("removeProjectLibraries");
|
|
1058
|
-
if (!projectId || !libraryIds) {
|
|
1059
|
-
throw new Error("Project ID and library IDs are required");
|
|
1060
|
-
}
|
|
1061
|
-
try {
|
|
1062
|
-
const response = await this._request(`/projects/${projectId}/libraries`, {
|
|
1063
|
-
method: "DELETE",
|
|
1064
|
-
body: JSON.stringify({ libraryIds }),
|
|
1065
|
-
methodName: "removeProjectLibraries"
|
|
1066
|
-
});
|
|
1067
|
-
if (response.success) {
|
|
1068
|
-
return response.data;
|
|
1069
|
-
}
|
|
1070
|
-
throw new Error(response.message);
|
|
1071
|
-
} catch (error) {
|
|
1072
|
-
throw new Error(`Failed to remove project libraries: ${error.message}`);
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
// ==================== FILE METHODS ====================
|
|
1076
|
-
async uploadFile(file, options = {}) {
|
|
1077
|
-
this._requireReady("uploadFile");
|
|
1078
|
-
if (!file) {
|
|
1079
|
-
throw new Error("File is required for upload");
|
|
1080
|
-
}
|
|
1081
|
-
const formData = new FormData();
|
|
1082
|
-
formData.append("file", file);
|
|
1083
|
-
if (options.projectId) {
|
|
1084
|
-
formData.append("projectId", options.projectId);
|
|
1085
|
-
}
|
|
1086
|
-
if (options.tags) {
|
|
1087
|
-
formData.append("tags", JSON.stringify(options.tags));
|
|
1088
|
-
}
|
|
1089
|
-
if (options.visibility) {
|
|
1090
|
-
formData.append("visibility", options.visibility || "public");
|
|
1091
|
-
}
|
|
1092
|
-
if (options.metadata) {
|
|
1093
|
-
formData.append("metadata", JSON.stringify(options.metadata));
|
|
1094
|
-
}
|
|
1095
|
-
try {
|
|
1096
|
-
const response = await this._request("/files/upload", {
|
|
1097
|
-
method: "POST",
|
|
1098
|
-
body: formData,
|
|
1099
|
-
headers: {},
|
|
1100
|
-
// Let browser set Content-Type for FormData
|
|
1101
|
-
methodName: "uploadFile"
|
|
1102
|
-
});
|
|
1103
|
-
if (!response.success) {
|
|
1104
|
-
throw new Error(response.message);
|
|
1105
|
-
}
|
|
1106
|
-
return {
|
|
1107
|
-
id: response.data.id,
|
|
1108
|
-
src: `${this._apiUrl}/core/files/public/${response.data.id}/download`,
|
|
1109
|
-
success: true,
|
|
1110
|
-
message: response.message
|
|
1111
|
-
};
|
|
1112
|
-
} catch (error) {
|
|
1113
|
-
throw new Error(`File upload failed: ${error.message}`);
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
async updateProjectIcon(projectId, iconFile) {
|
|
1117
|
-
this._requireReady("updateProjectIcon");
|
|
1118
|
-
if (!projectId || !iconFile) {
|
|
1119
|
-
throw new Error("Project ID and icon file are required");
|
|
1120
|
-
}
|
|
1121
|
-
const formData = new FormData();
|
|
1122
|
-
formData.append("icon", iconFile);
|
|
1123
|
-
formData.append("projectId", projectId);
|
|
1124
|
-
try {
|
|
1125
|
-
const response = await this._request("/files/upload-project-icon", {
|
|
1126
|
-
method: "POST",
|
|
1127
|
-
body: formData,
|
|
1128
|
-
headers: {},
|
|
1129
|
-
// Let browser set Content-Type for FormData
|
|
1130
|
-
methodName: "updateProjectIcon"
|
|
1131
|
-
});
|
|
1132
|
-
if (response.success) {
|
|
1133
|
-
return response.data;
|
|
1134
|
-
}
|
|
1135
|
-
throw new Error(response.message);
|
|
1136
|
-
} catch (error) {
|
|
1137
|
-
throw new Error(`Failed to update project icon: ${error.message}`);
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
// ==================== PAYMENT METHODS ====================
|
|
1141
|
-
async checkout(options = {}) {
|
|
1142
|
-
this._requireReady("checkout");
|
|
1143
|
-
const {
|
|
1144
|
-
projectId,
|
|
1145
|
-
seats = 1,
|
|
1146
|
-
price = "starter_monthly",
|
|
1147
|
-
successUrl = `${window.location.origin}/success`,
|
|
1148
|
-
cancelUrl = `${window.location.origin}/pricing`
|
|
1149
|
-
} = options;
|
|
1150
|
-
if (!projectId) {
|
|
1151
|
-
throw new Error("Project ID is required for checkout");
|
|
1152
|
-
}
|
|
1153
|
-
try {
|
|
1154
|
-
const response = await this._request("/payments/checkout", {
|
|
1155
|
-
method: "POST",
|
|
1156
|
-
body: JSON.stringify({
|
|
1157
|
-
projectId,
|
|
1158
|
-
seats,
|
|
1159
|
-
price,
|
|
1160
|
-
successUrl,
|
|
1161
|
-
cancelUrl
|
|
1162
|
-
}),
|
|
1163
|
-
methodName: "checkout"
|
|
1164
|
-
});
|
|
1165
|
-
if (response.success) {
|
|
1166
|
-
return response.data;
|
|
1167
|
-
}
|
|
1168
|
-
throw new Error(response.message);
|
|
1169
|
-
} catch (error) {
|
|
1170
|
-
throw new Error(`Failed to checkout: ${error.message}`);
|
|
1171
|
-
}
|
|
1172
|
-
}
|
|
1173
|
-
async getSubscriptionStatus(projectId) {
|
|
1174
|
-
this._requireReady("getSubscriptionStatus");
|
|
1175
|
-
if (!projectId) {
|
|
1176
|
-
throw new Error("Project ID is required");
|
|
1177
|
-
}
|
|
1178
|
-
try {
|
|
1179
|
-
const response = await this._request(`/payments/subscription/${projectId}`, {
|
|
1180
|
-
method: "GET",
|
|
1181
|
-
methodName: "getSubscriptionStatus"
|
|
1182
|
-
});
|
|
1183
|
-
if (response.success) {
|
|
1184
|
-
return response.data;
|
|
1185
|
-
}
|
|
1186
|
-
throw new Error(response.message);
|
|
1187
|
-
} catch (error) {
|
|
1188
|
-
throw new Error(`Failed to get subscription status: ${error.message}`);
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
// ==================== DNS METHODS ====================
|
|
1192
|
-
async createDnsRecord(domain, options = {}) {
|
|
1193
|
-
this._requireReady("createDnsRecord");
|
|
1194
|
-
if (!domain) {
|
|
1195
|
-
throw new Error("Domain is required");
|
|
1196
|
-
}
|
|
1197
|
-
try {
|
|
1198
|
-
const response = await this._request("/dns/records", {
|
|
1199
|
-
method: "POST",
|
|
1200
|
-
body: JSON.stringify({ domain, ...options }),
|
|
1201
|
-
methodName: "createDnsRecord"
|
|
1202
|
-
});
|
|
1203
|
-
if (response.success) {
|
|
1204
|
-
return response.data;
|
|
1205
|
-
}
|
|
1206
|
-
throw new Error(response.message);
|
|
1207
|
-
} catch (error) {
|
|
1208
|
-
throw new Error(`Failed to create DNS record: ${error.message}`);
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
async getDnsRecord(domain) {
|
|
1212
|
-
this._requireReady("getDnsRecord");
|
|
1213
|
-
if (!domain) {
|
|
1214
|
-
throw new Error("Domain is required");
|
|
1215
|
-
}
|
|
1216
|
-
try {
|
|
1217
|
-
const response = await this._request(`/dns/records/${domain}`, {
|
|
1218
|
-
method: "GET",
|
|
1219
|
-
methodName: "getDnsRecord"
|
|
1220
|
-
});
|
|
1221
|
-
if (response.success) {
|
|
1222
|
-
return response.data;
|
|
1223
|
-
}
|
|
1224
|
-
throw new Error(response.message);
|
|
1225
|
-
} catch (error) {
|
|
1226
|
-
throw new Error(`Failed to get DNS record: ${error.message}`);
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
async removeDnsRecord(domain) {
|
|
1230
|
-
this._requireReady("removeDnsRecord");
|
|
1231
|
-
if (!domain) {
|
|
1232
|
-
throw new Error("Domain is required");
|
|
1233
|
-
}
|
|
1234
|
-
try {
|
|
1235
|
-
const response = await this._request(`/dns/records/${domain}`, {
|
|
1236
|
-
method: "DELETE",
|
|
1237
|
-
methodName: "removeDnsRecord"
|
|
1238
|
-
});
|
|
1239
|
-
if (response.success) {
|
|
1240
|
-
return response.data;
|
|
1241
|
-
}
|
|
1242
|
-
throw new Error(response.message);
|
|
1243
|
-
} catch (error) {
|
|
1244
|
-
throw new Error(`Failed to remove DNS record: ${error.message}`);
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
async setProjectDomains(projectKey, customDomain, hasCustomDomainAccess = false) {
|
|
1248
|
-
this._requireReady("setProjectDomains");
|
|
1249
|
-
if (!projectKey) {
|
|
1250
|
-
throw new Error("Project key is required");
|
|
1251
|
-
}
|
|
1252
|
-
try {
|
|
1253
|
-
const response = await this._request("/dns/project-domains", {
|
|
1254
|
-
method: "POST",
|
|
1255
|
-
body: JSON.stringify({
|
|
1256
|
-
projectKey,
|
|
1257
|
-
customDomain,
|
|
1258
|
-
hasCustomDomainAccess
|
|
1259
|
-
}),
|
|
1260
|
-
methodName: "setProjectDomains"
|
|
1261
|
-
});
|
|
1262
|
-
if (response.success) {
|
|
1263
|
-
return response.data;
|
|
1264
|
-
}
|
|
1265
|
-
throw new Error(response.message);
|
|
1266
|
-
} catch (error) {
|
|
1267
|
-
throw new Error(`Failed to set project domains: ${error.message}`);
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
// ==================== UTILITY METHODS ====================
|
|
1271
|
-
async getHealthStatus() {
|
|
1272
|
-
try {
|
|
1273
|
-
const response = await this._request("/health", {
|
|
1274
|
-
method: "GET",
|
|
1275
|
-
methodName: "getHealthStatus"
|
|
1276
|
-
});
|
|
1277
|
-
if (response.success) {
|
|
1278
|
-
return response.data;
|
|
1279
|
-
}
|
|
1280
|
-
throw new Error(response.message);
|
|
1281
|
-
} catch (error) {
|
|
1282
|
-
throw new Error(`Failed to get health status: ${error.message}`);
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
// ==================== PROJECT DATA METHODS (SYMSTORY REPLACEMENT) ====================
|
|
1286
|
-
/**
|
|
1287
|
-
* Apply changes to a project, creating a new version
|
|
1288
|
-
* Replaces: SymstoryService.updateData()
|
|
1289
|
-
*/
|
|
1290
|
-
async applyProjectChanges(projectId, changes, options = {}) {
|
|
1291
|
-
this._requireReady("applyProjectChanges");
|
|
1292
|
-
if (!projectId) {
|
|
1293
|
-
throw new Error("Project ID is required");
|
|
1294
|
-
}
|
|
1295
|
-
if (!Array.isArray(changes)) {
|
|
1296
|
-
throw new Error("Changes must be an array");
|
|
1297
|
-
}
|
|
1298
|
-
const {
|
|
1299
|
-
message,
|
|
1300
|
-
branch = "main",
|
|
1301
|
-
type = "patch"
|
|
1302
|
-
} = options;
|
|
1303
|
-
try {
|
|
1304
|
-
const response = await this._request(`/projects/${projectId}/changes`, {
|
|
1305
|
-
method: "POST",
|
|
1306
|
-
body: JSON.stringify({
|
|
1307
|
-
changes,
|
|
1308
|
-
message,
|
|
1309
|
-
branch,
|
|
1310
|
-
type
|
|
1311
|
-
}),
|
|
1312
|
-
methodName: "applyProjectChanges"
|
|
1313
|
-
});
|
|
1314
|
-
if (response.success) {
|
|
1315
|
-
return response.data;
|
|
1316
|
-
}
|
|
1317
|
-
throw new Error(response.message);
|
|
1318
|
-
} catch (error) {
|
|
1319
|
-
throw new Error(`Failed to apply project changes: ${error.message}`);
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
/**
|
|
1323
|
-
* Get current project data for a specific branch
|
|
1324
|
-
* Replaces: SymstoryService.getData()
|
|
1325
|
-
*/
|
|
1326
|
-
async getProjectData(projectId, options = {}) {
|
|
1327
|
-
this._requireReady("getProjectData");
|
|
1328
|
-
if (!projectId) {
|
|
1329
|
-
throw new Error("Project ID is required");
|
|
1330
|
-
}
|
|
1331
|
-
const {
|
|
1332
|
-
branch = "main",
|
|
1333
|
-
version = "latest",
|
|
1334
|
-
includeHistory = false
|
|
1335
|
-
} = options;
|
|
1336
|
-
const queryParams = new URLSearchParams({
|
|
1337
|
-
branch,
|
|
1338
|
-
version,
|
|
1339
|
-
includeHistory: includeHistory.toString()
|
|
1340
|
-
}).toString();
|
|
1341
|
-
try {
|
|
1342
|
-
const response = await this._request(`/projects/${projectId}/data?${queryParams}`, {
|
|
1343
|
-
method: "GET",
|
|
1344
|
-
methodName: "getProjectData"
|
|
1345
|
-
});
|
|
1346
|
-
if (response.success) {
|
|
1347
|
-
return response.data;
|
|
1348
|
-
}
|
|
1349
|
-
throw new Error(response.message);
|
|
1350
|
-
} catch (error) {
|
|
1351
|
-
throw new Error(`Failed to get project data: ${error.message}`);
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
/**
|
|
1355
|
-
* Get project versions with pagination
|
|
1356
|
-
*/
|
|
1357
|
-
async getProjectVersions(projectId, options = {}) {
|
|
1358
|
-
this._requireReady("getProjectVersions");
|
|
1359
|
-
if (!projectId) {
|
|
1360
|
-
throw new Error("Project ID is required");
|
|
1361
|
-
}
|
|
1362
|
-
const {
|
|
1363
|
-
branch = "main",
|
|
1364
|
-
page = 1,
|
|
1365
|
-
limit = 50
|
|
1366
|
-
} = options;
|
|
1367
|
-
const queryParams = new URLSearchParams({
|
|
1368
|
-
branch,
|
|
1369
|
-
page: page.toString(),
|
|
1370
|
-
limit: limit.toString()
|
|
1371
|
-
}).toString();
|
|
1372
|
-
try {
|
|
1373
|
-
const response = await this._request(`/projects/${projectId}/versions?${queryParams}`, {
|
|
1374
|
-
method: "GET",
|
|
1375
|
-
methodName: "getProjectVersions"
|
|
1376
|
-
});
|
|
1377
|
-
if (response.success) {
|
|
1378
|
-
return response.data;
|
|
1379
|
-
}
|
|
1380
|
-
throw new Error(response.message);
|
|
1381
|
-
} catch (error) {
|
|
1382
|
-
throw new Error(`Failed to get project versions: ${error.message}`);
|
|
1383
|
-
}
|
|
1384
|
-
}
|
|
1385
|
-
/**
|
|
1386
|
-
* Restore project to a previous version
|
|
1387
|
-
* Replaces: SymstoryService.restoreVersion()
|
|
1388
|
-
*/
|
|
1389
|
-
async restoreProjectVersion(projectId, version, options = {}) {
|
|
1390
|
-
this._requireReady("restoreProjectVersion");
|
|
1391
|
-
if (!projectId) {
|
|
1392
|
-
throw new Error("Project ID is required");
|
|
1393
|
-
}
|
|
1394
|
-
if (!version) {
|
|
1395
|
-
throw new Error("Version is required");
|
|
1396
|
-
}
|
|
1397
|
-
const {
|
|
1398
|
-
message,
|
|
1399
|
-
branch = "main",
|
|
1400
|
-
type = "patch"
|
|
1401
|
-
} = options;
|
|
1402
|
-
try {
|
|
1403
|
-
const response = await this._request(`/projects/${projectId}/restore`, {
|
|
1404
|
-
method: "POST",
|
|
1405
|
-
body: JSON.stringify({
|
|
1406
|
-
version,
|
|
1407
|
-
message,
|
|
1408
|
-
branch,
|
|
1409
|
-
type
|
|
1410
|
-
}),
|
|
1411
|
-
methodName: "restoreProjectVersion"
|
|
1412
|
-
});
|
|
1413
|
-
if (response.success) {
|
|
1414
|
-
return response.data;
|
|
1415
|
-
}
|
|
1416
|
-
throw new Error(response.message);
|
|
1417
|
-
} catch (error) {
|
|
1418
|
-
throw new Error(`Failed to restore project version: ${error.message}`);
|
|
1419
|
-
}
|
|
1420
|
-
}
|
|
1421
|
-
/**
|
|
1422
|
-
* Helper method to update a single item in the project
|
|
1423
|
-
* Convenience wrapper around applyProjectChanges
|
|
1424
|
-
*/
|
|
1425
|
-
async updateProjectItem(projectId, path, value, options = {}) {
|
|
1426
|
-
const changes = [["update", path, value]];
|
|
1427
|
-
const message = options.message || `Updated ${Array.isArray(path) ? path.join(".") : path}`;
|
|
1428
|
-
return await this.applyProjectChanges(projectId, changes, {
|
|
1429
|
-
...options,
|
|
1430
|
-
message
|
|
1431
|
-
});
|
|
1432
|
-
}
|
|
1433
|
-
/**
|
|
1434
|
-
* Helper method to delete an item from the project
|
|
1435
|
-
* Convenience wrapper around applyProjectChanges
|
|
1436
|
-
*/
|
|
1437
|
-
async deleteProjectItem(projectId, path, options = {}) {
|
|
1438
|
-
const changes = [["delete", path]];
|
|
1439
|
-
const message = options.message || `Deleted ${Array.isArray(path) ? path.join(".") : path}`;
|
|
1440
|
-
return await this.applyProjectChanges(projectId, changes, {
|
|
1441
|
-
...options,
|
|
1442
|
-
message
|
|
1443
|
-
});
|
|
1444
|
-
}
|
|
1445
|
-
/**
|
|
1446
|
-
* Helper method to set a value in the project (alias for update)
|
|
1447
|
-
* Convenience wrapper around applyProjectChanges
|
|
1448
|
-
*/
|
|
1449
|
-
async setProjectValue(projectId, path, value, options = {}) {
|
|
1450
|
-
const changes = [["set", path, value]];
|
|
1451
|
-
const message = options.message || `Set ${Array.isArray(path) ? path.join(".") : path}`;
|
|
1452
|
-
return await this.applyProjectChanges(projectId, changes, {
|
|
1453
|
-
...options,
|
|
1454
|
-
message
|
|
1455
|
-
});
|
|
1456
|
-
}
|
|
1457
|
-
/**
|
|
1458
|
-
* Helper method to add multiple items to the project
|
|
1459
|
-
* Convenience wrapper around applyProjectChanges
|
|
1460
|
-
*/
|
|
1461
|
-
async addProjectItems(projectId, items, options = {}) {
|
|
1462
|
-
const changes = items.map((item) => {
|
|
1463
|
-
const [type, data] = item;
|
|
1464
|
-
const { value, ...schema } = data;
|
|
1465
|
-
return [
|
|
1466
|
-
["update", [type, data.key], value],
|
|
1467
|
-
["update", ["schema", type, data.key], schema]
|
|
1468
|
-
];
|
|
1469
|
-
}).flat();
|
|
1470
|
-
const message = options.message || `Added ${items.length} items`;
|
|
1471
|
-
return await this.applyProjectChanges(projectId, changes, {
|
|
1472
|
-
...options,
|
|
1473
|
-
message
|
|
1474
|
-
});
|
|
1475
|
-
}
|
|
1476
|
-
/**
|
|
1477
|
-
* Helper method to get specific data from project by path
|
|
1478
|
-
* Convenience wrapper that gets project data and extracts specific path
|
|
1479
|
-
*/
|
|
1480
|
-
async getProjectItemByPath(projectId, path, options = {}) {
|
|
1481
|
-
const projectData = await this.getProjectData(projectId, options);
|
|
1482
|
-
if (!(projectData == null ? void 0 : projectData.data)) {
|
|
1483
|
-
return null;
|
|
1484
|
-
}
|
|
1485
|
-
let current = projectData.data;
|
|
1486
|
-
const pathArray = Array.isArray(path) ? path : [path];
|
|
1487
|
-
for (const segment of pathArray) {
|
|
1488
|
-
if (current && typeof current === "object" && segment in current) {
|
|
1489
|
-
current = current[segment];
|
|
1490
|
-
} else {
|
|
1491
|
-
return null;
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
return current;
|
|
1495
|
-
}
|
|
1496
|
-
// ==================== PULL REQUEST METHODS ====================
|
|
1497
|
-
/**
|
|
1498
|
-
* Create a new pull request
|
|
1499
|
-
*/
|
|
1500
|
-
async createPullRequest(projectId, pullRequestData) {
|
|
1501
|
-
this._requireReady("createPullRequest");
|
|
1502
|
-
if (!projectId) {
|
|
1503
|
-
throw new Error("Project ID is required");
|
|
1504
|
-
}
|
|
1505
|
-
if (!pullRequestData.source || !pullRequestData.target || !pullRequestData.title) {
|
|
1506
|
-
throw new Error("Source branch, target branch, and title are required");
|
|
1507
|
-
}
|
|
1508
|
-
try {
|
|
1509
|
-
const response = await this._request(`/projects/${projectId}/pull-requests`, {
|
|
1510
|
-
method: "POST",
|
|
1511
|
-
body: JSON.stringify(pullRequestData),
|
|
1512
|
-
methodName: "createPullRequest"
|
|
1513
|
-
});
|
|
1514
|
-
if (response.success) {
|
|
1515
|
-
return response.data;
|
|
1516
|
-
}
|
|
1517
|
-
throw new Error(response.message);
|
|
1518
|
-
} catch (error) {
|
|
1519
|
-
throw new Error(`Failed to create pull request: ${error.message}`);
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1522
|
-
/**
|
|
1523
|
-
* List pull requests for a project with filtering options
|
|
1524
|
-
*/
|
|
1525
|
-
async listPullRequests(projectId, options = {}) {
|
|
1526
|
-
this._requireReady("listPullRequests");
|
|
1527
|
-
if (!projectId) {
|
|
1528
|
-
throw new Error("Project ID is required");
|
|
1529
|
-
}
|
|
1530
|
-
const {
|
|
1531
|
-
status = "open",
|
|
1532
|
-
source,
|
|
1533
|
-
target,
|
|
1534
|
-
page = 1,
|
|
1535
|
-
limit = 20
|
|
1536
|
-
} = options;
|
|
1537
|
-
const queryParams = new URLSearchParams({
|
|
1538
|
-
status,
|
|
1539
|
-
page: page.toString(),
|
|
1540
|
-
limit: limit.toString()
|
|
1541
|
-
});
|
|
1542
|
-
if (source) {
|
|
1543
|
-
queryParams.append("source", source);
|
|
1544
|
-
}
|
|
1545
|
-
if (target) {
|
|
1546
|
-
queryParams.append("target", target);
|
|
1547
|
-
}
|
|
1548
|
-
try {
|
|
1549
|
-
const response = await this._request(`/projects/${projectId}/pull-requests?${queryParams.toString()}`, {
|
|
1550
|
-
method: "GET",
|
|
1551
|
-
methodName: "listPullRequests"
|
|
1552
|
-
});
|
|
1553
|
-
if (response.success) {
|
|
1554
|
-
return response.data;
|
|
1555
|
-
}
|
|
1556
|
-
throw new Error(response.message);
|
|
1557
|
-
} catch (error) {
|
|
1558
|
-
throw new Error(`Failed to list pull requests: ${error.message}`);
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
/**
|
|
1562
|
-
* Get detailed information about a specific pull request
|
|
1563
|
-
*/
|
|
1564
|
-
async getPullRequest(projectId, prId) {
|
|
1565
|
-
this._requireReady("getPullRequest");
|
|
1566
|
-
if (!projectId) {
|
|
1567
|
-
throw new Error("Project ID is required");
|
|
1568
|
-
}
|
|
1569
|
-
if (!prId) {
|
|
1570
|
-
throw new Error("Pull request ID is required");
|
|
1571
|
-
}
|
|
1572
|
-
try {
|
|
1573
|
-
const response = await this._request(`/projects/${projectId}/pull-requests/${prId}`, {
|
|
1574
|
-
method: "GET",
|
|
1575
|
-
methodName: "getPullRequest"
|
|
1576
|
-
});
|
|
1577
|
-
if (response.success) {
|
|
1578
|
-
return response.data;
|
|
1579
|
-
}
|
|
1580
|
-
throw new Error(response.message);
|
|
1581
|
-
} catch (error) {
|
|
1582
|
-
throw new Error(`Failed to get pull request: ${error.message}`);
|
|
1583
|
-
}
|
|
1584
|
-
}
|
|
1585
|
-
/**
|
|
1586
|
-
* Submit a review for a pull request
|
|
1587
|
-
*/
|
|
1588
|
-
async reviewPullRequest(projectId, prId, reviewData) {
|
|
1589
|
-
this._requireReady("reviewPullRequest");
|
|
1590
|
-
if (!projectId) {
|
|
1591
|
-
throw new Error("Project ID is required");
|
|
1592
|
-
}
|
|
1593
|
-
if (!prId) {
|
|
1594
|
-
throw new Error("Pull request ID is required");
|
|
1595
|
-
}
|
|
1596
|
-
const validStatuses = ["approved", "requested_changes", "feedback"];
|
|
1597
|
-
if (reviewData.status && !validStatuses.includes(reviewData.status)) {
|
|
1598
|
-
throw new Error(`Invalid review status. Must be one of: ${validStatuses.join(", ")}`);
|
|
1599
|
-
}
|
|
1600
|
-
try {
|
|
1601
|
-
const response = await this._request(`/projects/${projectId}/pull-requests/${prId}/review`, {
|
|
1602
|
-
method: "POST",
|
|
1603
|
-
body: JSON.stringify(reviewData),
|
|
1604
|
-
methodName: "reviewPullRequest"
|
|
1605
|
-
});
|
|
1606
|
-
if (response.success) {
|
|
1607
|
-
return response.data;
|
|
1608
|
-
}
|
|
1609
|
-
throw new Error(response.message);
|
|
1610
|
-
} catch (error) {
|
|
1611
|
-
throw new Error(`Failed to review pull request: ${error.message}`);
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
/**
|
|
1615
|
-
* Add a comment to an existing review thread
|
|
1616
|
-
*/
|
|
1617
|
-
async addPullRequestComment(projectId, prId, commentData) {
|
|
1618
|
-
this._requireReady("addPullRequestComment");
|
|
1619
|
-
if (!projectId) {
|
|
1620
|
-
throw new Error("Project ID is required");
|
|
1621
|
-
}
|
|
1622
|
-
if (!prId) {
|
|
1623
|
-
throw new Error("Pull request ID is required");
|
|
1624
|
-
}
|
|
1625
|
-
if (!commentData.value) {
|
|
1626
|
-
throw new Error("Comment value is required");
|
|
1627
|
-
}
|
|
1628
|
-
try {
|
|
1629
|
-
const response = await this._request(`/projects/${projectId}/pull-requests/${prId}/comment`, {
|
|
1630
|
-
method: "POST",
|
|
1631
|
-
body: JSON.stringify(commentData),
|
|
1632
|
-
methodName: "addPullRequestComment"
|
|
1633
|
-
});
|
|
1634
|
-
if (response.success) {
|
|
1635
|
-
return response.data;
|
|
1636
|
-
}
|
|
1637
|
-
throw new Error(response.message);
|
|
1638
|
-
} catch (error) {
|
|
1639
|
-
throw new Error(`Failed to add pull request comment: ${error.message}`);
|
|
1640
|
-
}
|
|
1641
|
-
}
|
|
1642
|
-
/**
|
|
1643
|
-
* Merge an approved pull request
|
|
1644
|
-
*/
|
|
1645
|
-
async mergePullRequest(projectId, prId) {
|
|
1646
|
-
this._requireReady("mergePullRequest");
|
|
1647
|
-
if (!projectId) {
|
|
1648
|
-
throw new Error("Project ID is required");
|
|
1649
|
-
}
|
|
1650
|
-
if (!prId) {
|
|
1651
|
-
throw new Error("Pull request ID is required");
|
|
1652
|
-
}
|
|
1653
|
-
try {
|
|
1654
|
-
const response = await this._request(`/projects/${projectId}/pull-requests/${prId}/merge`, {
|
|
1655
|
-
method: "POST",
|
|
1656
|
-
methodName: "mergePullRequest"
|
|
1657
|
-
});
|
|
1658
|
-
if (response.success) {
|
|
1659
|
-
return response.data;
|
|
1660
|
-
}
|
|
1661
|
-
throw new Error(response.message);
|
|
1662
|
-
} catch (error) {
|
|
1663
|
-
if (error.message.includes("conflicts") || error.message.includes("409")) {
|
|
1664
|
-
throw new Error(`Pull request has merge conflicts: ${error.message}`);
|
|
1665
|
-
}
|
|
1666
|
-
throw new Error(`Failed to merge pull request: ${error.message}`);
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
/**
|
|
1670
|
-
* Get the diff/changes for a pull request
|
|
1671
|
-
*/
|
|
1672
|
-
async getPullRequestDiff(projectId, prId) {
|
|
1673
|
-
this._requireReady("getPullRequestDiff");
|
|
1674
|
-
if (!projectId) {
|
|
1675
|
-
throw new Error("Project ID is required");
|
|
1676
|
-
}
|
|
1677
|
-
if (!prId) {
|
|
1678
|
-
throw new Error("Pull request ID is required");
|
|
1679
|
-
}
|
|
1680
|
-
try {
|
|
1681
|
-
const response = await this._request(`/projects/${projectId}/pull-requests/${prId}/diff`, {
|
|
1682
|
-
method: "GET",
|
|
1683
|
-
methodName: "getPullRequestDiff"
|
|
1684
|
-
});
|
|
1685
|
-
if (response.success) {
|
|
1686
|
-
return response.data;
|
|
1687
|
-
}
|
|
1688
|
-
throw new Error(response.message);
|
|
1689
|
-
} catch (error) {
|
|
1690
|
-
throw new Error(`Failed to get pull request diff: ${error.message}`);
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
/**
|
|
1694
|
-
* Helper method to create a pull request with validation
|
|
1695
|
-
*/
|
|
1696
|
-
async createPullRequestWithValidation(projectId, data) {
|
|
1697
|
-
const { source, target, title, description, changes } = data;
|
|
1698
|
-
if (source === target) {
|
|
1699
|
-
throw new Error("Source and target branches cannot be the same");
|
|
1700
|
-
}
|
|
1701
|
-
if (!title || title.trim().length === 0) {
|
|
1702
|
-
throw new Error("Pull request title cannot be empty");
|
|
1703
|
-
}
|
|
1704
|
-
if (title.length > 200) {
|
|
1705
|
-
throw new Error("Pull request title cannot exceed 200 characters");
|
|
1706
|
-
}
|
|
1707
|
-
const pullRequestData = {
|
|
1708
|
-
source: source.trim(),
|
|
1709
|
-
target: target.trim(),
|
|
1710
|
-
title: title.trim(),
|
|
1711
|
-
...description && { description: description.trim() },
|
|
1712
|
-
...changes && { changes }
|
|
1713
|
-
};
|
|
1714
|
-
return await this.createPullRequest(projectId, pullRequestData);
|
|
1715
|
-
}
|
|
1716
|
-
/**
|
|
1717
|
-
* Helper method to approve a pull request
|
|
1718
|
-
*/
|
|
1719
|
-
async approvePullRequest(projectId, prId, comment = "") {
|
|
1720
|
-
const reviewData = {
|
|
1721
|
-
status: "approved",
|
|
1722
|
-
...comment && {
|
|
1723
|
-
threads: [{
|
|
1724
|
-
comment,
|
|
1725
|
-
type: "praise"
|
|
1726
|
-
}]
|
|
1727
|
-
}
|
|
1728
|
-
};
|
|
1729
|
-
return await this.reviewPullRequest(projectId, prId, reviewData);
|
|
1730
|
-
}
|
|
1731
|
-
/**
|
|
1732
|
-
* Helper method to request changes on a pull request
|
|
1733
|
-
*/
|
|
1734
|
-
async requestPullRequestChanges(projectId, prId, threads = []) {
|
|
1735
|
-
if (!threads || threads.length === 0) {
|
|
1736
|
-
throw new Error("Must provide specific feedback when requesting changes");
|
|
1737
|
-
}
|
|
1738
|
-
const reviewData = {
|
|
1739
|
-
status: "requested_changes",
|
|
1740
|
-
threads
|
|
1741
|
-
};
|
|
1742
|
-
return await this.reviewPullRequest(projectId, prId, reviewData);
|
|
1743
|
-
}
|
|
1744
|
-
/**
|
|
1745
|
-
* Helper method to get pull requests by status
|
|
1746
|
-
*/
|
|
1747
|
-
async getOpenPullRequests(projectId, options = {}) {
|
|
1748
|
-
return await this.listPullRequests(projectId, { ...options, status: "open" });
|
|
1749
|
-
}
|
|
1750
|
-
async getClosedPullRequests(projectId, options = {}) {
|
|
1751
|
-
return await this.listPullRequests(projectId, { ...options, status: "closed" });
|
|
1752
|
-
}
|
|
1753
|
-
async getMergedPullRequests(projectId, options = {}) {
|
|
1754
|
-
return await this.listPullRequests(projectId, { ...options, status: "merged" });
|
|
1755
|
-
}
|
|
1756
|
-
/**
|
|
1757
|
-
* Helper method to check if a pull request is canMerge
|
|
1758
|
-
*/
|
|
1759
|
-
async isPullRequestMergeable(projectId, prId) {
|
|
1760
|
-
var _a;
|
|
1761
|
-
try {
|
|
1762
|
-
const prData = await this.getPullRequest(projectId, prId);
|
|
1763
|
-
return ((_a = prData == null ? void 0 : prData.data) == null ? void 0 : _a.canMerge) || false;
|
|
1764
|
-
} catch (error) {
|
|
1765
|
-
throw new Error(`Failed to check pull request mergeability: ${error.message}`);
|
|
1766
|
-
}
|
|
1767
|
-
}
|
|
1768
|
-
/**
|
|
1769
|
-
* Helper method to get pull request status summary
|
|
1770
|
-
*/
|
|
1771
|
-
async getPullRequestStatusSummary(projectId, prId) {
|
|
1772
|
-
var _a, _b, _c;
|
|
1773
|
-
try {
|
|
1774
|
-
const prData = await this.getPullRequest(projectId, prId);
|
|
1775
|
-
const pr = prData == null ? void 0 : prData.data;
|
|
1776
|
-
if (!pr) {
|
|
1777
|
-
throw new Error("Pull request not found");
|
|
1778
|
-
}
|
|
1779
|
-
return {
|
|
1780
|
-
status: pr.status,
|
|
1781
|
-
reviewStatus: pr.reviewStatus,
|
|
1782
|
-
canMerge: pr.canMerge,
|
|
1783
|
-
hasConflicts: !pr.canMerge,
|
|
1784
|
-
reviewCount: ((_a = pr.reviews) == null ? void 0 : _a.length) || 0,
|
|
1785
|
-
approvedReviews: ((_b = pr.reviews) == null ? void 0 : _b.filter((r) => r.status === "approved").length) || 0,
|
|
1786
|
-
changesRequested: ((_c = pr.reviews) == null ? void 0 : _c.filter((r) => r.status === "requested_changes").length) || 0
|
|
1787
|
-
};
|
|
1788
|
-
} catch (error) {
|
|
1789
|
-
throw new Error(`Failed to get pull request status summary: ${error.message}`);
|
|
1790
|
-
}
|
|
1791
|
-
}
|
|
1792
|
-
// ==================== BRANCH MANAGEMENT METHODS ====================
|
|
1793
|
-
/**
|
|
1794
|
-
* Get all branches for a project
|
|
1795
|
-
*/
|
|
1796
|
-
async listBranches(projectId) {
|
|
1797
|
-
this._requireReady("listBranches");
|
|
1798
|
-
if (!projectId) {
|
|
1799
|
-
throw new Error("Project ID is required");
|
|
1800
|
-
}
|
|
1801
|
-
try {
|
|
1802
|
-
const response = await this._request(`/projects/${projectId}/branches`, {
|
|
1803
|
-
method: "GET",
|
|
1804
|
-
methodName: "listBranches"
|
|
1805
|
-
});
|
|
1806
|
-
if (response.success) {
|
|
1807
|
-
return response.data;
|
|
1808
|
-
}
|
|
1809
|
-
throw new Error(response.message);
|
|
1810
|
-
} catch (error) {
|
|
1811
|
-
throw new Error(`Failed to list branches: ${error.message}`);
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
/**
|
|
1815
|
-
* Create a new branch from an existing branch
|
|
1816
|
-
*/
|
|
1817
|
-
async createBranch(projectId, branchData) {
|
|
1818
|
-
this._requireReady("createBranch");
|
|
1819
|
-
if (!projectId) {
|
|
1820
|
-
throw new Error("Project ID is required");
|
|
1821
|
-
}
|
|
1822
|
-
if (!branchData.name) {
|
|
1823
|
-
throw new Error("Branch name is required");
|
|
1824
|
-
}
|
|
1825
|
-
const { name, source = "main" } = branchData;
|
|
1826
|
-
try {
|
|
1827
|
-
const response = await this._request(`/projects/${projectId}/branches`, {
|
|
1828
|
-
method: "POST",
|
|
1829
|
-
body: JSON.stringify({ name, source }),
|
|
1830
|
-
methodName: "createBranch"
|
|
1831
|
-
});
|
|
1832
|
-
if (response.success) {
|
|
1833
|
-
return response.data;
|
|
1834
|
-
}
|
|
1835
|
-
throw new Error(response.message);
|
|
1836
|
-
} catch (error) {
|
|
1837
|
-
throw new Error(`Failed to create branch: ${error.message}`);
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
/**
|
|
1841
|
-
* Delete a branch (cannot delete main branch)
|
|
1842
|
-
*/
|
|
1843
|
-
async deleteBranch(projectId, branchName) {
|
|
1844
|
-
this._requireReady("deleteBranch");
|
|
1845
|
-
if (!projectId) {
|
|
1846
|
-
throw new Error("Project ID is required");
|
|
1847
|
-
}
|
|
1848
|
-
if (!branchName) {
|
|
1849
|
-
throw new Error("Branch name is required");
|
|
1850
|
-
}
|
|
1851
|
-
if (branchName === "main") {
|
|
1852
|
-
throw new Error("Cannot delete main branch");
|
|
1853
|
-
}
|
|
1854
|
-
try {
|
|
1855
|
-
const response = await this._request(`/projects/${projectId}/branches/${encodeURIComponent(branchName)}`, {
|
|
1856
|
-
method: "DELETE",
|
|
1857
|
-
methodName: "deleteBranch"
|
|
1858
|
-
});
|
|
1859
|
-
if (response.success) {
|
|
1860
|
-
return response.data;
|
|
1861
|
-
}
|
|
1862
|
-
throw new Error(response.message);
|
|
1863
|
-
} catch (error) {
|
|
1864
|
-
throw new Error(`Failed to delete branch: ${error.message}`);
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
/**
|
|
1868
|
-
* Rename a branch (cannot rename main branch)
|
|
1869
|
-
*/
|
|
1870
|
-
async renameBranch(projectId, branchName, newName) {
|
|
1871
|
-
this._requireReady("renameBranch");
|
|
1872
|
-
if (!projectId) {
|
|
1873
|
-
throw new Error("Project ID is required");
|
|
1874
|
-
}
|
|
1875
|
-
if (!branchName) {
|
|
1876
|
-
throw new Error("Current branch name is required");
|
|
1877
|
-
}
|
|
1878
|
-
if (!newName) {
|
|
1879
|
-
throw new Error("New branch name is required");
|
|
1880
|
-
}
|
|
1881
|
-
if (branchName === "main") {
|
|
1882
|
-
throw new Error("Cannot rename main branch");
|
|
1883
|
-
}
|
|
1884
|
-
try {
|
|
1885
|
-
const response = await this._request(`/projects/${projectId}/branches/${encodeURIComponent(branchName)}/rename`, {
|
|
1886
|
-
method: "POST",
|
|
1887
|
-
body: JSON.stringify({ newName }),
|
|
1888
|
-
methodName: "renameBranch"
|
|
1889
|
-
});
|
|
1890
|
-
if (response.success) {
|
|
1891
|
-
return response.data;
|
|
1892
|
-
}
|
|
1893
|
-
throw new Error(response.message);
|
|
1894
|
-
} catch (error) {
|
|
1895
|
-
throw new Error(`Failed to rename branch: ${error.message}`);
|
|
1896
|
-
}
|
|
1897
|
-
}
|
|
1898
|
-
/**
|
|
1899
|
-
* Get changes/diff for a branch compared to another version
|
|
1900
|
-
*/
|
|
1901
|
-
async getBranchChanges(projectId, branchName = "main", options = {}) {
|
|
1902
|
-
this._requireReady("getBranchChanges");
|
|
1903
|
-
if (!projectId) {
|
|
1904
|
-
throw new Error("Project ID is required");
|
|
1905
|
-
}
|
|
1906
|
-
if (!branchName) {
|
|
1907
|
-
throw new Error("Branch name is required");
|
|
1908
|
-
}
|
|
1909
|
-
const { versionId, versionValue, target } = options;
|
|
1910
|
-
const queryParams = new URLSearchParams();
|
|
1911
|
-
if (versionId) {
|
|
1912
|
-
queryParams.append("versionId", versionId);
|
|
1913
|
-
}
|
|
1914
|
-
if (versionValue) {
|
|
1915
|
-
queryParams.append("versionValue", versionValue);
|
|
1916
|
-
}
|
|
1917
|
-
if (target) {
|
|
1918
|
-
queryParams.append("target", target);
|
|
1919
|
-
}
|
|
1920
|
-
const queryString = queryParams.toString();
|
|
1921
|
-
const url = `/projects/${projectId}/branches/${encodeURIComponent(branchName)}/changes${queryString ? `?${queryString}` : ""}`;
|
|
1922
|
-
try {
|
|
1923
|
-
const response = await this._request(url, {
|
|
1924
|
-
method: "GET",
|
|
1925
|
-
methodName: "getBranchChanges"
|
|
1926
|
-
});
|
|
1927
|
-
if (response.success) {
|
|
1928
|
-
return response.data;
|
|
1929
|
-
}
|
|
1930
|
-
throw new Error(response.message);
|
|
1931
|
-
} catch (error) {
|
|
1932
|
-
throw new Error(`Failed to get branch changes: ${error.message}`);
|
|
1933
|
-
}
|
|
1934
|
-
}
|
|
1935
|
-
/**
|
|
1936
|
-
* Merge changes between branches (preview or commit)
|
|
1937
|
-
*/
|
|
1938
|
-
async mergeBranch(projectId, branchName, mergeData = {}) {
|
|
1939
|
-
this._requireReady("mergeBranch");
|
|
1940
|
-
if (!projectId) {
|
|
1941
|
-
throw new Error("Project ID is required");
|
|
1942
|
-
}
|
|
1943
|
-
if (!branchName) {
|
|
1944
|
-
throw new Error("Source branch name is required");
|
|
1945
|
-
}
|
|
1946
|
-
const {
|
|
1947
|
-
target = "main",
|
|
1948
|
-
message,
|
|
1949
|
-
type = "patch",
|
|
1950
|
-
commit = false,
|
|
1951
|
-
changes
|
|
1952
|
-
} = mergeData;
|
|
1953
|
-
const requestBody = {
|
|
1954
|
-
target,
|
|
1955
|
-
type,
|
|
1956
|
-
commit,
|
|
1957
|
-
...message && { message },
|
|
1958
|
-
...changes && { changes }
|
|
1959
|
-
};
|
|
1960
|
-
try {
|
|
1961
|
-
const response = await this._request(`/projects/${projectId}/branches/${encodeURIComponent(branchName)}/merge`, {
|
|
1962
|
-
method: "POST",
|
|
1963
|
-
body: JSON.stringify(requestBody),
|
|
1964
|
-
methodName: "mergeBranch"
|
|
1965
|
-
});
|
|
1966
|
-
if (response.success) {
|
|
1967
|
-
return response.data;
|
|
1968
|
-
}
|
|
1969
|
-
throw new Error(response.message);
|
|
1970
|
-
} catch (error) {
|
|
1971
|
-
if (error.message.includes("conflicts") || error.message.includes("409")) {
|
|
1972
|
-
throw new Error(`Merge conflicts detected: ${error.message}`);
|
|
1973
|
-
}
|
|
1974
|
-
throw new Error(`Failed to merge branch: ${error.message}`);
|
|
1975
|
-
}
|
|
1976
|
-
}
|
|
1977
|
-
/**
|
|
1978
|
-
* Reset a branch to a clean state
|
|
1979
|
-
*/
|
|
1980
|
-
async resetBranch(projectId, branchName) {
|
|
1981
|
-
this._requireReady("resetBranch");
|
|
1982
|
-
if (!projectId) {
|
|
1983
|
-
throw new Error("Project ID is required");
|
|
1984
|
-
}
|
|
1985
|
-
if (!branchName) {
|
|
1986
|
-
throw new Error("Branch name is required");
|
|
1987
|
-
}
|
|
1988
|
-
try {
|
|
1989
|
-
const response = await this._request(`/projects/${projectId}/branches/${encodeURIComponent(branchName)}/reset`, {
|
|
1990
|
-
method: "POST",
|
|
1991
|
-
methodName: "resetBranch"
|
|
1992
|
-
});
|
|
1993
|
-
if (response.success) {
|
|
1994
|
-
return response.data;
|
|
1995
|
-
}
|
|
1996
|
-
throw new Error(response.message);
|
|
1997
|
-
} catch (error) {
|
|
1998
|
-
throw new Error(`Failed to reset branch: ${error.message}`);
|
|
1999
|
-
}
|
|
2000
|
-
}
|
|
2001
|
-
/**
|
|
2002
|
-
* Publish a specific version as the live version
|
|
2003
|
-
*/
|
|
2004
|
-
async publishVersion(projectId, publishData) {
|
|
2005
|
-
this._requireReady("publishVersion");
|
|
2006
|
-
if (!projectId) {
|
|
2007
|
-
throw new Error("Project ID is required");
|
|
2008
|
-
}
|
|
2009
|
-
if (!publishData.version) {
|
|
2010
|
-
throw new Error("Version is required");
|
|
2011
|
-
}
|
|
2012
|
-
const { version, branch = "main" } = publishData;
|
|
2013
|
-
try {
|
|
2014
|
-
const response = await this._request(`/projects/${projectId}/publish`, {
|
|
2015
|
-
method: "POST",
|
|
2016
|
-
body: JSON.stringify({ version, branch }),
|
|
2017
|
-
methodName: "publishVersion"
|
|
2018
|
-
});
|
|
2019
|
-
if (response.success) {
|
|
2020
|
-
return response.data;
|
|
2021
|
-
}
|
|
2022
|
-
throw new Error(response.message);
|
|
2023
|
-
} catch (error) {
|
|
2024
|
-
throw new Error(`Failed to publish version: ${error.message}`);
|
|
2025
|
-
}
|
|
2026
|
-
}
|
|
2027
|
-
// ==================== BRANCH HELPER METHODS ====================
|
|
2028
|
-
/**
|
|
2029
|
-
* Helper method to create a branch with validation
|
|
2030
|
-
*/
|
|
2031
|
-
async createBranchWithValidation(projectId, name, source = "main") {
|
|
2032
|
-
if (!name || name.trim().length === 0) {
|
|
2033
|
-
throw new Error("Branch name cannot be empty");
|
|
2034
|
-
}
|
|
2035
|
-
if (name.includes(" ")) {
|
|
2036
|
-
throw new Error("Branch name cannot contain spaces");
|
|
2037
|
-
}
|
|
2038
|
-
if (name === "main") {
|
|
2039
|
-
throw new Error('Cannot create a branch named "main"');
|
|
2040
|
-
}
|
|
2041
|
-
const sanitizedName = name.trim().toLowerCase().replace(/[^a-z0-9-_]/gu, "-");
|
|
2042
|
-
return await this.createBranch(projectId, {
|
|
2043
|
-
name: sanitizedName,
|
|
2044
|
-
source
|
|
2045
|
-
});
|
|
2046
|
-
}
|
|
2047
|
-
/**
|
|
2048
|
-
* Helper method to check if a branch exists
|
|
2049
|
-
*/
|
|
2050
|
-
async branchExists(projectId, branchName) {
|
|
2051
|
-
var _a;
|
|
2052
|
-
try {
|
|
2053
|
-
const branches = await this.listBranches(projectId);
|
|
2054
|
-
return ((_a = branches == null ? void 0 : branches.data) == null ? void 0 : _a.includes(branchName)) || false;
|
|
2055
|
-
} catch (error) {
|
|
2056
|
-
throw new Error(`Failed to check if branch exists: ${error.message}`);
|
|
2057
|
-
}
|
|
2058
|
-
}
|
|
2059
|
-
/**
|
|
2060
|
-
* Helper method to preview merge without committing
|
|
2061
|
-
*/
|
|
2062
|
-
async previewMerge(projectId, sourceBranch, targetBranch = "main") {
|
|
2063
|
-
return await this.mergeBranch(projectId, sourceBranch, {
|
|
2064
|
-
target: targetBranch,
|
|
2065
|
-
commit: false
|
|
2066
|
-
});
|
|
2067
|
-
}
|
|
2068
|
-
/**
|
|
2069
|
-
* Helper method to commit merge after preview
|
|
2070
|
-
*/
|
|
2071
|
-
async commitMerge(projectId, sourceBranch, options = {}) {
|
|
2072
|
-
const {
|
|
2073
|
-
target = "main",
|
|
2074
|
-
message = `Merge ${sourceBranch} into ${target}`,
|
|
2075
|
-
type = "patch",
|
|
2076
|
-
changes
|
|
2077
|
-
} = options;
|
|
2078
|
-
return await this.mergeBranch(projectId, sourceBranch, {
|
|
2079
|
-
target,
|
|
2080
|
-
message,
|
|
2081
|
-
type,
|
|
2082
|
-
commit: true,
|
|
2083
|
-
changes
|
|
2084
|
-
});
|
|
2085
|
-
}
|
|
2086
|
-
/**
|
|
2087
|
-
* Helper method to create a feature branch from main
|
|
2088
|
-
*/
|
|
2089
|
-
async createFeatureBranch(projectId, featureName) {
|
|
2090
|
-
const branchName = `feature/${featureName.toLowerCase().replace(/[^a-z0-9-]/gu, "-")}`;
|
|
2091
|
-
return await this.createBranch(projectId, {
|
|
2092
|
-
name: branchName,
|
|
2093
|
-
source: "main"
|
|
2094
|
-
});
|
|
2095
|
-
}
|
|
2096
|
-
/**
|
|
2097
|
-
* Helper method to create a hotfix branch from main
|
|
2098
|
-
*/
|
|
2099
|
-
async createHotfixBranch(projectId, hotfixName) {
|
|
2100
|
-
const branchName = `hotfix/${hotfixName.toLowerCase().replace(/[^a-z0-9-]/gu, "-")}`;
|
|
2101
|
-
return await this.createBranch(projectId, {
|
|
2102
|
-
name: branchName,
|
|
2103
|
-
source: "main"
|
|
2104
|
-
});
|
|
2105
|
-
}
|
|
2106
|
-
/**
|
|
2107
|
-
* Helper method to get branch status summary
|
|
2108
|
-
*/
|
|
2109
|
-
async getBranchStatus(projectId, branchName) {
|
|
2110
|
-
var _a, _b, _c;
|
|
2111
|
-
try {
|
|
2112
|
-
const [branches, changes] = await Promise.all([
|
|
2113
|
-
this.listBranches(projectId),
|
|
2114
|
-
this.getBranchChanges(projectId, branchName).catch(() => null)
|
|
2115
|
-
]);
|
|
2116
|
-
const exists = ((_a = branches == null ? void 0 : branches.data) == null ? void 0 : _a.includes(branchName)) || false;
|
|
2117
|
-
const hasChanges = ((_b = changes == null ? void 0 : changes.data) == null ? void 0 : _b.length) > 0;
|
|
2118
|
-
return {
|
|
2119
|
-
exists,
|
|
2120
|
-
hasChanges,
|
|
2121
|
-
changeCount: ((_c = changes == null ? void 0 : changes.data) == null ? void 0 : _c.length) || 0,
|
|
2122
|
-
canDelete: exists && branchName !== "main",
|
|
2123
|
-
canRename: exists && branchName !== "main"
|
|
2124
|
-
};
|
|
2125
|
-
} catch (error) {
|
|
2126
|
-
throw new Error(`Failed to get branch status: ${error.message}`);
|
|
2127
|
-
}
|
|
2128
|
-
}
|
|
2129
|
-
/**
|
|
2130
|
-
* Helper method to safely delete a branch with confirmation
|
|
2131
|
-
*/
|
|
2132
|
-
async deleteBranchSafely(projectId, branchName, options = {}) {
|
|
2133
|
-
const { force = false } = options;
|
|
2134
|
-
if (!force) {
|
|
2135
|
-
const status = await this.getBranchStatus(projectId, branchName);
|
|
2136
|
-
if (!status.exists) {
|
|
2137
|
-
throw new Error(`Branch '${branchName}' does not exist`);
|
|
2138
|
-
}
|
|
2139
|
-
if (!status.canDelete) {
|
|
2140
|
-
throw new Error(`Branch '${branchName}' cannot be deleted`);
|
|
2141
|
-
}
|
|
2142
|
-
if (status.hasChanges) {
|
|
2143
|
-
throw new Error(`Branch '${branchName}' has uncommitted changes. Use force option to delete anyway.`);
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
return await this.deleteBranch(projectId, branchName);
|
|
2147
|
-
}
|
|
2148
|
-
// ==================== ADMIN METHODS ====================
|
|
2149
|
-
/**
|
|
2150
|
-
* Get admin users list with comprehensive filtering and search capabilities
|
|
2151
|
-
* Requires admin or super_admin global role
|
|
2152
|
-
*/
|
|
2153
|
-
async getAdminUsers(params = {}) {
|
|
2154
|
-
this._requireReady("getAdminUsers");
|
|
2155
|
-
const {
|
|
2156
|
-
emails,
|
|
2157
|
-
ids,
|
|
2158
|
-
query,
|
|
2159
|
-
status,
|
|
2160
|
-
page = 1,
|
|
2161
|
-
limit = 50,
|
|
2162
|
-
sort = { field: "createdAt", order: "desc" }
|
|
2163
|
-
} = params;
|
|
2164
|
-
const queryParams = new URLSearchParams();
|
|
2165
|
-
if (emails) {
|
|
2166
|
-
queryParams.append("emails", emails);
|
|
2167
|
-
}
|
|
2168
|
-
if (ids) {
|
|
2169
|
-
queryParams.append("ids", ids);
|
|
2170
|
-
}
|
|
2171
|
-
if (query) {
|
|
2172
|
-
queryParams.append("query", query);
|
|
2173
|
-
}
|
|
2174
|
-
if (status) {
|
|
2175
|
-
queryParams.append("status", status);
|
|
2176
|
-
}
|
|
2177
|
-
if (page) {
|
|
2178
|
-
queryParams.append("page", page.toString());
|
|
2179
|
-
}
|
|
2180
|
-
if (limit) {
|
|
2181
|
-
queryParams.append("limit", limit.toString());
|
|
2182
|
-
}
|
|
2183
|
-
if (sort && sort.field) {
|
|
2184
|
-
queryParams.append("sort[field]", sort.field);
|
|
2185
|
-
queryParams.append("sort[order]", sort.order || "desc");
|
|
2186
|
-
}
|
|
2187
|
-
const queryString = queryParams.toString();
|
|
2188
|
-
const url = `/users/admin/users${queryString ? `?${queryString}` : ""}`;
|
|
2189
|
-
try {
|
|
2190
|
-
const response = await this._request(url, {
|
|
2191
|
-
method: "GET",
|
|
2192
|
-
methodName: "getAdminUsers"
|
|
2193
|
-
});
|
|
2194
|
-
if (response.success) {
|
|
2195
|
-
return response.data;
|
|
2196
|
-
}
|
|
2197
|
-
throw new Error(response.message);
|
|
2198
|
-
} catch (error) {
|
|
2199
|
-
throw new Error(`Failed to get admin users: ${error.message}`);
|
|
2200
|
-
}
|
|
2201
|
-
}
|
|
2202
|
-
/**
|
|
2203
|
-
* Assign projects to a specific user
|
|
2204
|
-
* Requires admin or super_admin global role
|
|
2205
|
-
*/
|
|
2206
|
-
async assignProjectsToUser(userId, options = {}) {
|
|
2207
|
-
this._requireReady("assignProjectsToUser");
|
|
2208
|
-
if (!userId) {
|
|
2209
|
-
throw new Error("User ID is required");
|
|
2210
|
-
}
|
|
2211
|
-
const {
|
|
2212
|
-
projectIds,
|
|
2213
|
-
role = "guest"
|
|
2214
|
-
} = options;
|
|
2215
|
-
const requestBody = {
|
|
2216
|
-
userId,
|
|
2217
|
-
role
|
|
2218
|
-
};
|
|
2219
|
-
if (projectIds && Array.isArray(projectIds)) {
|
|
2220
|
-
requestBody.projectIds = projectIds;
|
|
2221
|
-
}
|
|
2222
|
-
try {
|
|
2223
|
-
const response = await this._request("/assign-projects", {
|
|
2224
|
-
method: "POST",
|
|
2225
|
-
body: JSON.stringify(requestBody),
|
|
2226
|
-
methodName: "assignProjectsToUser"
|
|
2227
|
-
});
|
|
2228
|
-
if (response.success) {
|
|
2229
|
-
return response.data;
|
|
2230
|
-
}
|
|
2231
|
-
throw new Error(response.message);
|
|
2232
|
-
} catch (error) {
|
|
2233
|
-
throw new Error(`Failed to assign projects to user: ${error.message}`);
|
|
2234
|
-
}
|
|
2235
|
-
}
|
|
2236
|
-
/**
|
|
2237
|
-
* Helper method for admin users search
|
|
2238
|
-
*/
|
|
2239
|
-
async searchAdminUsers(searchQuery, options = {}) {
|
|
2240
|
-
return await this.getAdminUsers({
|
|
2241
|
-
query: searchQuery,
|
|
2242
|
-
...options
|
|
2243
|
-
});
|
|
2244
|
-
}
|
|
2245
|
-
/**
|
|
2246
|
-
* Helper method to get admin users by email list
|
|
2247
|
-
*/
|
|
2248
|
-
async getAdminUsersByEmails(emails, options = {}) {
|
|
2249
|
-
const emailList = Array.isArray(emails) ? emails.join(",") : emails;
|
|
2250
|
-
return await this.getAdminUsers({
|
|
2251
|
-
emails: emailList,
|
|
2252
|
-
...options
|
|
2253
|
-
});
|
|
2254
|
-
}
|
|
2255
|
-
/**
|
|
2256
|
-
* Helper method to get admin users by ID list
|
|
2257
|
-
*/
|
|
2258
|
-
async getAdminUsersByIds(ids, options = {}) {
|
|
2259
|
-
const idList = Array.isArray(ids) ? ids.join(",") : ids;
|
|
2260
|
-
return await this.getAdminUsers({
|
|
2261
|
-
ids: idList,
|
|
2262
|
-
...options
|
|
2263
|
-
});
|
|
2264
|
-
}
|
|
2265
|
-
/**
|
|
2266
|
-
* Helper method to assign specific projects to a user with a specific role
|
|
2267
|
-
*/
|
|
2268
|
-
async assignSpecificProjectsToUser(userId, projectIds, role = "guest") {
|
|
2269
|
-
if (!Array.isArray(projectIds) || projectIds.length === 0) {
|
|
2270
|
-
throw new Error("Project IDs must be a non-empty array");
|
|
2271
|
-
}
|
|
2272
|
-
return await this.assignProjectsToUser(userId, {
|
|
2273
|
-
projectIds,
|
|
2274
|
-
role
|
|
2275
|
-
});
|
|
2276
|
-
}
|
|
2277
|
-
/**
|
|
2278
|
-
* Helper method to assign all projects to a user with a specific role
|
|
2279
|
-
*/
|
|
2280
|
-
async assignAllProjectsToUser(userId, role = "guest") {
|
|
2281
|
-
return await this.assignProjectsToUser(userId, {
|
|
2282
|
-
role
|
|
2283
|
-
});
|
|
2284
|
-
}
|
|
2285
|
-
// Cleanup
|
|
2286
|
-
destroy() {
|
|
2287
|
-
if (this._tokenManager) {
|
|
2288
|
-
this._tokenManager.destroy();
|
|
2289
|
-
this._tokenManager = null;
|
|
2290
|
-
}
|
|
2291
|
-
this._client = null;
|
|
2292
|
-
this._initialized = false;
|
|
2293
|
-
this._setReady(false);
|
|
2294
|
-
}
|
|
2295
|
-
}
|