@symbo.ls/sdk 2.34.35 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/README.md +2 -143
  2. package/dist/cjs/config/environment.js +30 -98
  3. package/dist/cjs/index.js +24 -144
  4. package/dist/cjs/services/AIService.js +155 -0
  5. package/dist/cjs/services/AuthService.js +305 -738
  6. package/dist/cjs/services/BaseService.js +6 -158
  7. package/dist/cjs/services/BasedService.js +1185 -0
  8. package/dist/cjs/services/CoreService.js +1751 -0
  9. package/dist/cjs/services/SocketIOService.js +307 -0
  10. package/dist/cjs/services/SocketService.js +161 -0
  11. package/dist/cjs/services/SymstoryService.js +571 -0
  12. package/dist/cjs/services/index.js +16 -64
  13. package/dist/cjs/utils/TokenManager.js +30 -78
  14. package/dist/cjs/utils/basedQuerys.js +181 -0
  15. package/dist/cjs/utils/services.js +103 -301
  16. package/dist/cjs/utils/symstoryClient.js +259 -0
  17. package/dist/cjs/utils/validation.js +3 -0
  18. package/dist/esm/config/environment.js +30 -98
  19. package/dist/esm/index.js +8797 -49416
  20. package/dist/esm/services/AIService.js +185 -0
  21. package/dist/esm/services/AuthService.js +386 -1493
  22. package/dist/esm/services/BaseService.js +6 -757
  23. package/dist/esm/services/BasedService.js +5278 -0
  24. package/dist/esm/services/CoreService.js +2264 -0
  25. package/dist/esm/services/SocketIOService.js +470 -0
  26. package/dist/esm/services/SocketService.js +191 -0
  27. package/dist/esm/services/SymstoryService.js +7041 -0
  28. package/dist/esm/services/index.js +8690 -49015
  29. package/dist/esm/utils/TokenManager.js +30 -78
  30. package/dist/esm/utils/basedQuerys.js +163 -0
  31. package/dist/esm/utils/services.js +103 -301
  32. package/dist/esm/utils/symstoryClient.js +370 -0
  33. package/dist/esm/utils/validation.js +7 -4
  34. package/dist/node/config/environment.js +30 -98
  35. package/dist/node/index.js +32 -175
  36. package/dist/node/services/AIService.js +136 -0
  37. package/dist/node/services/AuthService.js +310 -742
  38. package/dist/node/services/BaseService.js +6 -148
  39. package/dist/node/services/BasedService.js +1156 -0
  40. package/dist/node/services/CoreService.js +1722 -0
  41. package/dist/node/services/SocketIOService.js +278 -0
  42. package/dist/node/services/SocketService.js +142 -0
  43. package/dist/node/services/SymstoryService.js +542 -0
  44. package/dist/node/services/index.js +16 -64
  45. package/dist/node/utils/TokenManager.js +30 -78
  46. package/dist/node/utils/basedQuerys.js +162 -0
  47. package/dist/node/utils/services.js +103 -301
  48. package/dist/node/utils/symstoryClient.js +230 -0
  49. package/dist/node/utils/validation.js +3 -0
  50. package/package.json +16 -35
  51. package/src/config/environment.js +28 -99
  52. package/src/index.js +36 -181
  53. package/src/services/AIService.js +150 -0
  54. package/src/services/AuthService.js +328 -874
  55. package/src/services/BaseService.js +6 -166
  56. package/src/services/BasedService.js +1301 -0
  57. package/src/services/CoreService.js +1943 -0
  58. package/src/services/SocketIOService.js +334 -0
  59. package/src/services/SocketService.js +168 -0
  60. package/src/services/SymstoryService.js +649 -0
  61. package/src/services/index.js +13 -80
  62. package/src/utils/TokenManager.js +33 -88
  63. package/src/utils/basedQuerys.js +164 -0
  64. package/src/utils/services.js +107 -326
  65. package/src/utils/symstoryClient.js +252 -0
  66. package/src/utils/validation.js +3 -0
  67. package/dist/cjs/services/AdminService.js +0 -351
  68. package/dist/cjs/services/BranchService.js +0 -484
  69. package/dist/cjs/services/CollabService.js +0 -743
  70. package/dist/cjs/services/DnsService.js +0 -340
  71. package/dist/cjs/services/FeatureFlagService.js +0 -175
  72. package/dist/cjs/services/FileService.js +0 -201
  73. package/dist/cjs/services/IntegrationService.js +0 -538
  74. package/dist/cjs/services/MetricsService.js +0 -62
  75. package/dist/cjs/services/PaymentService.js +0 -271
  76. package/dist/cjs/services/PlanService.js +0 -426
  77. package/dist/cjs/services/ProjectService.js +0 -1207
  78. package/dist/cjs/services/PullRequestService.js +0 -503
  79. package/dist/cjs/services/ScreenshotService.js +0 -304
  80. package/dist/cjs/services/SubscriptionService.js +0 -396
  81. package/dist/cjs/services/TrackingService.js +0 -661
  82. package/dist/cjs/services/WaitlistService.js +0 -148
  83. package/dist/cjs/state/RootStateManager.js +0 -65
  84. package/dist/cjs/state/rootEventBus.js +0 -74
  85. package/dist/cjs/utils/CollabClient.js +0 -223
  86. package/dist/cjs/utils/changePreprocessor.js +0 -199
  87. package/dist/cjs/utils/jsonDiff.js +0 -145
  88. package/dist/cjs/utils/ordering.js +0 -309
  89. package/dist/esm/services/AdminService.js +0 -1132
  90. package/dist/esm/services/BranchService.js +0 -1265
  91. package/dist/esm/services/CollabService.js +0 -26838
  92. package/dist/esm/services/DnsService.js +0 -1121
  93. package/dist/esm/services/FeatureFlagService.js +0 -956
  94. package/dist/esm/services/FileService.js +0 -982
  95. package/dist/esm/services/IntegrationService.js +0 -1319
  96. package/dist/esm/services/MetricsService.js +0 -843
  97. package/dist/esm/services/PaymentService.js +0 -1052
  98. package/dist/esm/services/PlanService.js +0 -1207
  99. package/dist/esm/services/ProjectService.js +0 -2526
  100. package/dist/esm/services/PullRequestService.js +0 -1284
  101. package/dist/esm/services/ScreenshotService.js +0 -1085
  102. package/dist/esm/services/SubscriptionService.js +0 -1177
  103. package/dist/esm/services/TrackingService.js +0 -18343
  104. package/dist/esm/services/WaitlistService.js +0 -929
  105. package/dist/esm/state/RootStateManager.js +0 -90
  106. package/dist/esm/state/rootEventBus.js +0 -56
  107. package/dist/esm/utils/CollabClient.js +0 -18901
  108. package/dist/esm/utils/changePreprocessor.js +0 -542
  109. package/dist/esm/utils/jsonDiff.js +0 -7011
  110. package/dist/esm/utils/ordering.js +0 -291
  111. package/dist/node/services/AdminService.js +0 -332
  112. package/dist/node/services/BranchService.js +0 -465
  113. package/dist/node/services/CollabService.js +0 -724
  114. package/dist/node/services/DnsService.js +0 -321
  115. package/dist/node/services/FeatureFlagService.js +0 -156
  116. package/dist/node/services/FileService.js +0 -182
  117. package/dist/node/services/IntegrationService.js +0 -519
  118. package/dist/node/services/MetricsService.js +0 -43
  119. package/dist/node/services/PaymentService.js +0 -252
  120. package/dist/node/services/PlanService.js +0 -407
  121. package/dist/node/services/ProjectService.js +0 -1188
  122. package/dist/node/services/PullRequestService.js +0 -484
  123. package/dist/node/services/ScreenshotService.js +0 -285
  124. package/dist/node/services/SubscriptionService.js +0 -377
  125. package/dist/node/services/TrackingService.js +0 -632
  126. package/dist/node/services/WaitlistService.js +0 -129
  127. package/dist/node/state/RootStateManager.js +0 -36
  128. package/dist/node/state/rootEventBus.js +0 -55
  129. package/dist/node/utils/CollabClient.js +0 -194
  130. package/dist/node/utils/changePreprocessor.js +0 -180
  131. package/dist/node/utils/jsonDiff.js +0 -116
  132. package/dist/node/utils/ordering.js +0 -290
  133. package/src/services/AdminService.js +0 -374
  134. package/src/services/BranchService.js +0 -536
  135. package/src/services/CollabService.js +0 -900
  136. package/src/services/DnsService.js +0 -366
  137. package/src/services/FeatureFlagService.js +0 -174
  138. package/src/services/FileService.js +0 -213
  139. package/src/services/IntegrationService.js +0 -548
  140. package/src/services/MetricsService.js +0 -40
  141. package/src/services/PaymentService.js +0 -287
  142. package/src/services/PlanService.js +0 -468
  143. package/src/services/ProjectService.js +0 -1366
  144. package/src/services/PullRequestService.js +0 -537
  145. package/src/services/ScreenshotService.js +0 -258
  146. package/src/services/SubscriptionService.js +0 -425
  147. package/src/services/TrackingService.js +0 -853
  148. package/src/services/WaitlistService.js +0 -130
  149. package/src/services/tests/BranchService/createBranch.test.js +0 -153
  150. package/src/services/tests/BranchService/deleteBranch.test.js +0 -173
  151. package/src/services/tests/BranchService/getBranchChanges.test.js +0 -146
  152. package/src/services/tests/BranchService/listBranches.test.js +0 -87
  153. package/src/services/tests/BranchService/mergeBranch.test.js +0 -210
  154. package/src/services/tests/BranchService/publishVersion.test.js +0 -183
  155. package/src/services/tests/BranchService/renameBranch.test.js +0 -240
  156. package/src/services/tests/BranchService/resetBranch.test.js +0 -152
  157. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +0 -67
  158. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +0 -75
  159. package/src/services/tests/FileService/createFileFormData.test.js +0 -74
  160. package/src/services/tests/FileService/getFileUrl.test.js +0 -69
  161. package/src/services/tests/FileService/updateProjectIcon.test.js +0 -109
  162. package/src/services/tests/FileService/uploadDocument.test.js +0 -36
  163. package/src/services/tests/FileService/uploadFile.test.js +0 -78
  164. package/src/services/tests/FileService/uploadFileWithValidation.test.js +0 -114
  165. package/src/services/tests/FileService/uploadImage.test.js +0 -36
  166. package/src/services/tests/FileService/uploadMultipleFiles.test.js +0 -111
  167. package/src/services/tests/FileService/validateFile.test.js +0 -63
  168. package/src/services/tests/PlanService/createPlan.test.js +0 -104
  169. package/src/services/tests/PlanService/createPlanWithValidation.test.js +0 -523
  170. package/src/services/tests/PlanService/deletePlan.test.js +0 -92
  171. package/src/services/tests/PlanService/getActivePlans.test.js +0 -123
  172. package/src/services/tests/PlanService/getAdminPlans.test.js +0 -84
  173. package/src/services/tests/PlanService/getPlan.test.js +0 -50
  174. package/src/services/tests/PlanService/getPlanByKey.test.js +0 -109
  175. package/src/services/tests/PlanService/getPlanWithValidation.test.js +0 -85
  176. package/src/services/tests/PlanService/getPlans.test.js +0 -53
  177. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +0 -109
  178. package/src/services/tests/PlanService/getPlansWithValidation.test.js +0 -48
  179. package/src/services/tests/PlanService/initializePlans.test.js +0 -75
  180. package/src/services/tests/PlanService/updatePlan.test.js +0 -111
  181. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +0 -556
  182. package/src/state/RootStateManager.js +0 -76
  183. package/src/state/rootEventBus.js +0 -67
  184. package/src/utils/CollabClient.js +0 -248
  185. package/src/utils/changePreprocessor.js +0 -239
  186. package/src/utils/jsonDiff.js +0 -144
  187. package/src/utils/ordering.js +0 -271
