@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.
- package/README.md +143 -2
- package/dist/cjs/config/environment.js +98 -30
- package/dist/cjs/index.js +144 -24
- 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 +743 -0
- 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 +64 -16
- package/dist/cjs/state/RootStateManager.js +65 -0
- package/dist/cjs/state/rootEventBus.js +74 -0
- package/dist/cjs/utils/CollabClient.js +223 -0
- package/dist/cjs/utils/TokenManager.js +78 -30
- package/dist/cjs/utils/changePreprocessor.js +199 -0
- package/dist/cjs/utils/jsonDiff.js +145 -0
- package/dist/cjs/utils/ordering.js +309 -0
- package/dist/cjs/utils/services.js +301 -103
- package/dist/cjs/utils/validation.js +0 -3
- package/dist/esm/config/environment.js +98 -30
- package/dist/esm/index.js +49505 -8718
- 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 +26895 -0
- 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 +49062 -8569
- package/dist/esm/state/RootStateManager.js +90 -0
- package/dist/esm/state/rootEventBus.js +56 -0
- package/dist/esm/utils/CollabClient.js +18889 -0
- package/dist/esm/utils/TokenManager.js +78 -30
- package/dist/esm/utils/changePreprocessor.js +542 -0
- package/dist/esm/utils/jsonDiff.js +7011 -0
- package/dist/esm/utils/ordering.js +291 -0
- package/dist/esm/utils/services.js +301 -103
- package/dist/esm/utils/validation.js +116 -50
- package/dist/node/config/environment.js +98 -30
- package/dist/node/index.js +175 -32
- 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 +724 -0
- 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 +64 -16
- package/dist/node/state/RootStateManager.js +36 -0
- package/dist/node/state/rootEventBus.js +55 -0
- package/dist/node/utils/CollabClient.js +194 -0
- package/dist/node/utils/TokenManager.js +78 -30
- package/dist/node/utils/changePreprocessor.js +180 -0
- package/dist/node/utils/jsonDiff.js +116 -0
- package/dist/node/utils/ordering.js +290 -0
- package/dist/node/utils/services.js +301 -103
- package/dist/node/utils/validation.js +0 -3
- package/package.json +39 -21
- package/src/config/environment.js +99 -28
- package/src/index.js +181 -36
- 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 +900 -0
- 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 +80 -13
- 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 +76 -0
- package/src/state/rootEventBus.js +67 -0
- package/src/utils/CollabClient.js +248 -0
- package/src/utils/TokenManager.js +88 -33
- package/src/utils/changePreprocessor.js +239 -0
- package/src/utils/jsonDiff.js +144 -0
- package/src/utils/ordering.js +271 -0
- package/src/utils/services.js +326 -107
- 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 -1751
- package/dist/cjs/services/SocketIOService.js +0 -307
- package/dist/cjs/services/SocketService.js +0 -161
- 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 -5278
- package/dist/esm/services/CoreService.js +0 -2264
- package/dist/esm/services/SocketIOService.js +0 -470
- package/dist/esm/services/SocketService.js +0 -191
- package/dist/esm/services/SymstoryService.js +0 -7041
- package/dist/esm/utils/basedQuerys.js +0 -163
- package/dist/esm/utils/symstoryClient.js +0 -370
- package/dist/node/services/AIService.js +0 -136
- package/dist/node/services/BasedService.js +0 -1156
- package/dist/node/services/CoreService.js +0 -1722
- package/dist/node/services/SocketIOService.js +0 -278
- package/dist/node/services/SocketService.js +0 -142
- 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 -1301
- package/src/services/CoreService.js +0 -1943
- package/src/services/SocketIOService.js +0 -334
- package/src/services/SocketService.js +0 -168
- 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,23 +1,71 @@
|
|
|
1
|
-
import { SymstoryService } from "./SymstoryService.js";
|
|
2
1
|
import { AuthService } from "./AuthService.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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";
|
|
6
18
|
const createService = (ServiceClass, config) => new ServiceClass(config);
|
|
7
|
-
const createSymstoryService = (config) => createService(SymstoryService, config);
|
|
8
19
|
const createAuthService = (config) => createService(AuthService, config);
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
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);
|
|
12
36
|
export {
|
|
13
|
-
|
|
37
|
+
AdminService,
|
|
14
38
|
AuthService,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
39
|
+
BranchService,
|
|
40
|
+
CollabService,
|
|
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,
|
|
19
55
|
createAuthService,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
56
|
+
createBranchService,
|
|
57
|
+
createCollabService,
|
|
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
|
|
23
71
|
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as utils from "@domql/utils";
|
|
2
|
+
import { rootBus } from "./rootEventBus.js";
|
|
3
|
+
const { isFunction } = utils.default || utils;
|
|
4
|
+
class RootStateManager {
|
|
5
|
+
constructor(rootState) {
|
|
6
|
+
this._rootState = rootState;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Apply change tuples to the root state using the built-in setPathCollection
|
|
10
|
+
* of Symbo.ls APP state tree.
|
|
11
|
+
*
|
|
12
|
+
* @param {Array} changes – eg. ['update', ['foo'], 'bar']
|
|
13
|
+
* @param {Object} opts – forwarded to setPathCollection
|
|
14
|
+
*/
|
|
15
|
+
async applyChanges(changes = [], opts = {}) {
|
|
16
|
+
if (!this._rootState || !isFunction(this._rootState.setPathCollection)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const result = await this._rootState.setPathCollection(changes, {
|
|
20
|
+
preventUpdate: true,
|
|
21
|
+
...opts
|
|
22
|
+
});
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
setVersion(v) {
|
|
26
|
+
if (this._rootState) {
|
|
27
|
+
this._rootState.version = v;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
get root() {
|
|
31
|
+
return this._rootState;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
RootStateManager
|
|
36
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const getGlobalBus = () => {
|
|
2
|
+
if (globalThis.__SMBLS_ROOT_BUS__) {
|
|
3
|
+
return globalThis.__SMBLS_ROOT_BUS__;
|
|
4
|
+
}
|
|
5
|
+
const events = {};
|
|
6
|
+
const lastPayloads = {};
|
|
7
|
+
const bus = {
|
|
8
|
+
on(event, handler) {
|
|
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
|
+
}
|
|
17
|
+
},
|
|
18
|
+
off(event, handler) {
|
|
19
|
+
const list = events[event];
|
|
20
|
+
if (!list) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const idx = list.indexOf(handler);
|
|
24
|
+
if (idx !== -1) {
|
|
25
|
+
list.splice(idx, 1);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
emit(event, payload) {
|
|
29
|
+
lastPayloads[event] = payload;
|
|
30
|
+
const list = events[event];
|
|
31
|
+
if (!list || !list.length) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
list.slice().forEach((fn) => {
|
|
35
|
+
try {
|
|
36
|
+
fn(payload);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
console.error("[rootBus] handler error for", event, err);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
Object.defineProperty(bus, "_listeners", {
|
|
44
|
+
value: events,
|
|
45
|
+
enumerable: false
|
|
46
|
+
});
|
|
47
|
+
globalThis.__SMBLS_ROOT_BUS__ = bus;
|
|
48
|
+
return bus;
|
|
49
|
+
};
|
|
50
|
+
const rootBus = getGlobalBus();
|
|
51
|
+
var rootEventBus_default = rootBus;
|
|
52
|
+
export {
|
|
53
|
+
rootEventBus_default as default,
|
|
54
|
+
rootBus
|
|
55
|
+
};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { io } from "socket.io-client";
|
|
2
|
+
import * as Y from "yjs";
|
|
3
|
+
import { nanoid } from "nanoid";
|
|
4
|
+
import environment from "../config/environment.js";
|
|
5
|
+
import { diffJson, applyOpsToJson } from "./jsonDiff.js";
|
|
6
|
+
class CollabClient {
|
|
7
|
+
/* public fields */
|
|
8
|
+
socket = null;
|
|
9
|
+
ydoc = null;
|
|
10
|
+
branch = "main";
|
|
11
|
+
live = false;
|
|
12
|
+
projectId = null;
|
|
13
|
+
jwt = null;
|
|
14
|
+
/* private state */
|
|
15
|
+
_buffer = [];
|
|
16
|
+
_flushTimer = null;
|
|
17
|
+
_clientId = nanoid();
|
|
18
|
+
_outboxStore = createMemoryOutbox();
|
|
19
|
+
// Dexie table fallback
|
|
20
|
+
_readyResolve;
|
|
21
|
+
ready = new Promise((res) => this._readyResolve = res);
|
|
22
|
+
constructor({ jwt, projectId, branch = "main", live = false }) {
|
|
23
|
+
Object.assign(this, { jwt, projectId, branch, live });
|
|
24
|
+
this.ydoc = new Y.Doc();
|
|
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
|
+
}
|
|
42
|
+
this.socket = io(environment.socketUrl, {
|
|
43
|
+
path: "/collab-socket",
|
|
44
|
+
transports: ["websocket"],
|
|
45
|
+
auth: { token: jwt, projectId, branch, live },
|
|
46
|
+
reconnectionAttempts: Infinity,
|
|
47
|
+
reconnectionDelayMax: 4e3
|
|
48
|
+
});
|
|
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);
|
|
50
|
+
this._prevJson = this.ydoc.getMap("root").toJSON();
|
|
51
|
+
this.ydoc.on("afterTransaction", (tr) => {
|
|
52
|
+
if (tr.origin === "remote") {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const currentJson = this.ydoc.getMap("root").toJSON();
|
|
56
|
+
const ops = diffJson(this._prevJson, currentJson);
|
|
57
|
+
this._prevJson = currentJson;
|
|
58
|
+
if (!ops.length) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this._queueOps(ops);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/* ---------- public helpers ---------- */
|
|
65
|
+
toggleLive(flag) {
|
|
66
|
+
this.socket.emit("toggleLive", Boolean(flag));
|
|
67
|
+
}
|
|
68
|
+
sendCursor(data) {
|
|
69
|
+
this.socket.emit("cursor", data);
|
|
70
|
+
}
|
|
71
|
+
sendPresence(d) {
|
|
72
|
+
this.socket.emit("presence", d);
|
|
73
|
+
}
|
|
74
|
+
/* ---------- private handlers ---------- */
|
|
75
|
+
_onSnapshot = ({
|
|
76
|
+
data
|
|
77
|
+
/* Uint8Array */
|
|
78
|
+
}) => {
|
|
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
|
+
}
|
|
84
|
+
this._prevJson = this.ydoc.getMap("root").toJSON();
|
|
85
|
+
if (typeof this._readyResolve === "function") {
|
|
86
|
+
this._readyResolve();
|
|
87
|
+
this._readyResolve = null;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
_onOps = ({ changes }) => {
|
|
91
|
+
applyOpsToJson(changes, this.ydoc);
|
|
92
|
+
this._prevJson = this.ydoc.getMap("root").toJSON();
|
|
93
|
+
};
|
|
94
|
+
_onCommit = async ({ version }) => {
|
|
95
|
+
await this._outboxStore.clear();
|
|
96
|
+
console.info("[collab] committed", version);
|
|
97
|
+
};
|
|
98
|
+
_onConnect = async () => {
|
|
99
|
+
if (typeof this._readyResolve === "function") {
|
|
100
|
+
this._readyResolve();
|
|
101
|
+
this._readyResolve = null;
|
|
102
|
+
}
|
|
103
|
+
const queued = await this._outboxStore.toArray();
|
|
104
|
+
if (queued.length) {
|
|
105
|
+
this.socket.emit("ops", {
|
|
106
|
+
changes: queued.flatMap((e) => e.ops),
|
|
107
|
+
ts: Date.now(),
|
|
108
|
+
clientId: this._clientId
|
|
109
|
+
});
|
|
110
|
+
await this._outboxStore.clear();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
/* ---------- buffering & debounce ---------- */
|
|
114
|
+
_queueOps(ops) {
|
|
115
|
+
this._buffer.push(...ops);
|
|
116
|
+
this._outboxStore.put({ id: nanoid(), ops });
|
|
117
|
+
if (this.live && this.socket.connected) {
|
|
118
|
+
this._flushNow();
|
|
119
|
+
} else {
|
|
120
|
+
clearTimeout(this._flushTimer);
|
|
121
|
+
this._flushTimer = setTimeout(() => this._flushNow(), 40);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
_flushNow() {
|
|
125
|
+
if (!this._buffer.length || !this.socket.connected) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.socket.emit("ops", {
|
|
129
|
+
changes: this._buffer,
|
|
130
|
+
ts: Date.now(),
|
|
131
|
+
clientId: this._clientId
|
|
132
|
+
});
|
|
133
|
+
this._buffer.length = 0;
|
|
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
|
+
};
|
|
185
|
+
}
|
|
186
|
+
async function createDexieOutbox(name) {
|
|
187
|
+
const { default: Dexie } = await import("dexie");
|
|
188
|
+
const db = new Dexie(`collab-${name}`);
|
|
189
|
+
db.version(1).stores({ outbox: "id, ops" });
|
|
190
|
+
return db.table("outbox");
|
|
191
|
+
}
|
|
192
|
+
export {
|
|
193
|
+
CollabClient
|
|
194
|
+
};
|
|
@@ -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
|
/**
|
|
@@ -129,7 +142,28 @@ class TokenManager {
|
|
|
129
142
|
return true;
|
|
130
143
|
}
|
|
131
144
|
const now = Date.now();
|
|
132
|
-
|
|
145
|
+
const isValid = now < this.tokens.expiresAt - this.config.refreshBuffer;
|
|
146
|
+
if (!isValid) {
|
|
147
|
+
console.log("[TokenManager] Access token is expired or near expiry:", {
|
|
148
|
+
now: new Date(now).toISOString(),
|
|
149
|
+
expiresAt: new Date(this.tokens.expiresAt).toISOString(),
|
|
150
|
+
refreshBuffer: this.config.refreshBuffer
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return isValid;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Check if access token exists and is not expired (without refresh buffer)
|
|
157
|
+
*/
|
|
158
|
+
isAccessTokenActuallyValid() {
|
|
159
|
+
if (!this.tokens.accessToken) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
if (!this.tokens.expiresAt) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
const now = Date.now();
|
|
166
|
+
return now < this.tokens.expiresAt;
|
|
133
167
|
}
|
|
134
168
|
/**
|
|
135
169
|
* Check if tokens exist (regardless of expiry)
|
|
@@ -255,40 +289,54 @@ class TokenManager {
|
|
|
255
289
|
* Save tokens to storage
|
|
256
290
|
*/
|
|
257
291
|
saveTokens() {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
292
|
+
try {
|
|
293
|
+
const { storage } = this;
|
|
294
|
+
const keys = this.storageKeys;
|
|
295
|
+
if (this.tokens.accessToken) {
|
|
296
|
+
storage.setItem(keys.accessToken, this.tokens.accessToken);
|
|
297
|
+
}
|
|
298
|
+
if (this.tokens.refreshToken) {
|
|
299
|
+
storage.setItem(keys.refreshToken, this.tokens.refreshToken);
|
|
300
|
+
}
|
|
301
|
+
if (this.tokens.expiresAt) {
|
|
302
|
+
storage.setItem(keys.expiresAt, this.tokens.expiresAt.toString());
|
|
303
|
+
}
|
|
304
|
+
if (this.tokens.expiresIn) {
|
|
305
|
+
storage.setItem(keys.expiresIn, this.tokens.expiresIn.toString());
|
|
306
|
+
}
|
|
307
|
+
} catch (error) {
|
|
308
|
+
console.error("[TokenManager] Error saving tokens to storage:", error);
|
|
271
309
|
}
|
|
272
310
|
}
|
|
273
311
|
/**
|
|
274
312
|
* Load tokens from storage
|
|
275
313
|
*/
|
|
276
314
|
loadTokens() {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
315
|
+
try {
|
|
316
|
+
const { storage } = this;
|
|
317
|
+
const keys = this.storageKeys;
|
|
318
|
+
const accessToken = storage.getItem(keys.accessToken);
|
|
319
|
+
const refreshToken = storage.getItem(keys.refreshToken);
|
|
320
|
+
const expiresAt = storage.getItem(keys.expiresAt);
|
|
321
|
+
const expiresIn = storage.getItem(keys.expiresIn);
|
|
322
|
+
if (accessToken) {
|
|
323
|
+
this.tokens = {
|
|
324
|
+
accessToken,
|
|
325
|
+
refreshToken,
|
|
326
|
+
expiresAt: expiresAt ? parseInt(expiresAt, 10) : null,
|
|
327
|
+
expiresIn: expiresIn ? parseInt(expiresIn, 10) : null,
|
|
328
|
+
tokenType: "Bearer"
|
|
329
|
+
};
|
|
330
|
+
this.scheduleRefresh();
|
|
331
|
+
}
|
|
332
|
+
} catch (error) {
|
|
333
|
+
console.error("[TokenManager] Error loading tokens from storage:", error);
|
|
284
334
|
this.tokens = {
|
|
285
|
-
accessToken,
|
|
286
|
-
refreshToken,
|
|
287
|
-
expiresAt:
|
|
288
|
-
expiresIn:
|
|
289
|
-
tokenType: "Bearer"
|
|
335
|
+
accessToken: null,
|
|
336
|
+
refreshToken: null,
|
|
337
|
+
expiresAt: null,
|
|
338
|
+
expiresIn: null
|
|
290
339
|
};
|
|
291
|
-
this.scheduleRefresh();
|
|
292
340
|
}
|
|
293
341
|
}
|
|
294
342
|
/**
|