@symbo.ls/sdk 3.1.2 → 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.
Files changed (187) hide show
  1. package/README.md +143 -2
  2. package/dist/cjs/config/environment.js +98 -30
  3. package/dist/cjs/index.js +144 -24
  4. package/dist/cjs/services/AdminService.js +351 -0
  5. package/dist/cjs/services/AuthService.js +738 -305
  6. package/dist/cjs/services/BaseService.js +158 -6
  7. package/dist/cjs/services/BranchService.js +484 -0
  8. package/dist/cjs/services/CollabService.js +743 -0
  9. package/dist/cjs/services/DnsService.js +340 -0
  10. package/dist/cjs/services/FeatureFlagService.js +175 -0
  11. package/dist/cjs/services/FileService.js +201 -0
  12. package/dist/cjs/services/IntegrationService.js +538 -0
  13. package/dist/cjs/services/MetricsService.js +62 -0
  14. package/dist/cjs/services/PaymentService.js +271 -0
  15. package/dist/cjs/services/PlanService.js +426 -0
  16. package/dist/cjs/services/ProjectService.js +1207 -0
  17. package/dist/cjs/services/PullRequestService.js +503 -0
  18. package/dist/cjs/services/ScreenshotService.js +304 -0
  19. package/dist/cjs/services/SubscriptionService.js +396 -0
  20. package/dist/cjs/services/TrackingService.js +661 -0
  21. package/dist/cjs/services/WaitlistService.js +148 -0
  22. package/dist/cjs/services/index.js +64 -16
  23. package/dist/cjs/state/RootStateManager.js +65 -0
  24. package/dist/cjs/state/rootEventBus.js +74 -0
  25. package/dist/cjs/utils/CollabClient.js +223 -0
  26. package/dist/cjs/utils/TokenManager.js +78 -30
  27. package/dist/cjs/utils/changePreprocessor.js +199 -0
  28. package/dist/cjs/utils/jsonDiff.js +145 -0
  29. package/dist/cjs/utils/ordering.js +309 -0
  30. package/dist/cjs/utils/services.js +301 -103
  31. package/dist/cjs/utils/validation.js +0 -3
  32. package/dist/esm/config/environment.js +98 -30
  33. package/dist/esm/index.js +49505 -8718
  34. package/dist/esm/services/AdminService.js +1132 -0
  35. package/dist/esm/services/AuthService.js +1493 -386
  36. package/dist/esm/services/BaseService.js +757 -6
  37. package/dist/esm/services/BranchService.js +1265 -0
  38. package/dist/esm/services/CollabService.js +26895 -0
  39. package/dist/esm/services/DnsService.js +1121 -0
  40. package/dist/esm/services/FeatureFlagService.js +956 -0
  41. package/dist/esm/services/FileService.js +982 -0
  42. package/dist/esm/services/IntegrationService.js +1319 -0
  43. package/dist/esm/services/MetricsService.js +843 -0
  44. package/dist/esm/services/PaymentService.js +1052 -0
  45. package/dist/esm/services/PlanService.js +1207 -0
  46. package/dist/esm/services/ProjectService.js +2526 -0
  47. package/dist/esm/services/PullRequestService.js +1284 -0
  48. package/dist/esm/services/ScreenshotService.js +1085 -0
  49. package/dist/esm/services/SubscriptionService.js +1177 -0
  50. package/dist/esm/services/TrackingService.js +18454 -0
  51. package/dist/esm/services/WaitlistService.js +929 -0
  52. package/dist/esm/services/index.js +49062 -8569
  53. package/dist/esm/state/RootStateManager.js +90 -0
  54. package/dist/esm/state/rootEventBus.js +56 -0
  55. package/dist/esm/utils/CollabClient.js +18889 -0
  56. package/dist/esm/utils/TokenManager.js +78 -30
  57. package/dist/esm/utils/changePreprocessor.js +542 -0
  58. package/dist/esm/utils/jsonDiff.js +7011 -0
  59. package/dist/esm/utils/ordering.js +291 -0
  60. package/dist/esm/utils/services.js +301 -103
  61. package/dist/esm/utils/validation.js +116 -50
  62. package/dist/node/config/environment.js +98 -30
  63. package/dist/node/index.js +175 -32
  64. package/dist/node/services/AdminService.js +332 -0
  65. package/dist/node/services/AuthService.js +742 -310
  66. package/dist/node/services/BaseService.js +148 -6
  67. package/dist/node/services/BranchService.js +465 -0
  68. package/dist/node/services/CollabService.js +724 -0
  69. package/dist/node/services/DnsService.js +321 -0
  70. package/dist/node/services/FeatureFlagService.js +156 -0
  71. package/dist/node/services/FileService.js +182 -0
  72. package/dist/node/services/IntegrationService.js +519 -0
  73. package/dist/node/services/MetricsService.js +43 -0
  74. package/dist/node/services/PaymentService.js +252 -0
  75. package/dist/node/services/PlanService.js +407 -0
  76. package/dist/node/services/ProjectService.js +1188 -0
  77. package/dist/node/services/PullRequestService.js +484 -0
  78. package/dist/node/services/ScreenshotService.js +285 -0
  79. package/dist/node/services/SubscriptionService.js +377 -0
  80. package/dist/node/services/TrackingService.js +632 -0
  81. package/dist/node/services/WaitlistService.js +129 -0
  82. package/dist/node/services/index.js +64 -16
  83. package/dist/node/state/RootStateManager.js +36 -0
  84. package/dist/node/state/rootEventBus.js +55 -0
  85. package/dist/node/utils/CollabClient.js +194 -0
  86. package/dist/node/utils/TokenManager.js +78 -30
  87. package/dist/node/utils/changePreprocessor.js +180 -0
  88. package/dist/node/utils/jsonDiff.js +116 -0
  89. package/dist/node/utils/ordering.js +290 -0
  90. package/dist/node/utils/services.js +301 -103
  91. package/dist/node/utils/validation.js +0 -3
  92. package/package.json +39 -21
  93. package/src/config/environment.js +99 -28
  94. package/src/index.js +181 -36
  95. package/src/services/AdminService.js +374 -0
  96. package/src/services/AuthService.js +874 -328
  97. package/src/services/BaseService.js +166 -6
  98. package/src/services/BranchService.js +536 -0
  99. package/src/services/CollabService.js +900 -0
  100. package/src/services/DnsService.js +366 -0
  101. package/src/services/FeatureFlagService.js +174 -0
  102. package/src/services/FileService.js +213 -0
  103. package/src/services/IntegrationService.js +548 -0
  104. package/src/services/MetricsService.js +40 -0
  105. package/src/services/PaymentService.js +287 -0
  106. package/src/services/PlanService.js +468 -0
  107. package/src/services/ProjectService.js +1366 -0
  108. package/src/services/PullRequestService.js +537 -0
  109. package/src/services/ScreenshotService.js +258 -0
  110. package/src/services/SubscriptionService.js +425 -0
  111. package/src/services/TrackingService.js +853 -0
  112. package/src/services/WaitlistService.js +130 -0
  113. package/src/services/index.js +80 -13
  114. package/src/services/tests/BranchService/createBranch.test.js +153 -0
  115. package/src/services/tests/BranchService/deleteBranch.test.js +173 -0
  116. package/src/services/tests/BranchService/getBranchChanges.test.js +146 -0
  117. package/src/services/tests/BranchService/listBranches.test.js +87 -0
  118. package/src/services/tests/BranchService/mergeBranch.test.js +210 -0
  119. package/src/services/tests/BranchService/publishVersion.test.js +183 -0
  120. package/src/services/tests/BranchService/renameBranch.test.js +240 -0
  121. package/src/services/tests/BranchService/resetBranch.test.js +152 -0
  122. package/src/services/tests/FeatureFlagService/adminFeatureFlags.test.js +67 -0
  123. package/src/services/tests/FeatureFlagService/getFeatureFlags.test.js +75 -0
  124. package/src/services/tests/FileService/createFileFormData.test.js +74 -0
  125. package/src/services/tests/FileService/getFileUrl.test.js +69 -0
  126. package/src/services/tests/FileService/updateProjectIcon.test.js +109 -0
  127. package/src/services/tests/FileService/uploadDocument.test.js +36 -0
  128. package/src/services/tests/FileService/uploadFile.test.js +78 -0
  129. package/src/services/tests/FileService/uploadFileWithValidation.test.js +114 -0
  130. package/src/services/tests/FileService/uploadImage.test.js +36 -0
  131. package/src/services/tests/FileService/uploadMultipleFiles.test.js +111 -0
  132. package/src/services/tests/FileService/validateFile.test.js +63 -0
  133. package/src/services/tests/PlanService/createPlan.test.js +104 -0
  134. package/src/services/tests/PlanService/createPlanWithValidation.test.js +523 -0
  135. package/src/services/tests/PlanService/deletePlan.test.js +92 -0
  136. package/src/services/tests/PlanService/getActivePlans.test.js +123 -0
  137. package/src/services/tests/PlanService/getAdminPlans.test.js +84 -0
  138. package/src/services/tests/PlanService/getPlan.test.js +50 -0
  139. package/src/services/tests/PlanService/getPlanByKey.test.js +109 -0
  140. package/src/services/tests/PlanService/getPlanWithValidation.test.js +85 -0
  141. package/src/services/tests/PlanService/getPlans.test.js +53 -0
  142. package/src/services/tests/PlanService/getPlansByPriceRange.test.js +109 -0
  143. package/src/services/tests/PlanService/getPlansWithValidation.test.js +48 -0
  144. package/src/services/tests/PlanService/initializePlans.test.js +75 -0
  145. package/src/services/tests/PlanService/updatePlan.test.js +111 -0
  146. package/src/services/tests/PlanService/updatePlanWithValidation.test.js +556 -0
  147. package/src/state/RootStateManager.js +76 -0
  148. package/src/state/rootEventBus.js +67 -0
  149. package/src/utils/CollabClient.js +248 -0
  150. package/src/utils/TokenManager.js +88 -33
  151. package/src/utils/changePreprocessor.js +239 -0
  152. package/src/utils/jsonDiff.js +144 -0
  153. package/src/utils/ordering.js +271 -0
  154. package/src/utils/services.js +326 -107
  155. package/src/utils/validation.js +0 -3
  156. package/dist/cjs/services/AIService.js +0 -155
  157. package/dist/cjs/services/BasedService.js +0 -1185
  158. package/dist/cjs/services/CoreService.js +0 -1751
  159. package/dist/cjs/services/SocketIOService.js +0 -307
  160. package/dist/cjs/services/SocketService.js +0 -161
  161. package/dist/cjs/services/SymstoryService.js +0 -571
  162. package/dist/cjs/utils/basedQuerys.js +0 -181
  163. package/dist/cjs/utils/symstoryClient.js +0 -259
  164. package/dist/esm/services/AIService.js +0 -185
  165. package/dist/esm/services/BasedService.js +0 -5278
  166. package/dist/esm/services/CoreService.js +0 -2264
  167. package/dist/esm/services/SocketIOService.js +0 -470
  168. package/dist/esm/services/SocketService.js +0 -191
  169. package/dist/esm/services/SymstoryService.js +0 -7041
  170. package/dist/esm/utils/basedQuerys.js +0 -163
  171. package/dist/esm/utils/symstoryClient.js +0 -370
  172. package/dist/node/services/AIService.js +0 -136
  173. package/dist/node/services/BasedService.js +0 -1156
  174. package/dist/node/services/CoreService.js +0 -1722
  175. package/dist/node/services/SocketIOService.js +0 -278
  176. package/dist/node/services/SocketService.js +0 -142
  177. package/dist/node/services/SymstoryService.js +0 -542
  178. package/dist/node/utils/basedQuerys.js +0 -162
  179. package/dist/node/utils/symstoryClient.js +0 -230
  180. package/src/services/AIService.js +0 -150
  181. package/src/services/BasedService.js +0 -1301
  182. package/src/services/CoreService.js +0 -1943
  183. package/src/services/SocketIOService.js +0 -334
  184. package/src/services/SocketService.js +0 -168
  185. package/src/services/SymstoryService.js +0 -649
  186. package/src/utils/basedQuerys.js +0 -164
  187. package/src/utils/symstoryClient.js +0 -252