@@ -1,468 +0,0 @@
1
- import { BaseService } from './BaseService.js'
2
-
3
- export class PlanService extends BaseService {
4
- // ==================== PLAN METHODS ====================
5
-
6
- /**
7
- * Get list of public plans (no authentication required)
8
- */
9
- async getPlans () {
10
- try {
11
- const response = await this._request('/plans', {
12
- method: 'GET',
13
- methodName: 'getPlans'
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 get plans: ${error.message}`, { cause: error })
21
- }
22
- }
23
-
24
- /**
25
- * Get list of public plans with enhanced pricing information (no authentication required)
26
- */
27
- async getPlansWithPricing () {
28
- try {
29
- const response = await this._request('/plans/pricing', {
30
- method: 'GET',
31
- methodName: 'getPlansWithPricing'
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 plans with pricing: ${error.message}`, {
39
- cause: error
40
- })
41
- }
42
- }
43
-
44
- /**
45
- * Get a specific plan by ID (no authentication required)
46
- */
47
- async getPlan (planId) {
48
- if (!planId) {
49
- throw new Error('Plan ID is required')
50
- }
51
- try {
52
- const response = await this._request(`/plans/${planId}`, {
53
- method: 'GET',
54
- methodName: 'getPlan'
55
- })
56
- if (response.success) {
57
- return response.data
58
- }
59
- throw new Error(response.message)
60
- } catch (error) {
61
- throw new Error(`Failed to get plan: ${error.message}`, { cause: error })
62
- }
63
- }
64
-
65
- // ==================== ADMIN PLAN METHODS ====================
66
-
67
- /**
68
- * Get all plans including inactive ones (admin only)
69
- */
70
- async getAdminPlans () {
71
- this._requireReady('getAdminPlans')
72
- try {
73
- const response = await this._request('/admin/plans', {
74
- method: 'GET',
75
- methodName: 'getAdminPlans'
76
- })
77
- if (response.success) {
78
- return response.data
79
- }
80
- throw new Error(response.message)
81
- } catch (error) {
82
- throw new Error(`Failed to get admin plans: ${error.message}`, {
83
- cause: error
84
- })
85
- }
86
- }
87
-
88
- /**
89
- * Create a new plan (admin only)
90
- */
91
- async createPlan (planData) {
92
- this._requireReady('createPlan')
93
- if (!planData || typeof planData !== 'object') {
94
- throw new Error('Plan data is required')
95
- }
96
- try {
97
- const response = await this._request('/admin/plans', {
98
- method: 'POST',
99
- body: JSON.stringify(planData),
100
- methodName: 'createPlan'
101
- })
102
- if (response.success) {
103
- return response.data
104
- }
105
- throw new Error(response.message)
106
- } catch (error) {
107
- throw new Error(`Failed to create plan: ${error.message}`, {
108
- cause: error
109
- })
110
- }
111
- }
112
-
113
- /**
114
- * Update an existing plan (admin only)
115
- */
116
- async updatePlan (planId, planData) {
117
- this._requireReady('updatePlan')
118
- if (!planId) {
119
- throw new Error('Plan ID is required')
120
- }
121
- if (!planData || typeof planData !== 'object') {
122
- throw new Error('Plan data is required')
123
- }
124
- try {
125
- const response = await this._request(`/admin/plans/${planId}`, {
126
- method: 'PATCH',
127
- body: JSON.stringify(planData),
128
- methodName: 'updatePlan'
129
- })
130
- if (response.success) {
131
- return response.data
132
- }
133
- throw new Error(response.message)
134
- } catch (error) {
135
- throw new Error(`Failed to update plan: ${error.message}`, {
136
- cause: error
137
- })
138
- }
139
- }
140
-
141
- /**
142
- * Delete a plan (soft delete + archive Stripe product) (admin only)
143
- */
144
- async deletePlan (planId) {
145
- this._requireReady('deletePlan')
146
- if (!planId) {
147
- throw new Error('Plan ID is required')
148
- }
149
- try {
150
- const response = await this._request(`/admin/plans/${planId}`, {
151
- method: 'DELETE',
152
- methodName: 'deletePlan'
153
- })
154
- if (response.success) {
155
- return response.data
156
- }
157
- throw new Error(response.message)
158
- } catch (error) {
159
- throw new Error(`Failed to delete plan: ${error.message}`, {
160
- cause: error
161
- })
162
- }
163
- }
164
-
165
- /**
166
- * Initialize default plans (admin only)
167
- */
168
- async initializePlans () {
169
- this._requireReady('initializePlans')
170
- try {
171
- const response = await this._request('/admin/plans/initialize', {
172
- method: 'POST',
173
- methodName: 'initializePlans'
174
- })
175
- if (response.success) {
176
- return response
177
- }
178
- throw new Error(response.message)
179
- } catch (error) {
180
- throw new Error(`Failed to initialize plans: ${error.message}`, {
181
- cause: error
182
- })
183
- }
184
- }
185
-
186
- // ==================== PLAN HELPER METHODS ====================
187
-
188
- /**
189
- * Helper method to get plans with validation
190
- */
191
- async getPlansWithValidation () {
192
- try {
193
- const plans = await this.getPlans()
194
- if (!Array.isArray(plans)) {
195
- throw new Error('Invalid response format: plans should be an array')
196
- }
197
- return plans
198
- } catch (error) {
199
- throw new Error(`Failed to get plans with validation: ${error.message}`, {
200
- cause: error
201
- })
202
- }
203
- }
204
-
205
- /**
206
- * Helper method to get a plan by ID with validation
207
- */
208
- async getPlanWithValidation (planId) {
209
- if (!planId || typeof planId !== 'string') {
210
- throw new Error('Plan ID must be a valid string')
211
- }
212
-
213
- try {
214
- const plan = await this.getPlan(planId)
215
- if (!plan || typeof plan !== 'object') {
216
- throw new Error('Invalid plan data received')
217
- }
218
- return plan
219
- } catch (error) {
220
- throw new Error(`Failed to get plan with validation: ${error.message}`, {
221
- cause: error
222
- })
223
- }
224
- }
225
-
226
- /**
227
- * Helper method to create a plan with validation (admin only)
228
- */
229
- async createPlanWithValidation (planData) {
230
- if (!planData || typeof planData !== 'object') {
231
- throw new Error('Plan data must be a valid object')
232
- }
233
-
234
- // Basic validation for required fields to match server model
235
- const requiredFields = ['name', 'description']
236
- for (const field of requiredFields) {
237
- if (!planData[field]) {
238
- throw new Error(`Required field '${field}' is missing`)
239
- }
240
- }
241
-
242
- // Legacy field guard: bare "price" is no longer supported on the server
243
- if (Object.hasOwn(planData, 'price')) {
244
- throw new Error(
245
- 'Field "price" is no longer supported. Use unified "pricingOptions" with "amount" instead.'
246
- )
247
- }
248
-
249
- // Validate unified pricingOptions structure if provided
250
- if (planData.pricingOptions != null) {
251
- if (
252
- !Array.isArray(planData.pricingOptions) ||
253
- planData.pricingOptions.length === 0
254
- ) {
255
- throw new Error(
256
- 'pricingOptions must be a non-empty array when provided'
257
- )
258
- }
259
-
260
- const allowedIntervals = new Set(['month', 'year', 'week', 'day', null])
261
- planData.pricingOptions.forEach((option, index) => {
262
- if (!option || typeof option !== 'object') {
263
- throw new Error(`Pricing option at index ${index} must be an object`)
264
- }
265
-
266
- const { key, displayName, amount, interval, lookupKey } = option
267
-
268
- if (!key || typeof key !== 'string') {
269
- throw new Error(
270
- `Pricing option at index ${index} is missing required field 'key'`
271
- )
272
- }
273
-
274
- // Validate key format (alphanumeric and hyphens only)
275
- if (!/^[a-z0-9-]+$/u.test(key)) {
276
- throw new Error(
277
- `Pricing option key '${key}' must contain only lowercase letters, numbers, and hyphens`
278
- )
279
- }
280
-
281
- if (!displayName || typeof displayName !== 'string') {
282
- throw new Error(
283
- `Pricing option '${key}' is missing required field 'displayName'`
284
- )
285
- }
286
-
287
- if (typeof amount !== 'number' || amount < 0) {
288
- throw new Error(
289
- `Pricing option '${key}' must have a non-negative numeric 'amount'`
290
- )
291
- }
292
-
293
- if (interval !== null && !allowedIntervals.has(interval)) {
294
- throw new Error(
295
- `Pricing option '${key}' has invalid interval '${interval}'. Allowed: month, year, week, day or null`
296
- )
297
- }
298
-
299
- if (!lookupKey || typeof lookupKey !== 'string') {
300
- throw new Error(
301
- `Pricing option '${key}' is missing required field 'lookupKey'`
302
- )
303
- }
304
- })
305
- }
306
-
307
- // Optional: validate top-level key if provided (legacy support)
308
- if (Object.hasOwn(planData, 'key') && planData.key == null) {
309
- throw new Error('Plan key must be a valid string')
310
- }
311
- if (planData.key && !/^[a-z0-9-]+$/u.test(planData.key)) {
312
- throw new Error(
313
- 'Plan key must contain only lowercase letters, numbers, and hyphens'
314
- )
315
- }
316
-
317
- return await this.createPlan(planData)
318
- }
319
-
320
- /**
321
- * Helper method to update a plan with validation (admin only)
322
- */
323
- async updatePlanWithValidation (planId, planData) {
324
- if (!planId || typeof planId !== 'string') {
325
- throw new Error('Plan ID must be a valid string')
326
- }
327
- if (!planData || typeof planData !== 'object') {
328
- throw new Error('Plan data must be a valid object')
329
- }
330
-
331
- // Legacy field guard: bare "price" is no longer supported on the server
332
- if (Object.hasOwn(planData, 'price')) {
333
- throw new Error(
334
- 'Field "price" is no longer supported. Use unified "pricingOptions" with "amount" instead.'
335
- )
336
- }
337
-
338
- // Validate unified pricingOptions structure if provided
339
- if (planData.pricingOptions != null) {
340
- if (
341
- !Array.isArray(planData.pricingOptions) ||
342
- planData.pricingOptions.length === 0
343
- ) {
344
- throw new Error(
345
- 'pricingOptions must be a non-empty array when provided'
346
- )
347
- }
348
-
349
- const allowedIntervals = new Set(['month', 'year', 'week', 'day', null])
350
- planData.pricingOptions.forEach((option, index) => {
351
- if (!option || typeof option !== 'object') {
352
- throw new Error(`Pricing option at index ${index} must be an object`)
353
- }
354
-
355
- const { key, displayName, amount, interval, lookupKey } = option
356
-
357
- if (!key || typeof key !== 'string') {
358
- throw new Error(
359
- `Pricing option at index ${index} is missing required field 'key'`
360
- )
361
- }
362
-
363
- // Validate key format (alphanumeric and hyphens only)
364
- if (!/^[a-z0-9-]+$/u.test(key)) {
365
- throw new Error(
366
- `Pricing option key '${key}' must contain only lowercase letters, numbers, and hyphens`
367
- )
368
- }
369
-
370
- if (!displayName || typeof displayName !== 'string') {
371
- throw new Error(
372
- `Pricing option '${key}' is missing required field 'displayName'`
373
- )
374
- }
375
-
376
- if (typeof amount !== 'number' || amount < 0) {
377
- throw new Error(
378
- `Pricing option '${key}' must have a non-negative numeric 'amount'`
379
- )
380
- }
381
-
382
- if (interval !== null && !allowedIntervals.has(interval)) {
383
- throw new Error(
384
- `Pricing option '${key}' has invalid interval '${interval}'. Allowed: month, year, week, day or null`
385
- )
386
- }
387
-
388
- if (!lookupKey || typeof lookupKey !== 'string') {
389
- throw new Error(
390
- `Pricing option '${key}' is missing required field 'lookupKey'`
391
- )
392
- }
393
- })
394
- }
395
-
396
- // Validate key format if provided
397
- if (Object.hasOwn(planData, 'key') && planData.key == null) {
398
- throw new Error('Plan key must be a valid string')
399
- }
400
- if (planData.key && !/^[a-z0-9-]+$/u.test(planData.key)) {
401
- throw new Error(
402
- 'Plan key must contain only lowercase letters, numbers, and hyphens'
403
- )
404
- }
405
-
406
- return await this.updatePlan(planId, planData)
407
- }
408
-
409
- /**
410
- * Helper method to get active plans only
411
- */
412
- async getActivePlans () {
413
- try {
414
- const plans = await this.getPlans()
415
- // Server already returns only active & visible plans for /plans,
416
- // but we keep this helper aligned with the model fields.
417
- return plans.filter(
418
- plan => plan.status === 'active' && plan.isVisible !== false
419
- )
420
- } catch (error) {
421
- throw new Error(`Failed to get active plans: ${error.message}`, {
422
- cause: error
423
- })
424
- }
425
- }
426
-
427
- /**
428
- * Helper method to get plans by price range
429
- */
430
- async getPlansByPriceRange (minPrice = 0, maxPrice = Infinity) {
431
- try {
432
- // Use enhanced pricing information from /plans/pricing
433
- const plans = await this.getPlansWithPricing()
434
- return plans.filter(plan => {
435
- const price = plan?.pricing?.bestPrice?.amount ?? 0
436
- return price >= minPrice && price <= maxPrice
437
- })
438
- } catch (error) {
439
- throw new Error(`Failed to get plans by price range: ${error.message}`, {
440
- cause: error
441
- })
442
- }
443
- }
444
-
445
- /**
446
- * Helper method to find plan by key
447
- */
448
- async getPlanByKey (key) {
449
- if (!key) {
450
- throw new Error('Plan key is required')
451
- }
452
-
453
- try {
454
- const plans = await this.getPlans()
455
- const plan = plans.find(p => p.key === key)
456
-
457
- if (!plan) {
458
- throw new Error(`Plan with key '${key}' not found`)
459
- }
460
-
461
- return plan
462
- } catch (error) {
463
- throw new Error(`Failed to get plan by key: ${error.message}`, {
464
- cause: error
465
- })
466
- }
467
- }
468
- }