@symbo.ls/sdk 3.2.3 → 3.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +141 -0
- package/dist/cjs/config/environment.js +94 -10
- package/dist/cjs/index.js +152 -12
- package/dist/cjs/services/AdminService.js +351 -0
- package/dist/cjs/services/AuthService.js +738 -305
- package/dist/cjs/services/BaseService.js +158 -6
- package/dist/cjs/services/BranchService.js +484 -0
- package/dist/cjs/services/CollabService.js +439 -116
- package/dist/cjs/services/DnsService.js +340 -0
- package/dist/cjs/services/FeatureFlagService.js +175 -0
- package/dist/cjs/services/FileService.js +201 -0
- package/dist/cjs/services/IntegrationService.js +538 -0
- package/dist/cjs/services/MetricsService.js +62 -0
- package/dist/cjs/services/PaymentService.js +271 -0
- package/dist/cjs/services/PlanService.js +426 -0
- package/dist/cjs/services/ProjectService.js +1207 -0
- package/dist/cjs/services/PullRequestService.js +503 -0
- package/dist/cjs/services/ScreenshotService.js +304 -0
- package/dist/cjs/services/SubscriptionService.js +396 -0
- package/dist/cjs/services/TrackingService.js +661 -0
- package/dist/cjs/services/WaitlistService.js +148 -0
- package/dist/cjs/services/index.js +60 -4
- package/dist/cjs/state/RootStateManager.js +2 -23
- package/dist/cjs/state/rootEventBus.js +9 -0
- package/dist/cjs/utils/CollabClient.js +78 -12
- package/dist/cjs/utils/TokenManager.js +16 -3
- package/dist/cjs/utils/changePreprocessor.js +199 -0
- package/dist/cjs/utils/jsonDiff.js +46 -4
- package/dist/cjs/utils/ordering.js +309 -0
- package/dist/cjs/utils/services.js +285 -128
- package/dist/cjs/utils/validation.js +0 -3
- package/dist/esm/config/environment.js +94 -10
- package/dist/esm/index.js +47862 -18248
- package/dist/esm/services/AdminService.js +1132 -0
- package/dist/esm/services/AuthService.js +1493 -386
- package/dist/esm/services/BaseService.js +757 -6
- package/dist/esm/services/BranchService.js +1265 -0
- package/dist/esm/services/CollabService.js +24956 -16089
- package/dist/esm/services/DnsService.js +1121 -0
- package/dist/esm/services/FeatureFlagService.js +956 -0
- package/dist/esm/services/FileService.js +982 -0
- package/dist/esm/services/IntegrationService.js +1319 -0
- package/dist/esm/services/MetricsService.js +843 -0
- package/dist/esm/services/PaymentService.js +1052 -0
- package/dist/esm/services/PlanService.js +1207 -0
- package/dist/esm/services/ProjectService.js +2526 -0
- package/dist/esm/services/PullRequestService.js +1284 -0
- package/dist/esm/services/ScreenshotService.js +1085 -0
- package/dist/esm/services/SubscriptionService.js +1177 -0
- package/dist/esm/services/TrackingService.js +18454 -0
- package/dist/esm/services/WaitlistService.js +929 -0
- package/dist/esm/services/index.js +47373 -18027
- package/dist/esm/state/RootStateManager.js +11 -23
- package/dist/esm/state/rootEventBus.js +9 -0
- package/dist/esm/utils/CollabClient.js +17526 -16120
- package/dist/esm/utils/TokenManager.js +16 -3
- package/dist/esm/utils/changePreprocessor.js +542 -0
- package/dist/esm/utils/jsonDiff.js +958 -43
- package/dist/esm/utils/ordering.js +291 -0
- package/dist/esm/utils/services.js +285 -128
- package/dist/esm/utils/validation.js +116 -50
- package/dist/node/config/environment.js +94 -10
- package/dist/node/index.js +183 -16
- package/dist/node/services/AdminService.js +332 -0
- package/dist/node/services/AuthService.js +742 -310
- package/dist/node/services/BaseService.js +148 -6
- package/dist/node/services/BranchService.js +465 -0
- package/dist/node/services/CollabService.js +439 -116
- package/dist/node/services/DnsService.js +321 -0
- package/dist/node/services/FeatureFlagService.js +156 -0
- package/dist/node/services/FileService.js +182 -0
- package/dist/node/services/IntegrationService.js +519 -0
- package/dist/node/services/MetricsService.js +43 -0
- package/dist/node/services/PaymentService.js +252 -0
- package/dist/node/services/PlanService.js +407 -0
- package/dist/node/services/ProjectService.js +1188 -0
- package/dist/node/services/PullRequestService.js +484 -0
- package/dist/node/services/ScreenshotService.js +285 -0
- package/dist/node/services/SubscriptionService.js +377 -0
- package/dist/node/services/TrackingService.js +632 -0
- package/dist/node/services/WaitlistService.js +129 -0
- package/dist/node/services/index.js +60 -4
- package/dist/node/state/RootStateManager.js +2 -23
- package/dist/node/state/rootEventBus.js +9 -0
- package/dist/node/utils/CollabClient.js +77 -11
- package/dist/node/utils/TokenManager.js +16 -3
- package/dist/node/utils/changePreprocessor.js +180 -0
- package/dist/node/utils/jsonDiff.js +46 -4
- package/dist/node/utils/ordering.js +290 -0
- package/dist/node/utils/services.js +285 -128
- package/dist/node/utils/validation.js +0 -3
- package/package.json +30 -18
- package/src/config/environment.js +95 -10
- package/src/index.js +190 -23
- package/src/services/AdminService.js +374 -0
- package/src/services/AuthService.js +874 -328
- package/src/services/BaseService.js +166 -6
- package/src/services/BranchService.js +536 -0
- package/src/services/CollabService.js +557 -148
- package/src/services/DnsService.js +366 -0
- package/src/services/FeatureFlagService.js +174 -0
- package/src/services/FileService.js +213 -0
- package/src/services/IntegrationService.js +548 -0
- package/src/services/MetricsService.js +40 -0
- package/src/services/PaymentService.js +287 -0
- package/src/services/PlanService.js +468 -0
- package/src/services/ProjectService.js +1366 -0
- package/src/services/PullRequestService.js +537 -0
- package/src/services/ScreenshotService.js +258 -0
- package/src/services/SubscriptionService.js +425 -0
- package/src/services/TrackingService.js +853 -0
- package/src/services/WaitlistService.js +130 -0
- package/src/services/index.js +79 -5
- package/src/services/tests/BranchService/createBranch.test.js +153 -0
- package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
- package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
- package/src/services/tests/BranchService/listBranches.test.js +87 -0
- package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
- package/src/services/tests/BranchService/publishVersion.test.js +183 -0
- package/src/services/tests/BranchService/renameBranch.test.js +240 -0
- package/src/services/tests/BranchService/resetBranch.test.js +152 -0
- package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
- package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
- package/src/services/tests/FileService/createFileFormData.test.js +74 -0
- package/src/services/tests/FileService/getFileUrl.test.js +69 -0
- package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
- package/src/services/tests/FileService/uploadDocument.test.js +36 -0
- package/src/services/tests/FileService/uploadFile.test.js +78 -0
- package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
- package/src/services/tests/FileService/uploadImage.test.js +36 -0
- package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
- package/src/services/tests/FileService/validateFile.test.js +63 -0
- package/src/services/tests/PlanService/createPlan.test.js +104 -0
- package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
- package/src/services/tests/PlanService/deletePlan.test.js +92 -0
- package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
- package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
- package/src/services/tests/PlanService/getPlan.test.js +50 -0
- package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
- package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
- package/src/services/tests/PlanService/getPlans.test.js +53 -0
- package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
- package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
- package/src/services/tests/PlanService/initializePlans.test.js +75 -0
- package/src/services/tests/PlanService/updatePlan.test.js +111 -0
- package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
- package/src/state/RootStateManager.js +37 -32
- package/src/state/rootEventBus.js +19 -0
- package/src/utils/CollabClient.js +99 -12
- package/src/utils/TokenManager.js +20 -3
- package/src/utils/changePreprocessor.js +239 -0
- package/src/utils/jsonDiff.js +40 -5
- package/src/utils/ordering.js +271 -0
- package/src/utils/services.js +306 -139
- package/src/utils/validation.js +0 -3
- package/dist/cjs/services/AIService.js +0 -155
- package/dist/cjs/services/BasedService.js +0 -1185
- package/dist/cjs/services/CoreService.js +0 -2295
- package/dist/cjs/services/SocketService.js +0 -309
- package/dist/cjs/services/SymstoryService.js +0 -571
- package/dist/cjs/utils/basedQuerys.js +0 -181
- package/dist/cjs/utils/symstoryClient.js +0 -259
- package/dist/esm/services/AIService.js +0 -185
- package/dist/esm/services/BasedService.js +0 -5262
- package/dist/esm/services/CoreService.js +0 -2827
- package/dist/esm/services/SocketService.js +0 -456
- package/dist/esm/services/SymstoryService.js +0 -7025
- package/dist/esm/utils/basedQuerys.js +0 -163
- package/dist/esm/utils/symstoryClient.js +0 -354
- package/dist/node/services/AIService.js +0 -136
- package/dist/node/services/BasedService.js +0 -1156
- package/dist/node/services/CoreService.js +0 -2266
- package/dist/node/services/SocketService.js +0 -280
- package/dist/node/services/SymstoryService.js +0 -542
- package/dist/node/utils/basedQuerys.js +0 -162
- package/dist/node/utils/symstoryClient.js +0 -230
- package/src/services/AIService.js +0 -150
- package/src/services/BasedService.js +0 -1302
- package/src/services/CoreService.js +0 -2548
- package/src/services/SocketService.js +0 -336
- package/src/services/SymstoryService.js +0 -649
- package/src/utils/basedQuerys.js +0 -164
- package/src/utils/symstoryClient.js +0 -252
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService.js";
|
|
2
|
+
class DnsService extends BaseService {
|
|
3
|
+
// ==================== DNS METHODS ====================
|
|
4
|
+
async createDnsRecord(domain, options = {}) {
|
|
5
|
+
this._requireReady("createDnsRecord");
|
|
6
|
+
if (!domain) {
|
|
7
|
+
throw new Error("Domain is required");
|
|
8
|
+
}
|
|
9
|
+
try {
|
|
10
|
+
const response = await this._request("/dns/records", {
|
|
11
|
+
method: "POST",
|
|
12
|
+
body: JSON.stringify({ domain, ...options }),
|
|
13
|
+
methodName: "createDnsRecord"
|
|
14
|
+
});
|
|
15
|
+
if (response.success) {
|
|
16
|
+
return response.data;
|
|
17
|
+
}
|
|
18
|
+
throw new Error(response.message);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
throw new Error(`Failed to create DNS record: ${error.message}`, { cause: error });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async getDnsRecord(domain) {
|
|
24
|
+
this._requireReady("getDnsRecord");
|
|
25
|
+
if (!domain) {
|
|
26
|
+
throw new Error("Domain is required");
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const response = await this._request(`/dns/records/${domain}`, {
|
|
30
|
+
method: "GET",
|
|
31
|
+
methodName: "getDnsRecord"
|
|
32
|
+
});
|
|
33
|
+
if (response.success) {
|
|
34
|
+
return response.data;
|
|
35
|
+
}
|
|
36
|
+
throw new Error(response.message);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new Error(`Failed to get DNS record: ${error.message}`, { cause: error });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async getCustomHost(hostname) {
|
|
42
|
+
this._requireReady("getCustomHost");
|
|
43
|
+
if (!hostname) {
|
|
44
|
+
throw new Error("Hostname is required");
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
const response = await this._request(`/dns/custom-hosts/${encodeURIComponent(hostname)}`, {
|
|
48
|
+
method: "GET",
|
|
49
|
+
methodName: "getCustomHost"
|
|
50
|
+
});
|
|
51
|
+
if (response.success) {
|
|
52
|
+
return response.data;
|
|
53
|
+
}
|
|
54
|
+
throw new Error(response.message);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
throw new Error(`Failed to get custom host: ${error.message}`, { cause: error });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async removeDnsRecord(domain) {
|
|
60
|
+
this._requireReady("removeDnsRecord");
|
|
61
|
+
if (!domain) {
|
|
62
|
+
throw new Error("Domain is required");
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const response = await this._request(`/dns/records/${domain}`, {
|
|
66
|
+
method: "DELETE",
|
|
67
|
+
methodName: "removeDnsRecord"
|
|
68
|
+
});
|
|
69
|
+
if (response.success) {
|
|
70
|
+
return response.data;
|
|
71
|
+
}
|
|
72
|
+
throw new Error(response.message);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
throw new Error(`Failed to remove DNS record: ${error.message}`, { cause: error });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// customDomains could be a string or an array of strings
|
|
78
|
+
async addProjectCustomDomains(projectId, customDomains, options = {}) {
|
|
79
|
+
this._requireReady("addProjectCustomDomains");
|
|
80
|
+
if (!projectId) {
|
|
81
|
+
throw new Error("Project ID is required");
|
|
82
|
+
}
|
|
83
|
+
if (!customDomains || Array.isArray(customDomains) && !customDomains.length) {
|
|
84
|
+
throw new Error(
|
|
85
|
+
"customDomains is required and must be a non-empty string or array"
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const { envKey, headers } = options;
|
|
89
|
+
try {
|
|
90
|
+
const response = await this._request(`/projects/${projectId}/domains`, {
|
|
91
|
+
method: "PATCH",
|
|
92
|
+
body: JSON.stringify({
|
|
93
|
+
customDomains,
|
|
94
|
+
...envKey ? { envKey } : {}
|
|
95
|
+
}),
|
|
96
|
+
...headers ? { headers } : {},
|
|
97
|
+
methodName: "addProjectCustomDomains"
|
|
98
|
+
});
|
|
99
|
+
if (response.success) {
|
|
100
|
+
return response.data;
|
|
101
|
+
}
|
|
102
|
+
throw new Error(response.message);
|
|
103
|
+
} catch (error) {
|
|
104
|
+
throw new Error(
|
|
105
|
+
`Failed to update project custom domains: ${error.message}`,
|
|
106
|
+
{ cause: error }
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// ==================== DNS HELPER METHODS ====================
|
|
111
|
+
/**
|
|
112
|
+
* Helper method to validate domain format
|
|
113
|
+
*/
|
|
114
|
+
validateDomain(domain) {
|
|
115
|
+
if (!domain || typeof domain !== "string") {
|
|
116
|
+
return {
|
|
117
|
+
isValid: false,
|
|
118
|
+
error: "Domain must be a non-empty string"
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const domainRegex = /^[a-zA-Z0-9](?:(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)?(?:\.[a-zA-Z0-9](?:(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)?)*$/u;
|
|
122
|
+
if (!domainRegex.test(domain)) {
|
|
123
|
+
return {
|
|
124
|
+
isValid: false,
|
|
125
|
+
error: "Invalid domain format"
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const tldRegex = /\.[a-zA-Z]{2,}$/u;
|
|
129
|
+
if (!tldRegex.test(domain)) {
|
|
130
|
+
return {
|
|
131
|
+
isValid: false,
|
|
132
|
+
error: "Domain must have a valid top-level domain"
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
isValid: true,
|
|
137
|
+
error: null
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Helper method to create DNS record with validation
|
|
142
|
+
*/
|
|
143
|
+
async createDnsRecordWithValidation(domain, options = {}) {
|
|
144
|
+
const validation = this.validateDomain(domain);
|
|
145
|
+
if (!validation.isValid) {
|
|
146
|
+
throw new Error(validation.error);
|
|
147
|
+
}
|
|
148
|
+
return await this.createDnsRecord(domain, options);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Helper method to get DNS record with validation
|
|
152
|
+
*/
|
|
153
|
+
async getDnsRecordWithValidation(domain) {
|
|
154
|
+
const validation = this.validateDomain(domain);
|
|
155
|
+
if (!validation.isValid) {
|
|
156
|
+
throw new Error(validation.error);
|
|
157
|
+
}
|
|
158
|
+
return await this.getDnsRecord(domain);
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Helper method to remove DNS record with validation
|
|
162
|
+
*/
|
|
163
|
+
async removeDnsRecordWithValidation(domain) {
|
|
164
|
+
const validation = this.validateDomain(domain);
|
|
165
|
+
if (!validation.isValid) {
|
|
166
|
+
throw new Error(validation.error);
|
|
167
|
+
}
|
|
168
|
+
return await this.removeDnsRecord(domain);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Helper method to add project custom domains with validation
|
|
172
|
+
*/
|
|
173
|
+
async addProjectCustomDomainsWithValidation(projectId, customDomains, options = {}) {
|
|
174
|
+
if (!projectId || typeof projectId !== "string") {
|
|
175
|
+
throw new Error("Project ID must be a valid string");
|
|
176
|
+
}
|
|
177
|
+
if (!customDomains) {
|
|
178
|
+
throw new Error("Custom domains are required");
|
|
179
|
+
}
|
|
180
|
+
const domainsArray = Array.isArray(customDomains) ? customDomains : [customDomains];
|
|
181
|
+
if (domainsArray.length === 0) {
|
|
182
|
+
throw new Error("At least one custom domain is required");
|
|
183
|
+
}
|
|
184
|
+
for (const domain of domainsArray) {
|
|
185
|
+
const validation = this.validateDomain(domain);
|
|
186
|
+
if (!validation.isValid) {
|
|
187
|
+
throw new Error(`Invalid domain '${domain}': ${validation.error}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return await this.addProjectCustomDomains(projectId, customDomains, options);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Helper method to check if domain is available
|
|
194
|
+
*/
|
|
195
|
+
async isDomainAvailable(domain) {
|
|
196
|
+
try {
|
|
197
|
+
await this.getDnsRecord(domain);
|
|
198
|
+
return false;
|
|
199
|
+
} catch (error) {
|
|
200
|
+
if (error.message.includes("not found") || error.message.includes("404")) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Helper method to get domain status
|
|
208
|
+
*/
|
|
209
|
+
async getDomainStatus(domain) {
|
|
210
|
+
try {
|
|
211
|
+
const record = await this.getDnsRecord(domain);
|
|
212
|
+
return {
|
|
213
|
+
exists: true,
|
|
214
|
+
active: record.active || false,
|
|
215
|
+
verified: record.verified || false,
|
|
216
|
+
record
|
|
217
|
+
};
|
|
218
|
+
} catch (error) {
|
|
219
|
+
if (error.message.includes("not found") || error.message.includes("404")) {
|
|
220
|
+
return {
|
|
221
|
+
exists: false,
|
|
222
|
+
active: false,
|
|
223
|
+
verified: false,
|
|
224
|
+
error: "Domain not found"
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Helper method to verify domain ownership
|
|
232
|
+
*/
|
|
233
|
+
async verifyDomainOwnership(domain) {
|
|
234
|
+
try {
|
|
235
|
+
const record = await this.getDnsRecord(domain);
|
|
236
|
+
if (!record.verified) {
|
|
237
|
+
return {
|
|
238
|
+
verified: false,
|
|
239
|
+
needsVerification: true,
|
|
240
|
+
verificationMethod: record.verificationMethod || "dns",
|
|
241
|
+
verificationRecord: record.verificationRecord
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
return {
|
|
245
|
+
verified: true,
|
|
246
|
+
needsVerification: false
|
|
247
|
+
};
|
|
248
|
+
} catch (error) {
|
|
249
|
+
throw new Error(`Failed to verify domain ownership: ${error.message}`, { cause: error });
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Helper method to get project domains
|
|
254
|
+
*/
|
|
255
|
+
async getProjectDomains(projectId) {
|
|
256
|
+
this._requireReady("getProjectDomains");
|
|
257
|
+
if (!projectId) {
|
|
258
|
+
throw new Error("Project ID is required");
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
const response = await this._request(`/projects/${projectId}/domains`, {
|
|
262
|
+
method: "GET",
|
|
263
|
+
methodName: "getProjectDomains"
|
|
264
|
+
});
|
|
265
|
+
if (response.success) {
|
|
266
|
+
return response.data;
|
|
267
|
+
}
|
|
268
|
+
throw new Error(response.message);
|
|
269
|
+
} catch (error) {
|
|
270
|
+
throw new Error(`Failed to get project domains: ${error.message}`, { cause: error });
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Helper method to remove project custom domain
|
|
275
|
+
*/
|
|
276
|
+
async removeProjectCustomDomain(projectId, domain) {
|
|
277
|
+
this._requireReady("removeProjectCustomDomain");
|
|
278
|
+
if (!projectId) {
|
|
279
|
+
throw new Error("Project ID is required");
|
|
280
|
+
}
|
|
281
|
+
if (!domain) {
|
|
282
|
+
throw new Error("Domain is required");
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
const response = await this._request(`/projects/${projectId}/domains/${encodeURIComponent(domain)}`, {
|
|
286
|
+
method: "DELETE",
|
|
287
|
+
methodName: "removeProjectCustomDomain"
|
|
288
|
+
});
|
|
289
|
+
if (response.success) {
|
|
290
|
+
return response.data;
|
|
291
|
+
}
|
|
292
|
+
throw new Error(response.message);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
throw new Error(`Failed to remove project custom domain: ${error.message}`, { cause: error });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Helper method to format domain for display
|
|
299
|
+
*/
|
|
300
|
+
formatDomain(domain) {
|
|
301
|
+
if (!domain) {
|
|
302
|
+
return "";
|
|
303
|
+
}
|
|
304
|
+
const cleanDomain = domain.replace(/^https?:\/\//u, "");
|
|
305
|
+
return cleanDomain.replace(/\/$/u, "");
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Helper method to extract domain from URL
|
|
309
|
+
*/
|
|
310
|
+
extractDomainFromUrl(url) {
|
|
311
|
+
try {
|
|
312
|
+
const urlObj = new URL(url);
|
|
313
|
+
return urlObj.hostname;
|
|
314
|
+
} catch {
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
export {
|
|
320
|
+
DnsService
|
|
321
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService.js";
|
|
2
|
+
function normalizeKeysParam(keys) {
|
|
3
|
+
if (!keys) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
if (Array.isArray(keys)) {
|
|
7
|
+
const flattened = keys.flatMap((k) => String(k).split(","));
|
|
8
|
+
const cleaned2 = flattened.map((s) => s.trim()).filter(Boolean);
|
|
9
|
+
return cleaned2.length ? cleaned2.join(",") : null;
|
|
10
|
+
}
|
|
11
|
+
const cleaned = String(keys).split(",").map((s) => s.trim()).filter(Boolean);
|
|
12
|
+
return cleaned.length ? cleaned.join(",") : null;
|
|
13
|
+
}
|
|
14
|
+
class FeatureFlagService extends BaseService {
|
|
15
|
+
// ==================== USER FEATURE FLAGS (optional auth) ====================
|
|
16
|
+
/**
|
|
17
|
+
* Evaluate feature flags for the current user (or anonymous).
|
|
18
|
+
* @param {Object} [params]
|
|
19
|
+
* @param {string[]|string} [params.keys] Optional subset of keys (array or comma-separated string)
|
|
20
|
+
* @returns {Promise<{flags: Record<string, {enabled: boolean, variant: string|null, payload: any}>}>}
|
|
21
|
+
*/
|
|
22
|
+
async getFeatureFlags(params = {}) {
|
|
23
|
+
this._requireReady("getFeatureFlags");
|
|
24
|
+
const { keys } = params || {};
|
|
25
|
+
const queryParams = new URLSearchParams();
|
|
26
|
+
const keysParam = normalizeKeysParam(keys);
|
|
27
|
+
if (keysParam) {
|
|
28
|
+
queryParams.append("keys", keysParam);
|
|
29
|
+
}
|
|
30
|
+
const queryString = queryParams.toString();
|
|
31
|
+
const url = `/feature-flags${queryString ? `?${queryString}` : ""}`;
|
|
32
|
+
try {
|
|
33
|
+
const response = await this._request(url, {
|
|
34
|
+
method: "GET",
|
|
35
|
+
methodName: "getFeatureFlags"
|
|
36
|
+
});
|
|
37
|
+
if (response.success) {
|
|
38
|
+
return response.data;
|
|
39
|
+
}
|
|
40
|
+
throw new Error(response.message);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
throw new Error(`Failed to get feature flags: ${error.message}`, { cause: error });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Evaluate a single feature flag for the current user (or anonymous).
|
|
47
|
+
*/
|
|
48
|
+
async getFeatureFlag(key) {
|
|
49
|
+
this._requireReady("getFeatureFlag");
|
|
50
|
+
if (!key) {
|
|
51
|
+
throw new Error("Feature flag key is required");
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const response = await this._request(`/feature-flags/${encodeURIComponent(String(key))}`, {
|
|
55
|
+
method: "GET",
|
|
56
|
+
methodName: "getFeatureFlag"
|
|
57
|
+
});
|
|
58
|
+
if (response.success) {
|
|
59
|
+
return response.data;
|
|
60
|
+
}
|
|
61
|
+
throw new Error(response.message);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
throw new Error(`Failed to get feature flag: ${error.message}`, { cause: error });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// ==================== ADMIN FEATURE FLAGS (admin only) ====================
|
|
67
|
+
async getAdminFeatureFlags(params = {}) {
|
|
68
|
+
this._requireReady("getAdminFeatureFlags");
|
|
69
|
+
const { includeArchived = true } = params || {};
|
|
70
|
+
const queryParams = new URLSearchParams();
|
|
71
|
+
if (includeArchived === false) {
|
|
72
|
+
queryParams.append("includeArchived", "false");
|
|
73
|
+
}
|
|
74
|
+
const queryString = queryParams.toString();
|
|
75
|
+
const url = `/admin/feature-flags${queryString ? `?${queryString}` : ""}`;
|
|
76
|
+
try {
|
|
77
|
+
const response = await this._request(url, {
|
|
78
|
+
method: "GET",
|
|
79
|
+
methodName: "getAdminFeatureFlags"
|
|
80
|
+
});
|
|
81
|
+
if (response.success) {
|
|
82
|
+
return response.data;
|
|
83
|
+
}
|
|
84
|
+
throw new Error(response.message);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw new Error(`Failed to get admin feature flags: ${error.message}`, {
|
|
87
|
+
cause: error
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async createFeatureFlag(flagData) {
|
|
92
|
+
this._requireReady("createFeatureFlag");
|
|
93
|
+
if (!flagData || typeof flagData !== "object") {
|
|
94
|
+
throw new Error("Feature flag data is required");
|
|
95
|
+
}
|
|
96
|
+
if (!flagData.key) {
|
|
97
|
+
throw new Error("Feature flag key is required");
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const response = await this._request("/admin/feature-flags", {
|
|
101
|
+
method: "POST",
|
|
102
|
+
body: JSON.stringify(flagData),
|
|
103
|
+
methodName: "createFeatureFlag"
|
|
104
|
+
});
|
|
105
|
+
if (response.success) {
|
|
106
|
+
return response.data;
|
|
107
|
+
}
|
|
108
|
+
throw new Error(response.message);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
throw new Error(`Failed to create feature flag: ${error.message}`, { cause: error });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async updateFeatureFlag(id, patch) {
|
|
114
|
+
this._requireReady("updateFeatureFlag");
|
|
115
|
+
if (!id) {
|
|
116
|
+
throw new Error("Feature flag id is required");
|
|
117
|
+
}
|
|
118
|
+
if (!patch || typeof patch !== "object") {
|
|
119
|
+
throw new Error("Feature flag patch is required");
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const response = await this._request(`/admin/feature-flags/${encodeURIComponent(String(id))}`, {
|
|
123
|
+
method: "PATCH",
|
|
124
|
+
body: JSON.stringify(patch),
|
|
125
|
+
methodName: "updateFeatureFlag"
|
|
126
|
+
});
|
|
127
|
+
if (response.success) {
|
|
128
|
+
return response.data;
|
|
129
|
+
}
|
|
130
|
+
throw new Error(response.message);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
throw new Error(`Failed to update feature flag: ${error.message}`, { cause: error });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async archiveFeatureFlag(id) {
|
|
136
|
+
this._requireReady("archiveFeatureFlag");
|
|
137
|
+
if (!id) {
|
|
138
|
+
throw new Error("Feature flag id is required");
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const response = await this._request(`/admin/feature-flags/${encodeURIComponent(String(id))}`, {
|
|
142
|
+
method: "DELETE",
|
|
143
|
+
methodName: "archiveFeatureFlag"
|
|
144
|
+
});
|
|
145
|
+
if (response.success) {
|
|
146
|
+
return response.data;
|
|
147
|
+
}
|
|
148
|
+
throw new Error(response.message);
|
|
149
|
+
} catch (error) {
|
|
150
|
+
throw new Error(`Failed to archive feature flag: ${error.message}`, { cause: error });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
export {
|
|
155
|
+
FeatureFlagService
|
|
156
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService.js";
|
|
2
|
+
class FileService extends BaseService {
|
|
3
|
+
// ==================== FILE METHODS ====================
|
|
4
|
+
async uploadFile(file, options = {}) {
|
|
5
|
+
var _a;
|
|
6
|
+
this._requireReady("uploadFile");
|
|
7
|
+
if (!file) {
|
|
8
|
+
throw new Error("File is required for upload");
|
|
9
|
+
}
|
|
10
|
+
const formData = new FormData();
|
|
11
|
+
formData.append("file", file);
|
|
12
|
+
const hasProjectIdOption = Object.hasOwn(options, "projectId");
|
|
13
|
+
const projectId = hasProjectIdOption ? options.projectId : (_a = this._context.project) == null ? void 0 : _a.id;
|
|
14
|
+
if (projectId != null && projectId !== "") {
|
|
15
|
+
formData.append("projectId", projectId);
|
|
16
|
+
}
|
|
17
|
+
if (options.tags) {
|
|
18
|
+
formData.append("tags", JSON.stringify(options.tags));
|
|
19
|
+
}
|
|
20
|
+
if (options.visibility) {
|
|
21
|
+
formData.append("visibility", options.visibility || "public");
|
|
22
|
+
}
|
|
23
|
+
if (options.metadata) {
|
|
24
|
+
formData.append("metadata", JSON.stringify(options.metadata));
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const response = await this._request("/files/upload", {
|
|
28
|
+
method: "POST",
|
|
29
|
+
body: formData,
|
|
30
|
+
headers: {},
|
|
31
|
+
// Let browser set Content-Type for FormData
|
|
32
|
+
methodName: "uploadFile"
|
|
33
|
+
});
|
|
34
|
+
if (!response.success) {
|
|
35
|
+
throw new Error(response.message);
|
|
36
|
+
}
|
|
37
|
+
return response.data;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
throw new Error(`File upload failed: ${error.message}`, { cause: error });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async updateProjectIcon(projectId, iconFile) {
|
|
43
|
+
this._requireReady("updateProjectIcon");
|
|
44
|
+
if (!projectId || !iconFile) {
|
|
45
|
+
throw new Error("Project ID and icon file are required");
|
|
46
|
+
}
|
|
47
|
+
const formData = new FormData();
|
|
48
|
+
formData.append("icon", iconFile);
|
|
49
|
+
formData.append("projectId", projectId);
|
|
50
|
+
try {
|
|
51
|
+
const response = await this._request("/files/upload-project-icon", {
|
|
52
|
+
method: "POST",
|
|
53
|
+
body: formData,
|
|
54
|
+
headers: {},
|
|
55
|
+
// Let browser set Content-Type for FormData
|
|
56
|
+
methodName: "updateProjectIcon"
|
|
57
|
+
});
|
|
58
|
+
if (response.success) {
|
|
59
|
+
return response.data;
|
|
60
|
+
}
|
|
61
|
+
throw new Error(response.message);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
throw new Error(`Failed to update project icon: ${error.message}`, { cause: error });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// ==================== FILE HELPER METHODS ====================
|
|
67
|
+
/**
|
|
68
|
+
* Helper method to upload file with validation
|
|
69
|
+
*/
|
|
70
|
+
async uploadFileWithValidation(file, options = {}) {
|
|
71
|
+
if (!file) {
|
|
72
|
+
throw new Error("File is required");
|
|
73
|
+
}
|
|
74
|
+
const maxSize = options.maxSize || 10 * 1024 * 1024;
|
|
75
|
+
if (file.size > maxSize) {
|
|
76
|
+
throw new Error(`File size exceeds maximum allowed size of ${maxSize / (1024 * 1024)}MB`);
|
|
77
|
+
}
|
|
78
|
+
const allowedTypes = options.allowedTypes || ["image/*", "application/pdf", "text/*"];
|
|
79
|
+
if (allowedTypes.length > 0) {
|
|
80
|
+
const isValidType = allowedTypes.some((type) => {
|
|
81
|
+
if (type.endsWith("/*")) {
|
|
82
|
+
return file.type.startsWith(type.replace("/*", ""));
|
|
83
|
+
}
|
|
84
|
+
return file.type === type;
|
|
85
|
+
});
|
|
86
|
+
if (!isValidType) {
|
|
87
|
+
throw new Error(`File type '${file.type}' is not allowed. Allowed types: ${allowedTypes.join(", ")}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return await this.uploadFile(file, options);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Helper method to upload image file specifically
|
|
94
|
+
*/
|
|
95
|
+
async uploadImage(imageFile, options = {}) {
|
|
96
|
+
const imageOptions = {
|
|
97
|
+
...options,
|
|
98
|
+
allowedTypes: ["image/jpeg", "image/png", "image/gif", "image/webp"],
|
|
99
|
+
maxSize: options.maxSize || 5 * 1024 * 1024
|
|
100
|
+
// 5MB for images
|
|
101
|
+
};
|
|
102
|
+
return await this.uploadFileWithValidation(imageFile, imageOptions);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Helper method to upload document file
|
|
106
|
+
*/
|
|
107
|
+
async uploadDocument(documentFile, options = {}) {
|
|
108
|
+
const documentOptions = {
|
|
109
|
+
...options,
|
|
110
|
+
allowedTypes: ["application/pdf", "text/plain", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
|
|
111
|
+
maxSize: options.maxSize || 20 * 1024 * 1024
|
|
112
|
+
// 20MB for documents
|
|
113
|
+
};
|
|
114
|
+
return await this.uploadFileWithValidation(documentFile, documentOptions);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Helper method to get file URL by ID
|
|
118
|
+
*/
|
|
119
|
+
getFileUrl(fileId) {
|
|
120
|
+
if (!fileId) {
|
|
121
|
+
throw new Error("File ID is required");
|
|
122
|
+
}
|
|
123
|
+
return `${this._apiUrl}/core/files/public/${fileId}/download`;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Helper method to validate file before upload
|
|
127
|
+
*/
|
|
128
|
+
validateFile(file, options = {}) {
|
|
129
|
+
const errors = [];
|
|
130
|
+
if (!file) {
|
|
131
|
+
errors.push("File is required");
|
|
132
|
+
return errors;
|
|
133
|
+
}
|
|
134
|
+
const maxSize = options.maxSize || 10 * 1024 * 1024;
|
|
135
|
+
if (file.size > maxSize) {
|
|
136
|
+
errors.push(`File size (${(file.size / (1024 * 1024)).toFixed(2)}MB) exceeds maximum allowed size of ${maxSize / (1024 * 1024)}MB`);
|
|
137
|
+
}
|
|
138
|
+
const allowedTypes = options.allowedTypes || [];
|
|
139
|
+
if (allowedTypes.length > 0) {
|
|
140
|
+
const isValidType = allowedTypes.some((type) => {
|
|
141
|
+
if (type.endsWith("/*")) {
|
|
142
|
+
return file.type.startsWith(type.replace("/*", ""));
|
|
143
|
+
}
|
|
144
|
+
return file.type === type;
|
|
145
|
+
});
|
|
146
|
+
if (!isValidType) {
|
|
147
|
+
errors.push(`File type '${file.type}' is not allowed. Allowed types: ${allowedTypes.join(", ")}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return errors;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Helper method to create FormData with file and metadata
|
|
154
|
+
*/
|
|
155
|
+
createFileFormData(file, metadata = {}) {
|
|
156
|
+
const formData = new FormData();
|
|
157
|
+
formData.append("file", file);
|
|
158
|
+
if (Object.keys(metadata).length > 0) {
|
|
159
|
+
formData.append("metadata", JSON.stringify(metadata));
|
|
160
|
+
}
|
|
161
|
+
return formData;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Helper method to upload multiple files
|
|
165
|
+
*/
|
|
166
|
+
async uploadMultipleFiles(files, options = {}) {
|
|
167
|
+
if (!Array.isArray(files) || files.length === 0) {
|
|
168
|
+
throw new Error("Files array is required and must not be empty");
|
|
169
|
+
}
|
|
170
|
+
const uploadPromises = files.map((file) => this.uploadFile(file, options));
|
|
171
|
+
const results = await Promise.allSettled(uploadPromises);
|
|
172
|
+
return results.map((result, index) => ({
|
|
173
|
+
file: files[index],
|
|
174
|
+
success: result.status === "fulfilled",
|
|
175
|
+
data: result.status === "fulfilled" ? result.value : null,
|
|
176
|
+
error: result.status === "rejected" ? result.reason.message : null
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
export {
|
|
181
|
+
FileService
|
|
182
|
+
};
|