@@ -1,470 +0,0 @@
1
- // src/services/SocketIOService.js
2
- import { connect, send, disconnect } from "@symbo.ls/socket/client.js";
3
-
4
- // src/services/BaseService.js
5
- var BaseService = class {
6
- constructor({ context, options } = {}) {
7
- this._context = context || {};
8
- this._options = options || {};
9
- this._ready = false;
10
- this._error = null;
11
- }
12
- // Initialize service
13
- init() {
14
- throw new Error("init() must be implemented by service");
15
- }
16
- // Update context
17
- updateContext(context) {
18
- this._context = { ...this._context, ...context };
19
- }
20
- // Get service status
21
- getStatus() {
22
- return {
23
- ready: this._ready,
24
- error: this._error,
25
- context: { ...this._context }
26
- };
27
- }
28
- // Check if service is ready
29
- isReady() {
30
- return this._ready;
31
- }
32
- // Protected helper methods
33
- _setReady(ready = true) {
34
- this._ready = ready;
35
- this._error = null;
36
- }
37
- _setError(error) {
38
- this._ready = false;
39
- this._error = error;
40
- }
41
- _requireAuth() {
42
- if (!this._context.authToken) {
43
- throw new Error("Authentication required");
44
- }
45
- }
46
- _requireReady() {
47
- if (!this.isReady()) {
48
- throw new Error("Service not initialized");
49
- }
50
- }
51
- };
52
-
53
- // src/services/SocketIOService.js
54
- import * as utils from "@domql/utils";
55
- import { router } from "@symbo.ls/router";
56
-
57
- // src/config/environment.js
58
- import { isDevelopment } from "@domql/utils";
59
- var CONFIG = {
60
- // Common defaults for all environments
61
- common: {
62
- // NOTE: Google client id for google auth, need to configure URLs for each environment in Google console
63
- googleClientId: "686286207466-bvd2fqs31rlm64fgich7rtpnc8ns2tqg.apps.googleusercontent.com",
64
- // Feature toggles that apply across all environments by default
65
- features: {
66
- newUserOnboarding: true,
67
- betaFeatures: false
68
- }
69
- },
70
- // Environment-specific configurations
71
- local: {
72
- // local
73
- baseUrl: "http://localhost:8080",
74
- // For symstory api
75
- socketUrl: "http://localhost:8080",
76
- // For socket api
77
- routerUrl: "http://localhost:8080",
78
- // For router api
79
- apiUrl: "http://localhost:8080",
80
- // For server api
81
- basedEnv: "development",
82
- // For based api
83
- basedProject: "platform-v2-sm",
84
- // For based api
85
- basedOrg: "symbols",
86
- // For based api
87
- githubClientId: "Ov23liHxyWFBxS8f1gnF",
88
- // For github api
89
- // Environment-specific feature toggles (override common)
90
- features: {
91
- betaFeatures: true
92
- // Enable beta features in local dev
93
- }
94
- },
95
- development: {
96
- baseUrl: "https://dev.api.symbols.app",
97
- socketUrl: "https://dev.api.symbols.app",
98
- routerUrl: "https://dev.api.symbols.app",
99
- apiUrl: "https://dev.api.symbols.app",
100
- basedEnv: "development",
101
- basedProject: "platform-v2-sm",
102
- basedOrg: "symbols",
103
- githubClientId: "Ov23liHxyWFBxS8f1gnF"
104
- },
105
- testing: {
106
- baseUrl: "https://test.api.symbols.app",
107
- socketUrl: "https://test.api.symbols.app",
108
- routerUrl: "https://test.api.symbols.app",
109
- apiUrl: "https://test.api.symbols.app",
110
- basedEnv: "testing",
111
- basedProject: "platform-v2-sm",
112
- basedOrg: "symbols",
113
- githubClientId: "Ov23liHxyWFBxS8f1gnF"
114
- },
115
- staging: {
116
- baseUrl: "https://staging.api.symbols.app",
117
- socketUrl: "https://staging.api.symbols.app",
118
- routerUrl: "https://staging.api.symbols.app",
119
- apiUrl: "https://staging.api.symbols.app",
120
- basedEnv: "staging",
121
- basedProject: "platform-v2-sm",
122
- basedOrg: "symbols",
123
- githubClientId: "Ov23ligwZDQVD0VfuWNa"
124
- },
125
- production: {
126
- baseUrl: "https://api.symbols.app",
127
- socketUrl: "https://api.symbols.app",
128
- routerUrl: "https://api.symbols.app",
129
- apiUrl: "https://api.symbols.app",
130
- basedEnv: "production",
131
- basedProject: "platform-v2-sm",
132
- basedOrg: "symbols",
133
- githubClientId: "Ov23liFAlOEIXtX3dBtR"
134
- }
135
- };
136
- var getEnvironment = () => {
137
- const env = process.env.SYMBOLS_APP_ENV || process.env.NODE_ENV;
138
- if (!CONFIG[env]) {
139
- throw new Error(`Unknown environment "${env}"`);
140
- }
141
- return env;
142
- };
143
- var getConfig = () => {
144
- try {
145
- const env = getEnvironment();
146
- const envConfig = { ...CONFIG.common, ...CONFIG[env] };
147
- const finalConfig = {
148
- ...envConfig,
149
- baseUrl: process.env.SYMBOLS_APP_BASE_URL || envConfig.baseUrl,
150
- socketUrl: process.env.SYMBOLS_APP_SOCKET_URL || envConfig.socketUrl,
151
- routerUrl: process.env.SYMBOLS_APP_ROUTER_URL || envConfig.routerUrl,
152
- apiUrl: process.env.SYMBOLS_APP_API_URL || envConfig.apiUrl,
153
- basedEnv: process.env.SYMBOLS_APP_BASED_ENV || envConfig.basedEnv,
154
- basedProject: process.env.SYMBOLS_APP_BASED_PROJECT || envConfig.basedProject,
155
- basedOrg: process.env.SYMBOLS_APP_BASED_ORG || envConfig.basedOrg,
156
- githubClientId: process.env.SYMBOLS_APP_GITHUB_CLIENT_ID || envConfig.githubClientId,
157
- isDevelopment: isDevelopment(env),
158
- isTesting: env === "testing",
159
- isStaging: env === "staging",
160
- isProduction: env === "production"
161
- // Store all environment variables for potential future use
162
- };
163
- const requiredFields = [
164
- "baseUrl",
165
- "socketUrl",
166
- "apiUrl",
167
- "basedEnv",
168
- "basedProject",
169
- "basedOrg",
170
- "githubClientId",
171
- "googleClientId"
172
- ];
173
- const missingFields = requiredFields.filter((field) => !finalConfig[field]);
174
- if (missingFields.length > 0) {
175
- console.error(
176
- `Missing required configuration: ${missingFields.join(", ")}`
177
- );
178
- }
179
- if (finalConfig.isDevelopment) {
180
- console.log(
181
- "environment in SDK:",
182
- env || process.env.NODE_ENV || process.env.NODE_ENV
183
- );
184
- console.log(finalConfig);
185
- }
186
- return finalConfig;
187
- } catch (error) {
188
- console.error("Failed to load environment configuration:", error);
189
- return {
190
- ...CONFIG.development
191
- };
192
- }
193
- };
194
- var environment_default = getConfig();
195
-
196
- // src/services/SocketIOService.js
197
- var { deepStringify, deepDestringify, isString } = utils.default || utils;
198
- var SocketService = class extends BaseService {
199
- constructor(config) {
200
- super(config);
201
- this._socket = null;
202
- this._reconnectAttempts = 0;
203
- this._maxReconnectAttempts = (config == null ? void 0 : config.maxReconnectAttempts) || 5;
204
- this._reconnectDelay = (config == null ? void 0 : config.reconnectDelay) || 1e3;
205
- this._handlers = /* @__PURE__ */ new Map();
206
- this._sessionId = Math.random();
207
- this._ignoreSync = [
208
- "userId",
209
- "username",
210
- "usersName",
211
- "email",
212
- "projects",
213
- "feedbacks",
214
- "userRoles",
215
- "loading",
216
- "appKey",
217
- "projectName",
218
- "followingUser",
219
- "activeProject",
220
- "user",
221
- "sessionId",
222
- "clients"
223
- ];
224
- }
225
- init() {
226
- try {
227
- const { _context, _options } = this;
228
- const socketUrl = environment_default.socketUrl || _options.socketUrl;
229
- if (!socketUrl) {
230
- throw new Error("Socket URL is required");
231
- }
232
- this._info = {
233
- config: {
234
- url: socketUrl,
235
- hasToken: Boolean(_context.authToken),
236
- status: "initializing"
237
- }
238
- };
239
- this._setReady();
240
- } catch (error) {
241
- this._setError(error);
242
- throw error;
243
- }
244
- }
245
- connect() {
246
- var _a, _b, _c, _d, _e, _f, _g;
247
- try {
248
- if (this._socket && ["connected", "connecting"].includes((_b = (_a = this._info) == null ? void 0 : _a.config) == null ? void 0 : _b.status)) {
249
- console.warn(
250
- "Socket connection already exists:",
251
- (_d = (_c = this._info) == null ? void 0 : _c.config) == null ? void 0 : _d.status
252
- );
253
- return true;
254
- }
255
- const { _context } = this;
256
- if (!_context.appKey) {
257
- throw new Error("App key is required");
258
- }
259
- this._updateStatus("connecting");
260
- const config = {
261
- source: "platform",
262
- userId: (_e = _context.user) == null ? void 0 : _e.id,
263
- socketUrl: this._info.config.url,
264
- location: window.location.host,
265
- // onConnect: () => {
266
- // console.log('waz')
267
- // },
268
- onChange: this._handleMessage.bind(this),
269
- sessionId: this._sessionId,
270
- usersName: (_f = _context.user) == null ? void 0 : _f.name,
271
- route: window.location.pathname,
272
- onDisconnect: this._handleDisconnect.bind(this)
273
- };
274
- if (this._socket) {
275
- this.destroy();
276
- }
277
- this._socket = connect(_context.appKey, config);
278
- this._updateStatus("connected");
279
- if (environment_default.isDevelopment) {
280
- console.log("Socket connection established:", {
281
- appKey: _context.appKey,
282
- userId: (_g = _context.user) == null ? void 0 : _g.id,
283
- sessionId: this._sessionId,
284
- url: this._info.config.url
285
- });
286
- }
287
- return true;
288
- } catch (error) {
289
- this._updateStatus("failed");
290
- console.error("Socket connection failed:", error);
291
- throw new Error(`Socket connection failed: ${error.message}`);
292
- }
293
- }
294
- send(type, data, opts = {}) {
295
- var _a, _b;
296
- this._requireReady();
297
- if (!this._socket) {
298
- throw new Error("Socket is not connected");
299
- }
300
- const payload = {
301
- sessionId: this._sessionId,
302
- userId: (_a = this._context.user) == null ? void 0 : _a.id,
303
- usersName: (_b = this._context.user) == null ? void 0 : _b.name,
304
- ...data
305
- };
306
- send.call(
307
- this._socket,
308
- type,
309
- opts.useDeepStringify ? deepStringify(payload) : payload
310
- );
311
- }
312
- _handleMessage(event, data) {
313
- try {
314
- const d = isString(data) ? deepDestringify(JSON.parse(data)) : data;
315
- if (this._sessionId === d.sessionId) {
316
- return;
317
- }
318
- const handlers = this._handlers.get(event);
319
- if (handlers) {
320
- handlers.forEach((handler) => handler(d));
321
- }
322
- switch (event) {
323
- case "change":
324
- this._handleChangeEvent(d);
325
- break;
326
- case "clients":
327
- this._handleClientsEvent(d);
328
- break;
329
- case "route":
330
- this._handleRouteEvent(d);
331
- break;
332
- default:
333
- break;
334
- }
335
- } catch (error) {
336
- this._setError(new Error(`Failed to handle message: ${error.message}`));
337
- }
338
- }
339
- _handleChangeEvent(data) {
340
- const { type, changes, version } = data;
341
- if (version) this._context.state.version = version;
342
- if (changes) {
343
- window.requestAnimationFrame(async () => {
344
- await this._context.state.setPathCollection(changes, {
345
- preventReplace: type === "canvas",
346
- preventUpdate: true,
347
- fromSocket: true,
348
- userId: data.userId,
349
- changes
350
- });
351
- });
352
- }
353
- }
354
- _handleClientsEvent(data) {
355
- const { root } = this._context.state;
356
- root.replace(
357
- { clients: data },
358
- {
359
- fromSocket: true,
360
- preventUpdate: true
361
- }
362
- );
363
- }
364
- _handleRouteEvent(data) {
365
- const { element } = this._context;
366
- const { state } = this._context;
367
- if (data.userId && data.type === "routeChanged") {
368
- const isModalOpen = this.getWindow("modal");
369
- const isFollowing = state.followingUser === data.userId;
370
- const isRouteSyncEnabled = element.getUserSettings("presentMode") && data.userId === state.userId;
371
- if ((isFollowing || isRouteSyncEnabled) && !isModalOpen) {
372
- router(
373
- data.route,
374
- element.__ref.root,
375
- {},
376
- {
377
- fromSocket: true,
378
- updateStateOptions: {
379
- fromSocket: true,
380
- preventStateUpdateListener: 1
381
- // !isModalRoute(data.route, element)
382
- }
383
- }
384
- );
385
- }
386
- } else if (data.reload) {
387
- window.location.reload();
388
- } else if (data.route && data.type === "routeForced") {
389
- router(
390
- data.route,
391
- element.__ref.root,
392
- {},
393
- {
394
- fromSocket: true,
395
- updateStateOptions: {
396
- fromSocket: true
397
- }
398
- }
399
- );
400
- } else if (data.componentKey) {
401
- if (!element.getData("components")[data.componentKey]) {
402
- return;
403
- }
404
- element.activateSelected(data.componentKey);
405
- }
406
- }
407
- _handleDisconnect() {
408
- this._updateStatus("disconnected");
409
- this._handleReconnect();
410
- }
411
- _handleReconnect() {
412
- if (this._reconnectAttempts < this._maxReconnectAttempts) {
413
- this._reconnectAttempts++;
414
- this._updateStatus("reconnecting");
415
- setTimeout(() => {
416
- try {
417
- const connected = this.connect();
418
- if (connected) {
419
- this._reconnectAttempts = 0;
420
- } else {
421
- this._handleReconnect();
422
- }
423
- } catch (error) {
424
- console.error("Reconnection failed:", error);
425
- this._handleReconnect();
426
- }
427
- }, this._reconnectDelay * this._reconnectAttempts);
428
- } else {
429
- this._updateStatus("failed");
430
- this._setError(new Error("Max reconnection attempts reached"));
431
- }
432
- }
433
- _updateStatus(status) {
434
- this._info = {
435
- ...this._info,
436
- config: {
437
- ...this._info.config,
438
- status
439
- }
440
- };
441
- }
442
- destroy() {
443
- if (this._socket) {
444
- disconnect.call(this._socket);
445
- this._socket = null;
446
- }
447
- this._handlers.clear();
448
- this._setReady(false);
449
- }
450
- reconnect() {
451
- this.destroy();
452
- this.connect();
453
- }
454
- _checkRequiredContext() {
455
- var _a, _b;
456
- return Boolean(
457
- ((_a = this._context) == null ? void 0 : _a.appKey) && ((_b = this._context) == null ? void 0 : _b.authToken) && this._socket
458
- );
459
- }
460
- isReady() {
461
- if (this._checkRequiredContext()) {
462
- this._setReady(true);
463
- }
464
- return this._ready;
465
- }
466
- };
467
- export {
468
- SocketService
469
- };
470
- // @preserve-env
@@ -1,191 +0,0 @@
1
- // src/services/BaseService.js
2
- var BaseService = class {
3
- constructor({ context, options } = {}) {
4
- this._context = context || {};
5
- this._options = options || {};
6
- this._ready = false;
7
- this._error = null;
8
- }
9
- // Initialize service
10
- init() {
11
- throw new Error("init() must be implemented by service");
12
- }
13
- // Update context
14
- updateContext(context) {
15
- this._context = { ...this._context, ...context };
16
- }
17
- // Get service status
18
- getStatus() {
19
- return {
20
- ready: this._ready,
21
- error: this._error,
22
- context: { ...this._context }
23
- };
24
- }
25
- // Check if service is ready
26
- isReady() {
27
- return this._ready;
28
- }
29
- // Protected helper methods
30
- _setReady(ready = true) {
31
- this._ready = ready;
32
- this._error = null;
33
- }
34
- _setError(error) {
35
- this._ready = false;
36
- this._error = error;
37
- }
38
- _requireAuth() {
39
- if (!this._context.authToken) {
40
- throw new Error("Authentication required");
41
- }
42
- }
43
- _requireReady() {
44
- if (!this.isReady()) {
45
- throw new Error("Service not initialized");
46
- }
47
- }
48
- };
49
-
50
- // src/services/SocketService.js
51
- var SocketService = class extends BaseService {
52
- constructor(config) {
53
- super(config);
54
- this._socket = null;
55
- this._reconnectAttempts = 0;
56
- this._maxReconnectAttempts = (config == null ? void 0 : config.maxReconnectAttempts) || 5;
57
- this._reconnectDelay = (config == null ? void 0 : config.reconnectDelay) || 1e3;
58
- this._handlers = /* @__PURE__ */ new Map();
59
- }
60
- async init({ context, options }) {
61
- try {
62
- this._context = context;
63
- this._options = options;
64
- const { authToken } = context;
65
- const { socketUrl } = context.socket || {};
66
- if (!socketUrl) {
67
- throw new Error("Socket URL is required");
68
- }
69
- this._info = {
70
- config: {
71
- url: socketUrl,
72
- hasToken: Boolean(authToken),
73
- status: "initializing"
74
- }
75
- };
76
- await this.connect();
77
- this._setReady();
78
- } catch (error) {
79
- this._setError(error);
80
- throw error;
81
- }
82
- }
83
- connect() {
84
- try {
85
- const { socketUrl, authToken } = this._context.socket || {};
86
- this._socket = new window.WebSocket(socketUrl);
87
- this._socket.onopen = () => {
88
- this._reconnectAttempts = 0;
89
- this._updateStatus("connected");
90
- if (authToken) {
91
- this.send("auth", { token: authToken });
92
- }
93
- };
94
- this._socket.onclose = () => {
95
- this._updateStatus("disconnected");
96
- this._handleReconnect();
97
- };
98
- this._socket.onerror = (error) => {
99
- this._updateStatus("error");
100
- this._setError(error);
101
- };
102
- this._socket.onmessage = (event) => {
103
- this._handleMessage(event.data);
104
- };
105
- } catch (error) {
106
- throw new Error(`Socket connection failed: ${error.message}`);
107
- }
108
- }
109
- // Send message to socket server
110
- send(type, data) {
111
- this._requireReady();
112
- if (!this._socket || this._socket.readyState !== window.WebSocket.OPEN) {
113
- throw new Error("Socket is not connected");
114
- }
115
- this._socket.send(JSON.stringify({ type, data }));
116
- }
117
- // Subscribe to socket events
118
- subscribe(type, handler) {
119
- if (!this._handlers.has(type)) {
120
- this._handlers.set(type, /* @__PURE__ */ new Set());
121
- }
122
- this._handlers.get(type).add(handler);
123
- return () => {
124
- const handlers = this._handlers.get(type);
125
- if (handlers) {
126
- handlers.delete(handler);
127
- if (handlers.size === 0) {
128
- this._handlers.delete(type);
129
- }
130
- }
131
- };
132
- }
133
- subscribeChannel(type, handler) {
134
- return this.subscribe(type, handler);
135
- }
136
- // Private methods
137
- _handleMessage(rawData) {
138
- try {
139
- const { type, data } = JSON.parse(rawData);
140
- const handlers = this._handlers.get(type);
141
- if (handlers) {
142
- handlers.forEach((handler) => handler(data));
143
- }
144
- } catch (error) {
145
- this._setError(new Error(`Failed to handle message: ${error.message}`));
146
- }
147
- }
148
- _handleReconnect() {
149
- if (this._reconnectAttempts < this._maxReconnectAttempts) {
150
- this._reconnectAttempts++;
151
- this._updateStatus("reconnecting");
152
- setTimeout(() => {
153
- this.connect();
154
- }, this._reconnectDelay * this._reconnectAttempts);
155
- } else {
156
- this._updateStatus("failed");
157
- this._setError(new Error("Max reconnection attempts reached"));
158
- }
159
- }
160
- _updateStatus(status) {
161
- this._info = {
162
- ...this._info,
163
- config: {
164
- ...this._info.config,
165
- status
166
- }
167
- };
168
- }
169
- // Cleanup
170
- destroy() {
171
- if (this._socket) {
172
- this._socket.close();
173
- this._socket = null;
174
- }
175
- this._handlers.clear();
176
- this._setReady(false);
177
- }
178
- _checkRequiredContext() {
179
- const { socket } = this._context;
180
- return Boolean((socket == null ? void 0 : socket.socketUrl) && this._socket);
181
- }
182
- isReady() {
183
- if (this._checkRequiredContext()) {
184
- this._setReady(true);
185
- }
186
- return this._ready;
187
- }
188
- };
189
- export {
190
- SocketService
191
- };