@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
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var PaymentService_exports = {};
|
|
19
|
+
__export(PaymentService_exports, {
|
|
20
|
+
PaymentService: () => PaymentService
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(PaymentService_exports);
|
|
23
|
+
var import_BaseService = require("./BaseService.js");
|
|
24
|
+
class PaymentService extends import_BaseService.BaseService {
|
|
25
|
+
// ==================== PAYMENT METHODS ====================
|
|
26
|
+
async checkout(options = {}) {
|
|
27
|
+
this._requireReady("checkout");
|
|
28
|
+
const {
|
|
29
|
+
projectId,
|
|
30
|
+
seats = 1,
|
|
31
|
+
price = "starter_monthly",
|
|
32
|
+
successUrl = `${window.location.origin}/success`,
|
|
33
|
+
cancelUrl = `${window.location.origin}/pricing`
|
|
34
|
+
} = options;
|
|
35
|
+
if (!projectId) {
|
|
36
|
+
throw new Error("Project ID is required for checkout");
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const response = await this._request("/payments/checkout", {
|
|
40
|
+
method: "POST",
|
|
41
|
+
body: JSON.stringify({
|
|
42
|
+
projectId,
|
|
43
|
+
seats,
|
|
44
|
+
price,
|
|
45
|
+
successUrl,
|
|
46
|
+
cancelUrl
|
|
47
|
+
}),
|
|
48
|
+
methodName: "checkout"
|
|
49
|
+
});
|
|
50
|
+
if (response.success) {
|
|
51
|
+
return response.data;
|
|
52
|
+
}
|
|
53
|
+
throw new Error(response.message);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
throw new Error(`Failed to checkout: ${error.message}`, { cause: error });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async getSubscriptionStatus(projectId) {
|
|
59
|
+
this._requireReady("getSubscriptionStatus");
|
|
60
|
+
if (!projectId) {
|
|
61
|
+
throw new Error("Project ID is required");
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const response = await this._request(
|
|
65
|
+
`/payments/subscription/${projectId}`,
|
|
66
|
+
{
|
|
67
|
+
method: "GET",
|
|
68
|
+
methodName: "getSubscriptionStatus"
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
if (response.success) {
|
|
72
|
+
return response.data;
|
|
73
|
+
}
|
|
74
|
+
throw new Error(response.message);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
throw new Error(`Failed to get subscription status: ${error.message}`, { cause: error });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// ==================== PAYMENT HELPER METHODS ====================
|
|
80
|
+
/**
|
|
81
|
+
* Helper method to create checkout with validation
|
|
82
|
+
*/
|
|
83
|
+
async checkoutWithValidation(options = {}) {
|
|
84
|
+
const {
|
|
85
|
+
projectId,
|
|
86
|
+
seats,
|
|
87
|
+
price,
|
|
88
|
+
successUrl,
|
|
89
|
+
cancelUrl
|
|
90
|
+
} = options;
|
|
91
|
+
if (!projectId) {
|
|
92
|
+
throw new Error("Project ID is required");
|
|
93
|
+
}
|
|
94
|
+
if (seats && (typeof seats !== "number" || seats < 1)) {
|
|
95
|
+
throw new Error("Seats must be a positive number");
|
|
96
|
+
}
|
|
97
|
+
if (price && typeof price !== "string") {
|
|
98
|
+
throw new Error("Price must be a string");
|
|
99
|
+
}
|
|
100
|
+
if (successUrl && !this._isValidUrl(successUrl)) {
|
|
101
|
+
throw new Error("Success URL must be a valid URL");
|
|
102
|
+
}
|
|
103
|
+
if (cancelUrl && !this._isValidUrl(cancelUrl)) {
|
|
104
|
+
throw new Error("Cancel URL must be a valid URL");
|
|
105
|
+
}
|
|
106
|
+
return await this.checkout(options);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Helper method to get subscription status with validation
|
|
110
|
+
*/
|
|
111
|
+
async getSubscriptionStatusWithValidation(projectId) {
|
|
112
|
+
if (!projectId || typeof projectId !== "string") {
|
|
113
|
+
throw new Error("Project ID must be a valid string");
|
|
114
|
+
}
|
|
115
|
+
return await this.getSubscriptionStatus(projectId);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Helper method to check if project has active subscription
|
|
119
|
+
*/
|
|
120
|
+
async hasActiveSubscription(projectId) {
|
|
121
|
+
try {
|
|
122
|
+
const status = await this.getSubscriptionStatus(projectId);
|
|
123
|
+
return (status == null ? void 0 : status.active) === true;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.warn("Failed to check subscription status:", error.message);
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Helper method to get subscription details
|
|
131
|
+
*/
|
|
132
|
+
async getSubscriptionDetails(projectId) {
|
|
133
|
+
try {
|
|
134
|
+
const status = await this.getSubscriptionStatus(projectId);
|
|
135
|
+
if (!status) {
|
|
136
|
+
return {
|
|
137
|
+
hasSubscription: false,
|
|
138
|
+
active: false,
|
|
139
|
+
message: "No subscription found"
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
hasSubscription: true,
|
|
144
|
+
active: status.active || false,
|
|
145
|
+
plan: status.plan,
|
|
146
|
+
seats: status.seats,
|
|
147
|
+
nextBillingDate: status.nextBillingDate,
|
|
148
|
+
amount: status.amount,
|
|
149
|
+
currency: status.currency,
|
|
150
|
+
status: status.status
|
|
151
|
+
};
|
|
152
|
+
} catch (error) {
|
|
153
|
+
throw new Error(`Failed to get subscription details: ${error.message}`, { cause: error });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Helper method to create checkout for specific plan
|
|
158
|
+
*/
|
|
159
|
+
async checkoutForPlan(projectId, planKey, options = {}) {
|
|
160
|
+
if (!projectId) {
|
|
161
|
+
throw new Error("Project ID is required");
|
|
162
|
+
}
|
|
163
|
+
if (!planKey) {
|
|
164
|
+
throw new Error("Plan key is required");
|
|
165
|
+
}
|
|
166
|
+
const checkoutOptions = {
|
|
167
|
+
projectId,
|
|
168
|
+
price: planKey,
|
|
169
|
+
...options
|
|
170
|
+
};
|
|
171
|
+
return await this.checkoutWithValidation(checkoutOptions);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Helper method to create checkout for team plan
|
|
175
|
+
*/
|
|
176
|
+
async checkoutForTeam(projectId, seats, options = {}) {
|
|
177
|
+
if (!projectId) {
|
|
178
|
+
throw new Error("Project ID is required");
|
|
179
|
+
}
|
|
180
|
+
if (!seats || seats < 1) {
|
|
181
|
+
throw new Error("Seats must be a positive number");
|
|
182
|
+
}
|
|
183
|
+
const checkoutOptions = {
|
|
184
|
+
projectId,
|
|
185
|
+
seats,
|
|
186
|
+
price: "team_monthly",
|
|
187
|
+
...options
|
|
188
|
+
};
|
|
189
|
+
return await this.checkoutWithValidation(checkoutOptions);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Helper method to validate subscription status
|
|
193
|
+
*/
|
|
194
|
+
validateSubscriptionStatus(status) {
|
|
195
|
+
if (!status || typeof status !== "object") {
|
|
196
|
+
return {
|
|
197
|
+
isValid: false,
|
|
198
|
+
error: "Invalid subscription status format"
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
const requiredFields = ["active", "plan", "seats"];
|
|
202
|
+
const missingFields = requiredFields.filter((field) => !(field in status));
|
|
203
|
+
if (missingFields.length > 0) {
|
|
204
|
+
return {
|
|
205
|
+
isValid: false,
|
|
206
|
+
error: `Missing required fields: ${missingFields.join(", ")}`
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
isValid: true,
|
|
211
|
+
error: null
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Helper method to format subscription amount
|
|
216
|
+
*/
|
|
217
|
+
formatSubscriptionAmount(amount, currency = "USD") {
|
|
218
|
+
if (!amount || typeof amount !== "number") {
|
|
219
|
+
return "N/A";
|
|
220
|
+
}
|
|
221
|
+
return new Intl.NumberFormat("en-US", {
|
|
222
|
+
style: "currency",
|
|
223
|
+
currency
|
|
224
|
+
}).format(amount / 100);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Helper method to get subscription summary
|
|
228
|
+
*/
|
|
229
|
+
async getSubscriptionSummary(projectId) {
|
|
230
|
+
try {
|
|
231
|
+
const details = await this.getSubscriptionDetails(projectId);
|
|
232
|
+
if (!details.hasSubscription) {
|
|
233
|
+
return {
|
|
234
|
+
status: "no_subscription",
|
|
235
|
+
message: "No active subscription",
|
|
236
|
+
action: "subscribe"
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
if (!details.active) {
|
|
240
|
+
return {
|
|
241
|
+
status: "inactive",
|
|
242
|
+
message: "Subscription is inactive",
|
|
243
|
+
action: "reactivate"
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
status: "active",
|
|
248
|
+
message: `Active ${details.plan} plan with ${details.seats} seats`,
|
|
249
|
+
action: "manage",
|
|
250
|
+
details
|
|
251
|
+
};
|
|
252
|
+
} catch (error) {
|
|
253
|
+
return {
|
|
254
|
+
status: "error",
|
|
255
|
+
message: `Failed to get subscription: ${error.message}`,
|
|
256
|
+
action: "retry"
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Private helper to validate URL
|
|
262
|
+
*/
|
|
263
|
+
_isValidUrl(string) {
|
|
264
|
+
try {
|
|
265
|
+
const url = new URL(string);
|
|
266
|
+
return Boolean(url);
|
|
267
|
+
} catch {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var PlanService_exports = {};
|
|
19
|
+
__export(PlanService_exports, {
|
|
20
|
+
PlanService: () => PlanService
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(PlanService_exports);
|
|
23
|
+
var import_BaseService = require("./BaseService.js");
|
|
24
|
+
class PlanService extends import_BaseService.BaseService {
|
|
25
|
+
// ==================== PLAN METHODS ====================
|
|
26
|
+
/**
|
|
27
|
+
* Get list of public plans (no authentication required)
|
|
28
|
+
*/
|
|
29
|
+
async getPlans() {
|
|
30
|
+
try {
|
|
31
|
+
const response = await this._request("/plans", {
|
|
32
|
+
method: "GET",
|
|
33
|
+
methodName: "getPlans"
|
|
34
|
+
});
|
|
35
|
+
if (response.success) {
|
|
36
|
+
return response.data;
|
|
37
|
+
}
|
|
38
|
+
throw new Error(response.message);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
throw new Error(`Failed to get plans: ${error.message}`, { cause: error });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get list of public plans with enhanced pricing information (no authentication required)
|
|
45
|
+
*/
|
|
46
|
+
async getPlansWithPricing() {
|
|
47
|
+
try {
|
|
48
|
+
const response = await this._request("/plans/pricing", {
|
|
49
|
+
method: "GET",
|
|
50
|
+
methodName: "getPlansWithPricing"
|
|
51
|
+
});
|
|
52
|
+
if (response.success) {
|
|
53
|
+
return response.data;
|
|
54
|
+
}
|
|
55
|
+
throw new Error(response.message);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
throw new Error(`Failed to get plans with pricing: ${error.message}`, {
|
|
58
|
+
cause: error
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get a specific plan by ID (no authentication required)
|
|
64
|
+
*/
|
|
65
|
+
async getPlan(planId) {
|
|
66
|
+
if (!planId) {
|
|
67
|
+
throw new Error("Plan ID is required");
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const response = await this._request(`/plans/${planId}`, {
|
|
71
|
+
method: "GET",
|
|
72
|
+
methodName: "getPlan"
|
|
73
|
+
});
|
|
74
|
+
if (response.success) {
|
|
75
|
+
return response.data;
|
|
76
|
+
}
|
|
77
|
+
throw new Error(response.message);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
throw new Error(`Failed to get plan: ${error.message}`, { cause: error });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// ==================== ADMIN PLAN METHODS ====================
|
|
83
|
+
/**
|
|
84
|
+
* Get all plans including inactive ones (admin only)
|
|
85
|
+
*/
|
|
86
|
+
async getAdminPlans() {
|
|
87
|
+
this._requireReady("getAdminPlans");
|
|
88
|
+
try {
|
|
89
|
+
const response = await this._request("/admin/plans", {
|
|
90
|
+
method: "GET",
|
|
91
|
+
methodName: "getAdminPlans"
|
|
92
|
+
});
|
|
93
|
+
if (response.success) {
|
|
94
|
+
return response.data;
|
|
95
|
+
}
|
|
96
|
+
throw new Error(response.message);
|
|
97
|
+
} catch (error) {
|
|
98
|
+
throw new Error(`Failed to get admin plans: ${error.message}`, {
|
|
99
|
+
cause: error
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create a new plan (admin only)
|
|
105
|
+
*/
|
|
106
|
+
async createPlan(planData) {
|
|
107
|
+
this._requireReady("createPlan");
|
|
108
|
+
if (!planData || typeof planData !== "object") {
|
|
109
|
+
throw new Error("Plan data is required");
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const response = await this._request("/admin/plans", {
|
|
113
|
+
method: "POST",
|
|
114
|
+
body: JSON.stringify(planData),
|
|
115
|
+
methodName: "createPlan"
|
|
116
|
+
});
|
|
117
|
+
if (response.success) {
|
|
118
|
+
return response.data;
|
|
119
|
+
}
|
|
120
|
+
throw new Error(response.message);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
throw new Error(`Failed to create plan: ${error.message}`, {
|
|
123
|
+
cause: error
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Update an existing plan (admin only)
|
|
129
|
+
*/
|
|
130
|
+
async updatePlan(planId, planData) {
|
|
131
|
+
this._requireReady("updatePlan");
|
|
132
|
+
if (!planId) {
|
|
133
|
+
throw new Error("Plan ID is required");
|
|
134
|
+
}
|
|
135
|
+
if (!planData || typeof planData !== "object") {
|
|
136
|
+
throw new Error("Plan data is required");
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const response = await this._request(`/admin/plans/${planId}`, {
|
|
140
|
+
method: "PATCH",
|
|
141
|
+
body: JSON.stringify(planData),
|
|
142
|
+
methodName: "updatePlan"
|
|
143
|
+
});
|
|
144
|
+
if (response.success) {
|
|
145
|
+
return response.data;
|
|
146
|
+
}
|
|
147
|
+
throw new Error(response.message);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
throw new Error(`Failed to update plan: ${error.message}`, {
|
|
150
|
+
cause: error
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Delete a plan (soft delete + archive Stripe product) (admin only)
|
|
156
|
+
*/
|
|
157
|
+
async deletePlan(planId) {
|
|
158
|
+
this._requireReady("deletePlan");
|
|
159
|
+
if (!planId) {
|
|
160
|
+
throw new Error("Plan ID is required");
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const response = await this._request(`/admin/plans/${planId}`, {
|
|
164
|
+
method: "DELETE",
|
|
165
|
+
methodName: "deletePlan"
|
|
166
|
+
});
|
|
167
|
+
if (response.success) {
|
|
168
|
+
return response.data;
|
|
169
|
+
}
|
|
170
|
+
throw new Error(response.message);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
throw new Error(`Failed to delete plan: ${error.message}`, {
|
|
173
|
+
cause: error
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Initialize default plans (admin only)
|
|
179
|
+
*/
|
|
180
|
+
async initializePlans() {
|
|
181
|
+
this._requireReady("initializePlans");
|
|
182
|
+
try {
|
|
183
|
+
const response = await this._request("/admin/plans/initialize", {
|
|
184
|
+
method: "POST",
|
|
185
|
+
methodName: "initializePlans"
|
|
186
|
+
});
|
|
187
|
+
if (response.success) {
|
|
188
|
+
return response;
|
|
189
|
+
}
|
|
190
|
+
throw new Error(response.message);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
throw new Error(`Failed to initialize plans: ${error.message}`, {
|
|
193
|
+
cause: error
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// ==================== PLAN HELPER METHODS ====================
|
|
198
|
+
/**
|
|
199
|
+
* Helper method to get plans with validation
|
|
200
|
+
*/
|
|
201
|
+
async getPlansWithValidation() {
|
|
202
|
+
try {
|
|
203
|
+
const plans = await this.getPlans();
|
|
204
|
+
if (!Array.isArray(plans)) {
|
|
205
|
+
throw new Error("Invalid response format: plans should be an array");
|
|
206
|
+
}
|
|
207
|
+
return plans;
|
|
208
|
+
} catch (error) {
|
|
209
|
+
throw new Error(`Failed to get plans with validation: ${error.message}`, {
|
|
210
|
+
cause: error
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Helper method to get a plan by ID with validation
|
|
216
|
+
*/
|
|
217
|
+
async getPlanWithValidation(planId) {
|
|
218
|
+
if (!planId || typeof planId !== "string") {
|
|
219
|
+
throw new Error("Plan ID must be a valid string");
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
const plan = await this.getPlan(planId);
|
|
223
|
+
if (!plan || typeof plan !== "object") {
|
|
224
|
+
throw new Error("Invalid plan data received");
|
|
225
|
+
}
|
|
226
|
+
return plan;
|
|
227
|
+
} catch (error) {
|
|
228
|
+
throw new Error(`Failed to get plan with validation: ${error.message}`, {
|
|
229
|
+
cause: error
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Helper method to create a plan with validation (admin only)
|
|
235
|
+
*/
|
|
236
|
+
async createPlanWithValidation(planData) {
|
|
237
|
+
if (!planData || typeof planData !== "object") {
|
|
238
|
+
throw new Error("Plan data must be a valid object");
|
|
239
|
+
}
|
|
240
|
+
const requiredFields = ["name", "description"];
|
|
241
|
+
for (const field of requiredFields) {
|
|
242
|
+
if (!planData[field]) {
|
|
243
|
+
throw new Error(`Required field '${field}' is missing`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (Object.hasOwn(planData, "price")) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
'Field "price" is no longer supported. Use unified "pricingOptions" with "amount" instead.'
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
if (planData.pricingOptions != null) {
|
|
252
|
+
if (!Array.isArray(planData.pricingOptions) || planData.pricingOptions.length === 0) {
|
|
253
|
+
throw new Error(
|
|
254
|
+
"pricingOptions must be a non-empty array when provided"
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
const allowedIntervals = /* @__PURE__ */ new Set(["month", "year", "week", "day", null]);
|
|
258
|
+
planData.pricingOptions.forEach((option, index) => {
|
|
259
|
+
if (!option || typeof option !== "object") {
|
|
260
|
+
throw new Error(`Pricing option at index ${index} must be an object`);
|
|
261
|
+
}
|
|
262
|
+
const { key, displayName, amount, interval, lookupKey } = option;
|
|
263
|
+
if (!key || typeof key !== "string") {
|
|
264
|
+
throw new Error(
|
|
265
|
+
`Pricing option at index ${index} is missing required field 'key'`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
if (!/^[a-z0-9-]+$/u.test(key)) {
|
|
269
|
+
throw new Error(
|
|
270
|
+
`Pricing option key '${key}' must contain only lowercase letters, numbers, and hyphens`
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
if (!displayName || typeof displayName !== "string") {
|
|
274
|
+
throw new Error(
|
|
275
|
+
`Pricing option '${key}' is missing required field 'displayName'`
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
if (typeof amount !== "number" || amount < 0) {
|
|
279
|
+
throw new Error(
|
|
280
|
+
`Pricing option '${key}' must have a non-negative numeric 'amount'`
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
if (interval !== null && !allowedIntervals.has(interval)) {
|
|
284
|
+
throw new Error(
|
|
285
|
+
`Pricing option '${key}' has invalid interval '${interval}'. Allowed: month, year, week, day or null`
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
if (!lookupKey || typeof lookupKey !== "string") {
|
|
289
|
+
throw new Error(
|
|
290
|
+
`Pricing option '${key}' is missing required field 'lookupKey'`
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
if (Object.hasOwn(planData, "key") && planData.key == null) {
|
|
296
|
+
throw new Error("Plan key must be a valid string");
|
|
297
|
+
}
|
|
298
|
+
if (planData.key && !/^[a-z0-9-]+$/u.test(planData.key)) {
|
|
299
|
+
throw new Error(
|
|
300
|
+
"Plan key must contain only lowercase letters, numbers, and hyphens"
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
return await this.createPlan(planData);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Helper method to update a plan with validation (admin only)
|
|
307
|
+
*/
|
|
308
|
+
async updatePlanWithValidation(planId, planData) {
|
|
309
|
+
if (!planId || typeof planId !== "string") {
|
|
310
|
+
throw new Error("Plan ID must be a valid string");
|
|
311
|
+
}
|
|
312
|
+
if (!planData || typeof planData !== "object") {
|
|
313
|
+
throw new Error("Plan data must be a valid object");
|
|
314
|
+
}
|
|
315
|
+
if (Object.hasOwn(planData, "price")) {
|
|
316
|
+
throw new Error(
|
|
317
|
+
'Field "price" is no longer supported. Use unified "pricingOptions" with "amount" instead.'
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
if (planData.pricingOptions != null) {
|
|
321
|
+
if (!Array.isArray(planData.pricingOptions) || planData.pricingOptions.length === 0) {
|
|
322
|
+
throw new Error(
|
|
323
|
+
"pricingOptions must be a non-empty array when provided"
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
const allowedIntervals = /* @__PURE__ */ new Set(["month", "year", "week", "day", null]);
|
|
327
|
+
planData.pricingOptions.forEach((option, index) => {
|
|
328
|
+
if (!option || typeof option !== "object") {
|
|
329
|
+
throw new Error(`Pricing option at index ${index} must be an object`);
|
|
330
|
+
}
|
|
331
|
+
const { key, displayName, amount, interval, lookupKey } = option;
|
|
332
|
+
if (!key || typeof key !== "string") {
|
|
333
|
+
throw new Error(
|
|
334
|
+
`Pricing option at index ${index} is missing required field 'key'`
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
if (!/^[a-z0-9-]+$/u.test(key)) {
|
|
338
|
+
throw new Error(
|
|
339
|
+
`Pricing option key '${key}' must contain only lowercase letters, numbers, and hyphens`
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
if (!displayName || typeof displayName !== "string") {
|
|
343
|
+
throw new Error(
|
|
344
|
+
`Pricing option '${key}' is missing required field 'displayName'`
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
if (typeof amount !== "number" || amount < 0) {
|
|
348
|
+
throw new Error(
|
|
349
|
+
`Pricing option '${key}' must have a non-negative numeric 'amount'`
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
if (interval !== null && !allowedIntervals.has(interval)) {
|
|
353
|
+
throw new Error(
|
|
354
|
+
`Pricing option '${key}' has invalid interval '${interval}'. Allowed: month, year, week, day or null`
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
if (!lookupKey || typeof lookupKey !== "string") {
|
|
358
|
+
throw new Error(
|
|
359
|
+
`Pricing option '${key}' is missing required field 'lookupKey'`
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
if (Object.hasOwn(planData, "key") && planData.key == null) {
|
|
365
|
+
throw new Error("Plan key must be a valid string");
|
|
366
|
+
}
|
|
367
|
+
if (planData.key && !/^[a-z0-9-]+$/u.test(planData.key)) {
|
|
368
|
+
throw new Error(
|
|
369
|
+
"Plan key must contain only lowercase letters, numbers, and hyphens"
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
return await this.updatePlan(planId, planData);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Helper method to get active plans only
|
|
376
|
+
*/
|
|
377
|
+
async getActivePlans() {
|
|
378
|
+
try {
|
|
379
|
+
const plans = await this.getPlans();
|
|
380
|
+
return plans.filter(
|
|
381
|
+
(plan) => plan.status === "active" && plan.isVisible !== false
|
|
382
|
+
);
|
|
383
|
+
} catch (error) {
|
|
384
|
+
throw new Error(`Failed to get active plans: ${error.message}`, {
|
|
385
|
+
cause: error
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Helper method to get plans by price range
|
|
391
|
+
*/
|
|
392
|
+
async getPlansByPriceRange(minPrice = 0, maxPrice = Infinity) {
|
|
393
|
+
try {
|
|
394
|
+
const plans = await this.getPlansWithPricing();
|
|
395
|
+
return plans.filter((plan) => {
|
|
396
|
+
var _a, _b;
|
|
397
|
+
const price = ((_b = (_a = plan == null ? void 0 : plan.pricing) == null ? void 0 : _a.bestPrice) == null ? void 0 : _b.amount) ?? 0;
|
|
398
|
+
return price >= minPrice && price <= maxPrice;
|
|
399
|
+
});
|
|
400
|
+
} catch (error) {
|
|
401
|
+
throw new Error(`Failed to get plans by price range: ${error.message}`, {
|
|
402
|
+
cause: error
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Helper method to find plan by key
|
|
408
|
+
*/
|
|
409
|
+
async getPlanByKey(key) {
|
|
410
|
+
if (!key) {
|
|
411
|
+
throw new Error("Plan key is required");
|
|
412
|
+
}
|
|
413
|
+
try {
|
|
414
|
+
const plans = await this.getPlans();
|
|
415
|
+
const plan = plans.find((p) => p.key === key);
|
|
416
|
+
if (!plan) {
|
|
417
|
+
throw new Error(`Plan with key '${key}' not found`);
|
|
418
|
+
}
|
|
419
|
+
return plan;
|
|
420
|
+
} catch (error) {
|
|
421
|
+
throw new Error(`Failed to get plan by key: ${error.message}`, {
|
|
422
|
+
cause: error
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|