@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,129 @@
|
|
|
1
|
+
import { BaseService } from "./BaseService.js";
|
|
2
|
+
class WaitlistService extends BaseService {
|
|
3
|
+
// ==================== WAITLIST METHODS ====================
|
|
4
|
+
/**
|
|
5
|
+
* Join a waitlist campaign (public).
|
|
6
|
+
*
|
|
7
|
+
* Mirrors: POST /waitlist (WaitlistController.join)
|
|
8
|
+
*/
|
|
9
|
+
async joinWaitlist(data = {}) {
|
|
10
|
+
this._requireReady("joinWaitlist");
|
|
11
|
+
if (!data || typeof data !== "object") {
|
|
12
|
+
throw new Error("Waitlist join payload is required");
|
|
13
|
+
}
|
|
14
|
+
if (!data.email) {
|
|
15
|
+
throw new Error("Email is required");
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
const response = await this._request("/waitlist", {
|
|
19
|
+
method: "POST",
|
|
20
|
+
body: JSON.stringify(data),
|
|
21
|
+
methodName: "joinWaitlist"
|
|
22
|
+
});
|
|
23
|
+
if (response.success) {
|
|
24
|
+
return response.data;
|
|
25
|
+
}
|
|
26
|
+
throw new Error(response.message);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
throw new Error(`Failed to join waitlist: ${error.message}`, { cause: error });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* List waitlist entries (admin).
|
|
33
|
+
*
|
|
34
|
+
* Mirrors: GET /waitlist (WaitlistController.list)
|
|
35
|
+
*/
|
|
36
|
+
async listWaitlistEntries(options = {}) {
|
|
37
|
+
this._requireReady("listWaitlistEntries");
|
|
38
|
+
const {
|
|
39
|
+
campaignKey,
|
|
40
|
+
status,
|
|
41
|
+
search,
|
|
42
|
+
page,
|
|
43
|
+
limit
|
|
44
|
+
} = options || {};
|
|
45
|
+
const queryParams = new URLSearchParams();
|
|
46
|
+
if (campaignKey != null) {
|
|
47
|
+
queryParams.append("campaignKey", String(campaignKey));
|
|
48
|
+
}
|
|
49
|
+
if (status != null) {
|
|
50
|
+
queryParams.append("status", String(status));
|
|
51
|
+
}
|
|
52
|
+
if (search != null) {
|
|
53
|
+
queryParams.append("search", String(search));
|
|
54
|
+
}
|
|
55
|
+
if (page != null) {
|
|
56
|
+
queryParams.append("page", String(page));
|
|
57
|
+
}
|
|
58
|
+
if (limit != null) {
|
|
59
|
+
queryParams.append("limit", String(limit));
|
|
60
|
+
}
|
|
61
|
+
const queryString = queryParams.toString();
|
|
62
|
+
const url = `/waitlist${queryString ? `?${queryString}` : ""}`;
|
|
63
|
+
try {
|
|
64
|
+
const response = await this._request(url, {
|
|
65
|
+
method: "GET",
|
|
66
|
+
methodName: "listWaitlistEntries"
|
|
67
|
+
});
|
|
68
|
+
if (response.success) {
|
|
69
|
+
return response.data;
|
|
70
|
+
}
|
|
71
|
+
throw new Error(response.message);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
throw new Error(`Failed to list waitlist entries: ${error.message}`, { cause: error });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Update a waitlist entry (admin).
|
|
78
|
+
*
|
|
79
|
+
* Mirrors: PATCH /waitlist/:id (WaitlistController.update)
|
|
80
|
+
*/
|
|
81
|
+
async updateWaitlistEntry(id, update = {}) {
|
|
82
|
+
this._requireReady("updateWaitlistEntry");
|
|
83
|
+
if (!id) {
|
|
84
|
+
throw new Error("Waitlist entry ID is required");
|
|
85
|
+
}
|
|
86
|
+
if (!update || typeof update !== "object") {
|
|
87
|
+
throw new Error("Update payload is required");
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const response = await this._request(`/waitlist/${id}`, {
|
|
91
|
+
method: "PATCH",
|
|
92
|
+
body: JSON.stringify(update),
|
|
93
|
+
methodName: "updateWaitlistEntry"
|
|
94
|
+
});
|
|
95
|
+
if (response.success) {
|
|
96
|
+
return response.data;
|
|
97
|
+
}
|
|
98
|
+
throw new Error(response.message);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
throw new Error(`Failed to update waitlist entry: ${error.message}`, { cause: error });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Send an invitation email for a waitlist entry (admin).
|
|
105
|
+
*
|
|
106
|
+
* Mirrors: POST /waitlist/:id/invite (WaitlistController.invite)
|
|
107
|
+
*/
|
|
108
|
+
async inviteWaitlistEntry(id) {
|
|
109
|
+
this._requireReady("inviteWaitlistEntry");
|
|
110
|
+
if (!id) {
|
|
111
|
+
throw new Error("Waitlist entry ID is required");
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const response = await this._request(`/waitlist/${id}/invite`, {
|
|
115
|
+
method: "POST",
|
|
116
|
+
methodName: "inviteWaitlistEntry"
|
|
117
|
+
});
|
|
118
|
+
if (response.success) {
|
|
119
|
+
return response.data;
|
|
120
|
+
}
|
|
121
|
+
throw new Error(response.message);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
throw new Error(`Failed to invite waitlist entry: ${error.message}`, { cause: error });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export {
|
|
128
|
+
WaitlistService
|
|
129
|
+
};
|
|
@@ -1,15 +1,71 @@
|
|
|
1
1
|
import { AuthService } from "./AuthService.js";
|
|
2
|
-
import { CoreService } from "./CoreService.js";
|
|
3
2
|
import { CollabService } from "./CollabService.js";
|
|
3
|
+
import { ProjectService } from "./ProjectService.js";
|
|
4
|
+
import { PlanService } from "./PlanService.js";
|
|
5
|
+
import { SubscriptionService } from "./SubscriptionService.js";
|
|
6
|
+
import { FileService } from "./FileService.js";
|
|
7
|
+
import { PaymentService } from "./PaymentService.js";
|
|
8
|
+
import { DnsService } from "./DnsService.js";
|
|
9
|
+
import { BranchService } from "./BranchService.js";
|
|
10
|
+
import { PullRequestService } from "./PullRequestService.js";
|
|
11
|
+
import { AdminService } from "./AdminService.js";
|
|
12
|
+
import { ScreenshotService } from "./ScreenshotService.js";
|
|
13
|
+
import { TrackingService } from "./TrackingService.js";
|
|
14
|
+
import { WaitlistService } from "./WaitlistService.js";
|
|
15
|
+
import { MetricsService } from "./MetricsService.js";
|
|
16
|
+
import { IntegrationService } from "./IntegrationService.js";
|
|
17
|
+
import { FeatureFlagService } from "./FeatureFlagService.js";
|
|
4
18
|
const createService = (ServiceClass, config) => new ServiceClass(config);
|
|
5
19
|
const createAuthService = (config) => createService(AuthService, config);
|
|
6
|
-
const createCoreService = (config) => createService(CoreService, config);
|
|
7
20
|
const createCollabService = (config) => createService(CollabService, config);
|
|
21
|
+
const createProjectService = (config) => createService(ProjectService, config);
|
|
22
|
+
const createPlanService = (config) => createService(PlanService, config);
|
|
23
|
+
const createSubscriptionService = (config) => createService(SubscriptionService, config);
|
|
24
|
+
const createFileService = (config) => createService(FileService, config);
|
|
25
|
+
const createPaymentService = (config) => createService(PaymentService, config);
|
|
26
|
+
const createDnsService = (config) => createService(DnsService, config);
|
|
27
|
+
const createBranchService = (config) => createService(BranchService, config);
|
|
28
|
+
const createPullRequestService = (config) => createService(PullRequestService, config);
|
|
29
|
+
const createAdminService = (config) => createService(AdminService, config);
|
|
30
|
+
const createScreenshotService = (config) => createService(ScreenshotService, config);
|
|
31
|
+
const createTrackingService = (config) => createService(TrackingService, config);
|
|
32
|
+
const createWaitlistService = (config) => createService(WaitlistService, config);
|
|
33
|
+
const createMetricsService = (config) => createService(MetricsService, config);
|
|
34
|
+
const createIntegrationService = (config) => createService(IntegrationService, config);
|
|
35
|
+
const createFeatureFlagService = (config) => createService(FeatureFlagService, config);
|
|
8
36
|
export {
|
|
37
|
+
AdminService,
|
|
9
38
|
AuthService,
|
|
39
|
+
BranchService,
|
|
10
40
|
CollabService,
|
|
11
|
-
|
|
41
|
+
DnsService,
|
|
42
|
+
FeatureFlagService,
|
|
43
|
+
FileService,
|
|
44
|
+
IntegrationService,
|
|
45
|
+
MetricsService,
|
|
46
|
+
PaymentService,
|
|
47
|
+
PlanService,
|
|
48
|
+
ProjectService,
|
|
49
|
+
PullRequestService,
|
|
50
|
+
ScreenshotService,
|
|
51
|
+
SubscriptionService,
|
|
52
|
+
TrackingService,
|
|
53
|
+
WaitlistService,
|
|
54
|
+
createAdminService,
|
|
12
55
|
createAuthService,
|
|
56
|
+
createBranchService,
|
|
13
57
|
createCollabService,
|
|
14
|
-
|
|
58
|
+
createDnsService,
|
|
59
|
+
createFeatureFlagService,
|
|
60
|
+
createFileService,
|
|
61
|
+
createIntegrationService,
|
|
62
|
+
createMetricsService,
|
|
63
|
+
createPaymentService,
|
|
64
|
+
createPlanService,
|
|
65
|
+
createProjectService,
|
|
66
|
+
createPullRequestService,
|
|
67
|
+
createScreenshotService,
|
|
68
|
+
createSubscriptionService,
|
|
69
|
+
createTrackingService,
|
|
70
|
+
createWaitlistService
|
|
15
71
|
};
|
|
@@ -12,35 +12,14 @@ class RootStateManager {
|
|
|
12
12
|
* @param {Array} changes – eg. ['update', ['foo'], 'bar']
|
|
13
13
|
* @param {Object} opts – forwarded to setPathCollection
|
|
14
14
|
*/
|
|
15
|
-
applyChanges(changes = [], opts = {}) {
|
|
15
|
+
async applyChanges(changes = [], opts = {}) {
|
|
16
16
|
if (!this._rootState || !isFunction(this._rootState.setPathCollection)) {
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
|
-
const result = this._rootState.setPathCollection(changes, {
|
|
19
|
+
const result = await this._rootState.setPathCollection(changes, {
|
|
20
20
|
preventUpdate: true,
|
|
21
21
|
...opts
|
|
22
22
|
});
|
|
23
|
-
try {
|
|
24
|
-
const changedKeys = /* @__PURE__ */ new Set();
|
|
25
|
-
changes.forEach((tuple) => {
|
|
26
|
-
const [, path = []] = tuple;
|
|
27
|
-
if (!Array.isArray(path) || !path.length) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (path[0] === "components" && typeof path[1] === "string") {
|
|
31
|
-
changedKeys.add(path[1]);
|
|
32
|
-
}
|
|
33
|
-
if (path[0] === "schema" && path[1] === "components" && typeof path[2] === "string") {
|
|
34
|
-
changedKeys.add(path[2]);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
if (changedKeys.size) {
|
|
38
|
-
console.log("emit components:changed", [...changedKeys]);
|
|
39
|
-
rootBus.emit("components:changed", [...changedKeys]);
|
|
40
|
-
}
|
|
41
|
-
} catch (err) {
|
|
42
|
-
console.error("[RootStateManager] emit components:changed failed", err);
|
|
43
|
-
}
|
|
44
23
|
return result;
|
|
45
24
|
}
|
|
46
25
|
setVersion(v) {
|
|
@@ -3,9 +3,17 @@ const getGlobalBus = () => {
|
|
|
3
3
|
return globalThis.__SMBLS_ROOT_BUS__;
|
|
4
4
|
}
|
|
5
5
|
const events = {};
|
|
6
|
+
const lastPayloads = {};
|
|
6
7
|
const bus = {
|
|
7
8
|
on(event, handler) {
|
|
8
9
|
(events[event] ||= []).push(handler);
|
|
10
|
+
if (Object.hasOwn(lastPayloads, event)) {
|
|
11
|
+
try {
|
|
12
|
+
handler(lastPayloads[event]);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error("[rootBus] handler error for (replay)", event, err);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
9
17
|
},
|
|
10
18
|
off(event, handler) {
|
|
11
19
|
const list = events[event];
|
|
@@ -18,6 +26,7 @@ const getGlobalBus = () => {
|
|
|
18
26
|
}
|
|
19
27
|
},
|
|
20
28
|
emit(event, payload) {
|
|
29
|
+
lastPayloads[event] = payload;
|
|
21
30
|
const list = events[event];
|
|
22
31
|
if (!list || !list.length) {
|
|
23
32
|
return;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { io } from "socket.io-client";
|
|
2
2
|
import * as Y from "yjs";
|
|
3
|
-
import { IndexeddbPersistence } from "y-indexeddb";
|
|
4
|
-
import Dexie from "dexie";
|
|
5
3
|
import { nanoid } from "nanoid";
|
|
6
4
|
import environment from "../config/environment.js";
|
|
7
5
|
import { diffJson, applyOpsToJson } from "./jsonDiff.js";
|
|
@@ -17,15 +15,30 @@ class CollabClient {
|
|
|
17
15
|
_buffer = [];
|
|
18
16
|
_flushTimer = null;
|
|
19
17
|
_clientId = nanoid();
|
|
20
|
-
_outboxStore =
|
|
21
|
-
// Dexie table
|
|
18
|
+
_outboxStore = createMemoryOutbox();
|
|
19
|
+
// Dexie table fallback
|
|
22
20
|
_readyResolve;
|
|
23
21
|
ready = new Promise((res) => this._readyResolve = res);
|
|
24
22
|
constructor({ jwt, projectId, branch = "main", live = false }) {
|
|
25
23
|
Object.assign(this, { jwt, projectId, branch, live });
|
|
26
24
|
this.ydoc = new Y.Doc();
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const hasIndexedDB = typeof globalThis.indexedDB !== "undefined";
|
|
26
|
+
if (typeof window === "undefined" || !hasIndexedDB) {
|
|
27
|
+
console.log("[CollabClient] IndexedDB not available \u2013 skipping offline persistence");
|
|
28
|
+
} else {
|
|
29
|
+
import("y-indexeddb").then(({ IndexeddbPersistence }) => {
|
|
30
|
+
new IndexeddbPersistence(`${projectId}:${branch}`, this.ydoc);
|
|
31
|
+
}).catch((err) => {
|
|
32
|
+
console.warn("[CollabClient] Failed to load IndexeddbPersistence:", err);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (typeof window !== "undefined" && hasIndexedDB) {
|
|
36
|
+
createDexieOutbox(`${projectId}:${branch}`).then((outboxStore) => {
|
|
37
|
+
this._outboxStore = outboxStore;
|
|
38
|
+
}).catch((err) => {
|
|
39
|
+
console.warn("[CollabClient] Failed to load Dexie:", err);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
29
42
|
this.socket = io(environment.socketUrl, {
|
|
30
43
|
path: "/collab-socket",
|
|
31
44
|
transports: ["websocket"],
|
|
@@ -33,9 +46,7 @@ class CollabClient {
|
|
|
33
46
|
reconnectionAttempts: Infinity,
|
|
34
47
|
reconnectionDelayMax: 4e3
|
|
35
48
|
});
|
|
36
|
-
this.socket.on("snapshot", this._onSnapshot).on("ops", this._onOps).on("commit", this._onCommit).on("liveMode", (
|
|
37
|
-
this.live = flag;
|
|
38
|
-
}).on("connect", this._onConnect).on("error", (e) => console.warn("[collab] socket error", e));
|
|
49
|
+
this.socket.on("snapshot", this._onSnapshot).on("ops", this._onOps).on("commit", this._onCommit).on("liveMode", this._onLiveMode).on("connect", this._onConnect).on("error", this._onError);
|
|
39
50
|
this._prevJson = this.ydoc.getMap("root").toJSON();
|
|
40
51
|
this.ydoc.on("afterTransaction", (tr) => {
|
|
41
52
|
if (tr.origin === "remote") {
|
|
@@ -65,7 +76,11 @@ class CollabClient {
|
|
|
65
76
|
data
|
|
66
77
|
/* Uint8Array */
|
|
67
78
|
}) => {
|
|
68
|
-
|
|
79
|
+
if (Array.isArray(data) ? data.length : data && data.byteLength) {
|
|
80
|
+
Y.applyUpdate(this.ydoc, Uint8Array.from(data));
|
|
81
|
+
} else {
|
|
82
|
+
console.warn("[collab] Received empty snapshot \u2013 skipping applyUpdate");
|
|
83
|
+
}
|
|
69
84
|
this._prevJson = this.ydoc.getMap("root").toJSON();
|
|
70
85
|
if (typeof this._readyResolve === "function") {
|
|
71
86
|
this._readyResolve();
|
|
@@ -117,8 +132,59 @@ class CollabClient {
|
|
|
117
132
|
});
|
|
118
133
|
this._buffer.length = 0;
|
|
119
134
|
}
|
|
135
|
+
dispose() {
|
|
136
|
+
var _a;
|
|
137
|
+
clearTimeout(this._flushTimer);
|
|
138
|
+
this._flushTimer = null;
|
|
139
|
+
this._buffer.length = 0;
|
|
140
|
+
if ((_a = this._outboxStore) == null ? void 0 : _a.clear) {
|
|
141
|
+
try {
|
|
142
|
+
const result = this._outboxStore.clear();
|
|
143
|
+
if (result && typeof result.catch === "function") {
|
|
144
|
+
result.catch(() => {
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
} catch (error) {
|
|
148
|
+
console.warn("[CollabClient] Failed to clear outbox store during dispose:", error);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (this.socket) {
|
|
152
|
+
this.socket.off("snapshot", this._onSnapshot);
|
|
153
|
+
this.socket.off("ops", this._onOps);
|
|
154
|
+
this.socket.off("commit", this._onCommit);
|
|
155
|
+
this.socket.off("liveMode", this._onLiveMode);
|
|
156
|
+
this.socket.off("connect", this._onConnect);
|
|
157
|
+
this.socket.off("error", this._onError);
|
|
158
|
+
this.socket.removeAllListeners();
|
|
159
|
+
this.socket.disconnect();
|
|
160
|
+
this.socket = null;
|
|
161
|
+
}
|
|
162
|
+
if (this.ydoc) {
|
|
163
|
+
this.ydoc.destroy();
|
|
164
|
+
this.ydoc = null;
|
|
165
|
+
}
|
|
166
|
+
if (typeof this._readyResolve === "function") {
|
|
167
|
+
this._readyResolve();
|
|
168
|
+
this._readyResolve = null;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
_onLiveMode = (flag) => {
|
|
172
|
+
this.live = flag;
|
|
173
|
+
};
|
|
174
|
+
_onError = (e) => {
|
|
175
|
+
console.warn("[collab] socket error", e);
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function createMemoryOutbox() {
|
|
179
|
+
const store = /* @__PURE__ */ new Map();
|
|
180
|
+
return {
|
|
181
|
+
put: (item) => store.set(item.id, item),
|
|
182
|
+
toArray: () => Array.from(store.values()),
|
|
183
|
+
clear: () => store.clear()
|
|
184
|
+
};
|
|
120
185
|
}
|
|
121
|
-
function createDexieOutbox(name) {
|
|
186
|
+
async function createDexieOutbox(name) {
|
|
187
|
+
const { default: Dexie } = await import("dexie");
|
|
122
188
|
const db = new Dexie(`collab-${name}`);
|
|
123
189
|
db.version(1).stores({ outbox: "id, ops" });
|
|
124
190
|
return db.table("outbox");
|
|
@@ -2,7 +2,7 @@ class TokenManager {
|
|
|
2
2
|
constructor(options = {}) {
|
|
3
3
|
this.config = {
|
|
4
4
|
storagePrefix: "symbols_",
|
|
5
|
-
storageType: "localStorage",
|
|
5
|
+
storageType: typeof window === "undefined" || process.env.NODE_ENV === "test" || process.env.NODE_ENV === "testing" ? "memory" : "localStorage",
|
|
6
6
|
// 'localStorage' | 'sessionStorage' | 'memory'
|
|
7
7
|
refreshBuffer: 60 * 1e3,
|
|
8
8
|
// Refresh 1 minute before expiry
|
|
@@ -42,13 +42,26 @@ class TokenManager {
|
|
|
42
42
|
if (typeof window === "undefined") {
|
|
43
43
|
return this._memoryStorage;
|
|
44
44
|
}
|
|
45
|
+
const safeGetStorage = (provider) => {
|
|
46
|
+
try {
|
|
47
|
+
const storage = provider();
|
|
48
|
+
const testKey = `${this.config.storagePrefix}__tm_test__`;
|
|
49
|
+
storage.setItem(testKey, "1");
|
|
50
|
+
storage.removeItem(testKey);
|
|
51
|
+
return storage;
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const localStorageInstance = safeGetStorage(() => window.localStorage);
|
|
57
|
+
const sessionStorageInstance = safeGetStorage(() => window.sessionStorage);
|
|
45
58
|
switch (this.config.storageType) {
|
|
46
59
|
case "sessionStorage":
|
|
47
|
-
return
|
|
60
|
+
return sessionStorageInstance || this._memoryStorage;
|
|
48
61
|
case "memory":
|
|
49
62
|
return this._memoryStorage;
|
|
50
63
|
default:
|
|
51
|
-
return
|
|
64
|
+
return localStorageInstance || this._memoryStorage;
|
|
52
65
|
}
|
|
53
66
|
}
|
|
54
67
|
/**
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { diffJson } from "./jsonDiff.js";
|
|
2
|
+
import { computeOrdersForTuples } from "./ordering.js";
|
|
3
|
+
function isPlainObject(val) {
|
|
4
|
+
return val && typeof val === "object" && !Array.isArray(val);
|
|
5
|
+
}
|
|
6
|
+
function getByPathSafe(root, path) {
|
|
7
|
+
if (!root || typeof root.getByPath !== "function") {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
return root.getByPath(path);
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function resolveNextValueFromTuples(tuples, path) {
|
|
17
|
+
if (!Array.isArray(tuples) || !Array.isArray(path)) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
for (let i = tuples.length - 1; i >= 0; i--) {
|
|
21
|
+
const t = tuples[i];
|
|
22
|
+
if (!Array.isArray(t) || t.length < 3) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
const [action, tuplePath, tupleValue] = t;
|
|
26
|
+
if (action !== "update" && action !== "set" || !Array.isArray(tuplePath)) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (tuplePath.length > path.length) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
let isPrefix = true;
|
|
33
|
+
for (let j = 0; j < tuplePath.length; j++) {
|
|
34
|
+
if (tuplePath[j] !== path[j]) {
|
|
35
|
+
isPrefix = false;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (!isPrefix) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (tuplePath.length === path.length) {
|
|
43
|
+
return tupleValue;
|
|
44
|
+
}
|
|
45
|
+
let current = tupleValue;
|
|
46
|
+
for (let j = tuplePath.length; j < path.length; j++) {
|
|
47
|
+
if (current == null) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
current = current[path[j]];
|
|
51
|
+
}
|
|
52
|
+
if (current !== null) {
|
|
53
|
+
return current;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
function preprocessChanges(root, tuples = [], options = {}) {
|
|
59
|
+
const expandTuple = (t) => {
|
|
60
|
+
const [action, path, value] = t || [];
|
|
61
|
+
const isSchemaPath = Array.isArray(path) && path[0] === "schema";
|
|
62
|
+
const isFilesPath = Array.isArray(path) && path[0] === "files";
|
|
63
|
+
if (action === "delete") {
|
|
64
|
+
return [t];
|
|
65
|
+
}
|
|
66
|
+
const canConsiderExpansion = action === "update" && Array.isArray(path) && (path.length === 1 || path.length === 2 || isSchemaPath && path.length === 3) && isPlainObject(value);
|
|
67
|
+
if (!canConsiderExpansion || isFilesPath || value && value.type === "files") {
|
|
68
|
+
return [t];
|
|
69
|
+
}
|
|
70
|
+
const prevRaw = getByPathSafe(root, path);
|
|
71
|
+
const isCreatePath = Array.isArray(path) && action === "update" && // e.g. ['update', ['components', 'NewKey'], {...}]
|
|
72
|
+
(!isSchemaPath && path.length === 2 || // e.g. ['update', ['schema', 'components', 'NewKey'], {...}]
|
|
73
|
+
isSchemaPath && path.length === 3) && (prevRaw === null || typeof prevRaw === "undefined");
|
|
74
|
+
if (isCreatePath) {
|
|
75
|
+
return [t];
|
|
76
|
+
}
|
|
77
|
+
const prev = prevRaw || {};
|
|
78
|
+
const next = value || {};
|
|
79
|
+
if (!isPlainObject(prev) || !isPlainObject(next)) {
|
|
80
|
+
return [t];
|
|
81
|
+
}
|
|
82
|
+
const ops = diffJson(prev, next, []);
|
|
83
|
+
if (!ops.length) {
|
|
84
|
+
return [t];
|
|
85
|
+
}
|
|
86
|
+
const out = [];
|
|
87
|
+
for (let i = 0; i < ops.length; i++) {
|
|
88
|
+
const op = ops[i];
|
|
89
|
+
const fullPath = [...path, ...op.path];
|
|
90
|
+
const last = fullPath[fullPath.length - 1];
|
|
91
|
+
if (op.action === "set") {
|
|
92
|
+
out.push(["update", fullPath, op.value]);
|
|
93
|
+
} else if (op.action === "del") {
|
|
94
|
+
if (last !== "__order") {
|
|
95
|
+
out.push(["delete", fullPath]);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
};
|
|
101
|
+
const minimizeTuples = (input) => {
|
|
102
|
+
const out = [];
|
|
103
|
+
const seen2 = /* @__PURE__ */ new Set();
|
|
104
|
+
for (let i = 0; i < input.length; i++) {
|
|
105
|
+
const expanded = expandTuple(input[i]);
|
|
106
|
+
for (let k = 0; k < expanded.length; k++) {
|
|
107
|
+
const tuple = expanded[k];
|
|
108
|
+
const isDelete = Array.isArray(tuple) && tuple[0] === "delete";
|
|
109
|
+
const isOrderKey = isDelete && Array.isArray(tuple[1]) && tuple[1][tuple[1].length - 1] === "__order";
|
|
110
|
+
if (!isOrderKey) {
|
|
111
|
+
const key = JSON.stringify(tuple);
|
|
112
|
+
if (!seen2.has(key)) {
|
|
113
|
+
seen2.add(key);
|
|
114
|
+
out.push(tuple);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return out;
|
|
120
|
+
};
|
|
121
|
+
const granularChanges = (() => {
|
|
122
|
+
try {
|
|
123
|
+
const res = minimizeTuples(tuples);
|
|
124
|
+
if (options.append && options.append.length) {
|
|
125
|
+
res.push(...options.append);
|
|
126
|
+
}
|
|
127
|
+
return res;
|
|
128
|
+
} catch {
|
|
129
|
+
return Array.isArray(tuples) ? tuples.slice() : [];
|
|
130
|
+
}
|
|
131
|
+
})();
|
|
132
|
+
const hydratedGranularChanges = granularChanges.map((t) => {
|
|
133
|
+
if (!Array.isArray(t) || t.length < 3) {
|
|
134
|
+
return t;
|
|
135
|
+
}
|
|
136
|
+
const [action, path] = t;
|
|
137
|
+
if (action !== "update" && action !== "set" || !Array.isArray(path)) {
|
|
138
|
+
return t;
|
|
139
|
+
}
|
|
140
|
+
const nextValue = resolveNextValueFromTuples(tuples, path);
|
|
141
|
+
if (nextValue === null) {
|
|
142
|
+
return t;
|
|
143
|
+
}
|
|
144
|
+
return [action, path, nextValue];
|
|
145
|
+
});
|
|
146
|
+
const baseOrders = computeOrdersForTuples(root, hydratedGranularChanges);
|
|
147
|
+
const preferOrdersMap = /* @__PURE__ */ new Map();
|
|
148
|
+
for (let i = 0; i < tuples.length; i++) {
|
|
149
|
+
const t = tuples[i];
|
|
150
|
+
if (!Array.isArray(t) || t.length < 3) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const [action, path, value] = t;
|
|
154
|
+
const isFilesPath = Array.isArray(path) && path[0] === "files";
|
|
155
|
+
if (action !== "update" || !Array.isArray(path) || path.length !== 1 && path.length !== 2 || !isPlainObject(value) || isFilesPath || value && value.type === "files") {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const keys = Object.keys(value).filter((k) => k !== "__order");
|
|
159
|
+
const key = JSON.stringify(path);
|
|
160
|
+
preferOrdersMap.set(key, { path, keys });
|
|
161
|
+
}
|
|
162
|
+
const mergedOrders = [];
|
|
163
|
+
const seen = /* @__PURE__ */ new Set();
|
|
164
|
+
preferOrdersMap.forEach((v, k) => {
|
|
165
|
+
seen.add(k);
|
|
166
|
+
mergedOrders.push(v);
|
|
167
|
+
});
|
|
168
|
+
for (let i = 0; i < baseOrders.length; i++) {
|
|
169
|
+
const v = baseOrders[i];
|
|
170
|
+
const k = JSON.stringify(v.path);
|
|
171
|
+
if (!seen.has(k)) {
|
|
172
|
+
seen.add(k);
|
|
173
|
+
mergedOrders.push(v);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return { granularChanges: hydratedGranularChanges, orders: mergedOrders };
|
|
177
|
+
}
|
|
178
|
+
export {
|
|
179
|
+
preprocessChanges
|
|
180
|
+
};
|
|
@@ -2,12 +2,54 @@ function isPlainObject(o) {
|
|
|
2
2
|
return o && typeof o === "object" && !Array.isArray(o);
|
|
3
3
|
}
|
|
4
4
|
function deepEqual(a, b) {
|
|
5
|
-
|
|
6
|
-
return
|
|
7
|
-
}
|
|
8
|
-
|
|
5
|
+
if (Object.is(a, b)) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
if (typeof a === "function" && typeof b === "function") {
|
|
9
|
+
try {
|
|
10
|
+
return a.toString() === b.toString();
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (typeof a === "function" || typeof b === "function") {
|
|
9
16
|
return false;
|
|
10
17
|
}
|
|
18
|
+
if (a instanceof Date && b instanceof Date) {
|
|
19
|
+
return a.getTime() === b.getTime();
|
|
20
|
+
}
|
|
21
|
+
if (a instanceof RegExp && b instanceof RegExp) {
|
|
22
|
+
return String(a) === String(b);
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
25
|
+
if (a.length !== b.length) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
for (let i = 0; i < a.length; i++) {
|
|
29
|
+
if (!deepEqual(a[i], b[i])) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
if (a && b && typeof a === "object" && typeof b === "object") {
|
|
36
|
+
const aKeys = Object.keys(a);
|
|
37
|
+
const bKeys = Object.keys(b);
|
|
38
|
+
if (aKeys.length !== bKeys.length) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
for (let i = 0; i < aKeys.length; i++) {
|
|
42
|
+
const key = aKeys[i];
|
|
43
|
+
if (!Object.hasOwn(b, key)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (!deepEqual(a[key], b[key])) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
11
53
|
}
|
|
12
54
|
import * as Y from "yjs";
|
|
13
55
|
function getRootMap(ydoc) {
|