@symbo.ls/sdk 2.32.1 → 2.32.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/cjs/config/environment.js +8 -43
  2. package/dist/cjs/index.js +4 -12
  3. package/dist/cjs/services/AdminService.js +4 -4
  4. package/dist/cjs/services/AuthService.js +149 -36
  5. package/dist/cjs/services/BaseService.js +18 -5
  6. package/dist/cjs/services/BranchService.js +10 -10
  7. package/dist/cjs/services/CollabService.js +61 -163
  8. package/dist/cjs/services/CoreService.js +19 -19
  9. package/dist/cjs/services/DnsService.js +4 -4
  10. package/dist/cjs/services/FileService.js +2 -2
  11. package/dist/cjs/services/PaymentService.js +2 -2
  12. package/dist/cjs/services/PlanService.js +12 -12
  13. package/dist/cjs/services/ProjectService.js +34 -39
  14. package/dist/cjs/services/PullRequestService.js +7 -7
  15. package/dist/cjs/services/SubscriptionService.js +14 -14
  16. package/dist/cjs/services/index.js +0 -4
  17. package/dist/cjs/utils/TokenManager.js +5 -16
  18. package/dist/cjs/utils/services.js +1 -14
  19. package/dist/esm/config/environment.js +8 -43
  20. package/dist/esm/index.js +343 -937
  21. package/dist/esm/services/AdminService.js +35 -68
  22. package/dist/esm/services/AuthService.js +168 -100
  23. package/dist/esm/services/BaseService.js +31 -64
  24. package/dist/esm/services/BranchService.js +41 -74
  25. package/dist/esm/services/CollabService.js +93 -482
  26. package/dist/esm/services/CoreService.js +50 -83
  27. package/dist/esm/services/DnsService.js +35 -68
  28. package/dist/esm/services/FileService.js +33 -66
  29. package/dist/esm/services/PaymentService.js +33 -66
  30. package/dist/esm/services/PlanService.js +43 -76
  31. package/dist/esm/services/ProjectService.js +65 -356
  32. package/dist/esm/services/PullRequestService.js +38 -71
  33. package/dist/esm/services/SubscriptionService.js +45 -78
  34. package/dist/esm/services/index.js +338 -914
  35. package/dist/esm/utils/CollabClient.js +8 -43
  36. package/dist/esm/utils/TokenManager.js +5 -16
  37. package/dist/esm/utils/services.js +1 -14
  38. package/dist/node/config/environment.js +8 -43
  39. package/dist/node/index.js +5 -14
  40. package/dist/node/services/AdminService.js +4 -4
  41. package/dist/node/services/AuthService.js +139 -36
  42. package/dist/node/services/BaseService.js +18 -5
  43. package/dist/node/services/BranchService.js +10 -10
  44. package/dist/node/services/CollabService.js +62 -164
  45. package/dist/node/services/CoreService.js +19 -19
  46. package/dist/node/services/DnsService.js +4 -4
  47. package/dist/node/services/FileService.js +2 -2
  48. package/dist/node/services/PaymentService.js +2 -2
  49. package/dist/node/services/PlanService.js +12 -12
  50. package/dist/node/services/ProjectService.js +34 -39
  51. package/dist/node/services/PullRequestService.js +7 -7
  52. package/dist/node/services/SubscriptionService.js +14 -14
  53. package/dist/node/services/index.js +0 -4
  54. package/dist/node/utils/TokenManager.js +5 -16
  55. package/dist/node/utils/services.js +1 -14
  56. package/package.json +6 -7
  57. package/src/config/environment.js +9 -48
  58. package/src/index.js +22 -38
  59. package/src/services/AdminService.js +4 -4
  60. package/src/services/AuthService.js +175 -42
  61. package/src/services/BaseService.js +24 -7
  62. package/src/services/BranchService.js +10 -10
  63. package/src/services/CollabService.js +72 -203
  64. package/src/services/CoreService.js +19 -19
  65. package/src/services/DnsService.js +4 -4
  66. package/src/services/FileService.js +2 -2
  67. package/src/services/PaymentService.js +2 -2
  68. package/src/services/PlanService.js +12 -12
  69. package/src/services/ProjectService.js +34 -41
  70. package/src/services/PullRequestService.js +7 -7
  71. package/src/services/SubscriptionService.js +14 -14
  72. package/src/services/index.js +1 -6
  73. package/src/utils/TokenManager.js +5 -19
  74. package/src/utils/services.js +1 -15
  75. package/dist/cjs/services/ScreenshotService.js +0 -304
  76. package/dist/cjs/utils/ordering.js +0 -276
  77. package/dist/esm/services/ScreenshotService.js +0 -992
  78. package/dist/esm/utils/ordering.js +0 -258
  79. package/dist/node/services/ScreenshotService.js +0 -285
  80. package/dist/node/utils/ordering.js +0 -257
  81. package/src/services/ScreenshotService.js +0 -258
  82. package/src/utils/ordering.js +0 -244
@@ -14111,28 +14111,18 @@ var CONFIG = {
14111
14111
  // For based api
14112
14112
  basedOrg: "symbols",
14113
14113
  // For based api
14114
- githubClientId: "Ov23liAFrsR0StbAO6PO",
14114
+ githubClientId: "Ov23liHxyWFBxS8f1gnF",
14115
14115
  // For github api
14116
14116
  // Environment-specific feature toggles (override common)
14117
14117
  features: {
14118
14118
  betaFeatures: true
14119
14119
  // Enable beta features in local dev
14120
- },
14121
- typesenseCollectionName: "docs",
14122
- typesenseApiKey: "vZya3L2zpq8L6iI5WWMUZJZABvT63VDb",
14123
- typesenseHost: "localhost",
14124
- typesensePort: "8108",
14125
- typesenseProtocol: "http"
14120
+ }
14126
14121
  },
14127
14122
  development: {
14128
14123
  socketUrl: "https://dev.api.symbols.app",
14129
14124
  apiUrl: "https://dev.api.symbols.app",
14130
- githubClientId: "Ov23liHxyWFBxS8f1gnF",
14131
- typesenseCollectionName: "docs",
14132
- typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
14133
- typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
14134
- typesensePort: "443",
14135
- typesenseProtocol: "https"
14125
+ githubClientId: "Ov23liHxyWFBxS8f1gnF"
14136
14126
  },
14137
14127
  testing: {
14138
14128
  socketUrl: "https://test.api.symbols.app",
@@ -14140,22 +14130,12 @@ var CONFIG = {
14140
14130
  basedEnv: "testing",
14141
14131
  basedProject: "platform-v2-sm",
14142
14132
  basedOrg: "symbols",
14143
- githubClientId: "Ov23liHxyWFBxS8f1gnF",
14144
- typesenseCollectionName: "docs",
14145
- typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
14146
- typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
14147
- typesensePort: "443",
14148
- typesenseProtocol: "https"
14133
+ githubClientId: "Ov23liHxyWFBxS8f1gnF"
14149
14134
  },
14150
14135
  upcoming: {
14151
14136
  socketUrl: "https://upcoming.api.symbols.app",
14152
14137
  apiUrl: "https://upcoming.api.symbols.app",
14153
- githubClientId: "Ov23liWF7NvdZ056RV5J",
14154
- typesenseCollectionName: "docs",
14155
- typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
14156
- typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
14157
- typesensePort: "443",
14158
- typesenseProtocol: "https"
14138
+ githubClientId: "Ov23liWF7NvdZ056RV5J"
14159
14139
  },
14160
14140
  staging: {
14161
14141
  socketUrl: "https://staging.api.symbols.app",
@@ -14163,12 +14143,7 @@ var CONFIG = {
14163
14143
  basedEnv: "staging",
14164
14144
  basedProject: "platform-v2-sm",
14165
14145
  basedOrg: "symbols",
14166
- githubClientId: "Ov23ligwZDQVD0VfuWNa",
14167
- typesenseCollectionName: "docs",
14168
- typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
14169
- typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
14170
- typesensePort: "443",
14171
- typesenseProtocol: "https"
14146
+ githubClientId: "Ov23ligwZDQVD0VfuWNa"
14172
14147
  },
14173
14148
  production: {
14174
14149
  socketUrl: "https://api.symbols.app",
@@ -14176,12 +14151,7 @@ var CONFIG = {
14176
14151
  basedEnv: "production",
14177
14152
  basedProject: "platform-v2-sm",
14178
14153
  basedOrg: "symbols",
14179
- githubClientId: "Ov23liFAlOEIXtX3dBtR",
14180
- typesenseCollectionName: "docs",
14181
- typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
14182
- typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
14183
- typesensePort: "443",
14184
- typesenseProtocol: "https"
14154
+ githubClientId: "Ov23liFAlOEIXtX3dBtR"
14185
14155
  }
14186
14156
  };
14187
14157
  var getEnvironment = () => {
@@ -14203,11 +14173,6 @@ var getConfig = () => {
14203
14173
  basedProject: process.env.SYMBOLS_APP_BASED_PROJECT || envConfig.basedProject,
14204
14174
  basedOrg: process.env.SYMBOLS_APP_BASED_ORG || envConfig.basedOrg,
14205
14175
  githubClientId: process.env.SYMBOLS_APP_GITHUB_CLIENT_ID || envConfig.githubClientId,
14206
- typesenseCollectionName: process.env.TYPESENSE_COLLECTION_NAME || envConfig.typesenseCollectionName,
14207
- typesenseApiKey: process.env.TYPESENSE_API_KEY || envConfig.typesenseApiKey,
14208
- typesenseHost: process.env.TYPESENSE_HOST || envConfig.typesenseHost,
14209
- typesensePort: process.env.TYPESENSE_PORT || envConfig.typesensePort,
14210
- typesenseProtocol: process.env.TYPESENSE_PROTOCOL || envConfig.typesenseProtocol,
14211
14176
  isDevelopment: isDevelopment(env),
14212
14177
  isTesting: env === "testing",
14213
14178
  isStaging: env === "staging",
@@ -14227,7 +14192,7 @@ var getConfig = () => {
14227
14192
  );
14228
14193
  }
14229
14194
  if (finalConfig.isDevelopment) {
14230
- console.warn(
14195
+ console.log(
14231
14196
  "environment in SDK:",
14232
14197
  env || process.env.NODE_ENV || process.env.NODE_ENV
14233
14198
  );
@@ -14266,7 +14231,7 @@ var TokenManager = class {
14266
14231
  });
14267
14232
  this.config = {
14268
14233
  storagePrefix: "symbols_",
14269
- storageType: typeof window === "undefined" || process.env.NODE_ENV === "test" || process.env.NODE_ENV === "testing" ? "memory" : "localStorage",
14234
+ storageType: typeof window === "undefined" || process.env.NODE_ENV === "test" ? "memory" : "localStorage",
14270
14235
  // 'localStorage' | 'sessionStorage' | 'memory'
14271
14236
  refreshBuffer: 60 * 1e3,
14272
14237
  // Refresh 1 minute before expiry
@@ -14306,26 +14271,15 @@ var TokenManager = class {
14306
14271
  if (typeof window === "undefined") {
14307
14272
  return this._memoryStorage;
14308
14273
  }
14309
- const safeGetStorage = (provider) => {
14310
- try {
14311
- const storage = provider();
14312
- const testKey = `${this.config.storagePrefix}__tm_test__`;
14313
- storage.setItem(testKey, "1");
14314
- storage.removeItem(testKey);
14315
- return storage;
14316
- } catch {
14317
- return null;
14318
- }
14319
- };
14320
- const localStorageInstance = safeGetStorage(() => window.localStorage);
14321
- const sessionStorageInstance = safeGetStorage(() => window.sessionStorage);
14274
+ const hasLocalStorage = typeof window.localStorage !== "undefined";
14275
+ const hasSessionStorage = typeof window.sessionStorage !== "undefined";
14322
14276
  switch (this.config.storageType) {
14323
14277
  case "sessionStorage":
14324
- return sessionStorageInstance || this._memoryStorage;
14278
+ return hasSessionStorage ? window.sessionStorage : this._memoryStorage;
14325
14279
  case "memory":
14326
14280
  return this._memoryStorage;
14327
14281
  default:
14328
- return localStorageInstance || this._memoryStorage;
14282
+ return hasLocalStorage ? window.localStorage : this._memoryStorage;
14329
14283
  }
14330
14284
  }
14331
14285
  /**
@@ -14664,10 +14618,20 @@ var BaseService = class {
14664
14618
  }
14665
14619
  this._tokenManager = getTokenManager({
14666
14620
  apiUrl: this._apiUrl,
14621
+ onTokenRefresh: (tokens) => {
14622
+ this.updateContext({ authToken: tokens.accessToken });
14623
+ },
14624
+ onTokenExpired: () => {
14625
+ this.updateContext({ authToken: null });
14626
+ },
14667
14627
  onTokenError: (error) => {
14668
14628
  console.error("Token management error:", error);
14669
14629
  }
14670
14630
  });
14631
+ const { authToken } = this._context;
14632
+ if (authToken && !this._tokenManager.hasTokens()) {
14633
+ this._tokenManager.setTokens({ access_token: authToken });
14634
+ }
14671
14635
  this._setReady();
14672
14636
  } catch (error) {
14673
14637
  this._setError(error);
@@ -14676,9 +14640,7 @@ var BaseService = class {
14676
14640
  }
14677
14641
  // Update context
14678
14642
  updateContext(context) {
14679
- if (context && typeof context === "object") {
14680
- Object.assign(this._context, context);
14681
- }
14643
+ this._context = { ...this._context, ...context };
14682
14644
  }
14683
14645
  // Get service status
14684
14646
  getStatus() {
@@ -14733,6 +14695,11 @@ var BaseService = class {
14733
14695
  error
14734
14696
  );
14735
14697
  }
14698
+ } else if (this._requiresInit(options.methodName)) {
14699
+ const { authToken } = this._context;
14700
+ if (authToken) {
14701
+ defaultHeaders.Authorization = `Bearer ${authToken}`;
14702
+ }
14736
14703
  }
14737
14704
  try {
14738
14705
  const response = await fetch(url2, {
@@ -14750,11 +14717,11 @@ var BaseService = class {
14750
14717
  error = await response.json();
14751
14718
  } catch {
14752
14719
  }
14753
- throw new Error(error.message || error.error || "Request failed", { cause: error });
14720
+ throw new Error(error.message || error.error || "Request failed");
14754
14721
  }
14755
14722
  return response.status === 204 ? null : response.json();
14756
14723
  } catch (error) {
14757
- throw new Error(`Request failed: ${error.message}`, { cause: error });
14724
+ throw new Error(`Request failed: ${error.message}`);
14758
14725
  }
14759
14726
  }
14760
14727
  // Helper method to determine if a method requires initialization
@@ -24554,263 +24521,7 @@ var validateParams = {
24554
24521
  };
24555
24522
 
24556
24523
  // src/services/CollabService.js
24557
- import { deepStringifyFunctions } from "@domql/utils";
24558
-
24559
- // src/utils/ordering.js
24560
- function isObjectLike(val) {
24561
- return val && typeof val === "object" && !Array.isArray(val);
24562
- }
24563
- function normalizePath(path) {
24564
- if (Array.isArray(path)) {
24565
- return path;
24566
- }
24567
- if (typeof path === "string") {
24568
- return [path];
24569
- }
24570
- return [];
24571
- }
24572
- function getParentPathsFromTuples(tuples = []) {
24573
- const seen = /* @__PURE__ */ new Set();
24574
- const parents = [];
24575
- const META_KEYS = /* @__PURE__ */ new Set([
24576
- "style",
24577
- "class",
24578
- "text",
24579
- "html",
24580
- "content",
24581
- "data",
24582
- "attr",
24583
- "state",
24584
- "scope",
24585
- "props",
24586
- "define",
24587
- "on",
24588
- "extend",
24589
- "extends",
24590
- "childExtend",
24591
- "childExtends",
24592
- "childProps",
24593
- "children",
24594
- "component",
24595
- "context",
24596
- "tag",
24597
- "key",
24598
- "__order",
24599
- "if"
24600
- ]);
24601
- for (let i = 0; i < tuples.length; i++) {
24602
- const tuple = tuples[i];
24603
- if (!Array.isArray(tuple) || tuple.length < 2) {
24604
- continue;
24605
- }
24606
- const path = normalizePath(tuple[1]);
24607
- if (!path.length) {
24608
- continue;
24609
- }
24610
- if (path[0] === "schema") {
24611
- continue;
24612
- }
24613
- const immediateParent = path.slice(0, -1);
24614
- if (immediateParent.length) {
24615
- const key = JSON.stringify(immediateParent);
24616
- if (!seen.has(key)) {
24617
- seen.add(key);
24618
- parents.push(immediateParent);
24619
- }
24620
- }
24621
- const last2 = path[path.length - 1];
24622
- if (META_KEYS.has(last2) && path.length >= 2) {
24623
- const containerParent = path.slice(0, -2);
24624
- if (containerParent.length) {
24625
- const key2 = JSON.stringify(containerParent);
24626
- if (!seen.has(key2)) {
24627
- seen.add(key2);
24628
- parents.push(containerParent);
24629
- }
24630
- }
24631
- }
24632
- for (let j = 0; j < path.length; j++) {
24633
- const seg = path[j];
24634
- if (!META_KEYS.has(seg)) {
24635
- continue;
24636
- }
24637
- const containerParent2 = path.slice(0, j);
24638
- if (!containerParent2.length) {
24639
- continue;
24640
- }
24641
- const key3 = JSON.stringify(containerParent2);
24642
- if (!seen.has(key3)) {
24643
- seen.add(key3);
24644
- parents.push(containerParent2);
24645
- }
24646
- }
24647
- }
24648
- return parents;
24649
- }
24650
- function computeOrdersFromState(root, parentPaths = []) {
24651
- if (!root || typeof root.getByPath !== "function") {
24652
- return [];
24653
- }
24654
- const orders = [];
24655
- const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
24656
- for (let i = 0; i < parentPaths.length; i++) {
24657
- const parentPath = parentPaths[i];
24658
- const obj = (() => {
24659
- try {
24660
- return root.getByPath(parentPath);
24661
- } catch {
24662
- return null;
24663
- }
24664
- })();
24665
- if (!isObjectLike(obj)) {
24666
- continue;
24667
- }
24668
- const keys2 = Object.keys(obj).filter((k) => !EXCLUDE_KEYS.has(k));
24669
- orders.push({ path: parentPath, keys: keys2 });
24670
- }
24671
- return orders;
24672
- }
24673
- function normaliseSchemaCode(code) {
24674
- if (typeof code !== "string" || !code.length) {
24675
- return "";
24676
- }
24677
- return code.replaceAll("/////n", "\n").replaceAll("/////tilde", "`");
24678
- }
24679
- function parseExportedObject(code) {
24680
- const src = normaliseSchemaCode(code);
24681
- if (!src) {
24682
- return null;
24683
- }
24684
- const body = src.replace(/^\s*export\s+default\s*/u, "return ");
24685
- try {
24686
- return new Function(body)();
24687
- } catch {
24688
- return null;
24689
- }
24690
- }
24691
- function extractTopLevelKeysFromCode(code) {
24692
- const obj = parseExportedObject(code);
24693
- if (!obj || typeof obj !== "object") {
24694
- return [];
24695
- }
24696
- return Object.keys(obj);
24697
- }
24698
- function computeOrdersForTuples(root, tuples = []) {
24699
- const pendingChildrenByContainer = /* @__PURE__ */ new Map();
24700
- for (let i = 0; i < tuples.length; i++) {
24701
- const t = tuples[i];
24702
- if (!Array.isArray(t)) {
24703
- continue;
24704
- }
24705
- const [action, path] = t;
24706
- const p = normalizePath(path);
24707
- if (!Array.isArray(p) || p.length < 3) {
24708
- continue;
24709
- }
24710
- if (p[0] === "schema") {
24711
- continue;
24712
- }
24713
- const [typeName, containerKey, childKey] = p;
24714
- const containerPath = [typeName, containerKey];
24715
- const key = JSON.stringify(containerPath);
24716
- if (!pendingChildrenByContainer.has(key)) {
24717
- pendingChildrenByContainer.set(key, /* @__PURE__ */ new Set());
24718
- }
24719
- if (action === "update" || action === "set") {
24720
- pendingChildrenByContainer.get(key).add(childKey);
24721
- }
24722
- }
24723
- const preferredOrderMap = /* @__PURE__ */ new Map();
24724
- for (let i = 0; i < tuples.length; i++) {
24725
- const t = tuples[i];
24726
- if (!Array.isArray(t)) {
24727
- continue;
24728
- }
24729
- const [action, path, value2] = t;
24730
- const p = normalizePath(path);
24731
- if (action !== "update" || !Array.isArray(p) || p.length < 3) {
24732
- continue;
24733
- }
24734
- if (p[0] !== "schema") {
24735
- continue;
24736
- }
24737
- const [, type, key] = p;
24738
- const containerPath = [type, key];
24739
- const uses = value2 && Array.isArray(value2.uses) ? value2.uses : null;
24740
- const code = value2 && value2.code;
24741
- const obj = (() => {
24742
- try {
24743
- return root && typeof root.getByPath === "function" ? root.getByPath(containerPath) : null;
24744
- } catch {
24745
- return null;
24746
- }
24747
- })();
24748
- if (!obj) {
24749
- continue;
24750
- }
24751
- const present = new Set(Object.keys(obj));
24752
- const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
24753
- const codeKeys = extractTopLevelKeysFromCode(code);
24754
- let resolved = [];
24755
- const pendingKey = JSON.stringify(containerPath);
24756
- const pendingChildren = pendingChildrenByContainer.get(pendingKey) || /* @__PURE__ */ new Set();
24757
- const eligible = /* @__PURE__ */ new Set([...present, ...pendingChildren]);
24758
- if (Array.isArray(codeKeys) && codeKeys.length) {
24759
- resolved = codeKeys.filter((k) => eligible.has(k) && !EXCLUDE_KEYS.has(k));
24760
- }
24761
- if (Array.isArray(uses) && uses.length) {
24762
- for (let u = 0; u < uses.length; u++) {
24763
- const keyName = uses[u];
24764
- if (eligible.has(keyName) && !EXCLUDE_KEYS.has(keyName) && !resolved.includes(keyName)) {
24765
- resolved.push(keyName);
24766
- }
24767
- }
24768
- }
24769
- if (pendingChildren.size) {
24770
- for (const child of pendingChildren) {
24771
- if (!EXCLUDE_KEYS.has(child) && !resolved.includes(child)) {
24772
- resolved.push(child);
24773
- }
24774
- }
24775
- }
24776
- if (resolved.length) {
24777
- preferredOrderMap.set(JSON.stringify(containerPath), { path: containerPath, keys: resolved });
24778
- }
24779
- }
24780
- const parents = getParentPathsFromTuples(tuples);
24781
- const orders = [];
24782
- const seen = /* @__PURE__ */ new Set();
24783
- preferredOrderMap.forEach((v) => {
24784
- const k = JSON.stringify(v.path);
24785
- if (!seen.has(k)) {
24786
- seen.add(k);
24787
- orders.push(v);
24788
- }
24789
- });
24790
- const fallbackOrders = computeOrdersFromState(root, parents);
24791
- for (let i = 0; i < fallbackOrders.length; i++) {
24792
- const v = fallbackOrders[i];
24793
- const k = JSON.stringify(v.path);
24794
- if (seen.has(k)) {
24795
- continue;
24796
- }
24797
- const pending = pendingChildrenByContainer.get(k);
24798
- if (pending && pending.size) {
24799
- const existing = new Set(v.keys);
24800
- for (const child of pending) {
24801
- if (existing.has(child)) {
24802
- continue;
24803
- }
24804
- v.keys.push(child);
24805
- }
24806
- }
24807
- seen.add(k);
24808
- orders.push(v);
24809
- }
24810
- return orders;
24811
- }
24812
-
24813
- // src/services/CollabService.js
24524
+ import { deepStringify } from "@domql/utils";
24814
24525
  var CollabService = class extends BaseService {
24815
24526
  constructor(config) {
24816
24527
  super(config);
@@ -24874,8 +24585,8 @@ var CollabService = class extends BaseService {
24874
24585
  logger(`[Notification] ${title}${message ? ` \u2013 ${message}` : ""}`);
24875
24586
  return;
24876
24587
  }
24877
- case "deepStringifyFunctions": {
24878
- return deepStringifyFunctions(...args2);
24588
+ case "deepStringify": {
24589
+ return deepStringify(...args2);
24879
24590
  }
24880
24591
  default:
24881
24592
  return {};
@@ -24910,49 +24621,57 @@ var CollabService = class extends BaseService {
24910
24621
  if (this._client) {
24911
24622
  await this.disconnect();
24912
24623
  }
24913
- this._client = new CollabClient({
24914
- jwt,
24915
- projectId,
24916
- branch,
24917
- live: Boolean(pro)
24918
- });
24919
- await new Promise((resolve) => {
24920
- var _a2, _b2;
24921
- if ((_a2 = this._client.socket) == null ? void 0 : _a2.connected) {
24922
- resolve();
24923
- } else {
24924
- (_b2 = this._client.socket) == null ? void 0 : _b2.once("connect", resolve);
24925
- }
24926
- });
24927
- (_b = this._client.socket) == null ? void 0 : _b.on("ops", ({ changes }) => {
24928
- console.log(`ops event`);
24929
- this._stateManager.applyChanges(changes, { fromSocket: true });
24930
- });
24931
- (_c = this._client.socket) == null ? void 0 : _c.on("commit", ({ version: version2 }) => {
24932
- if (version2) {
24933
- this._stateManager.setVersion(version2);
24934
- }
24935
- rootBus.emit("checkpoint:done", { version: version2, origin: "auto" });
24936
- });
24937
- (_d = this._client.socket) == null ? void 0 : _d.on("clients", this._handleClientsEvent.bind(this));
24938
- (_e = this._client.socket) == null ? void 0 : _e.on(
24939
- "bundle:done",
24940
- this._handleBundleDoneEvent.bind(this)
24941
- );
24942
- (_f = this._client.socket) == null ? void 0 : _f.on(
24943
- "bundle:error",
24944
- this._handleBundleErrorEvent.bind(this)
24945
- );
24946
- if (this._pendingOps.length) {
24947
- console.log(
24948
- `[CollabService] Flushing ${this._pendingOps.length} offline operation batch(es)`
24949
- );
24950
- this._pendingOps.forEach(({ changes, orders }) => {
24951
- this.socket.emit("ops", { changes, orders, ts: Date.now() });
24624
+ try {
24625
+ this._client = new CollabClient({
24626
+ jwt,
24627
+ projectId,
24628
+ branch,
24629
+ live: Boolean(pro)
24630
+ });
24631
+ await new Promise((resolve) => {
24632
+ var _a2, _b2;
24633
+ if ((_a2 = this._client.socket) == null ? void 0 : _a2.connected) {
24634
+ resolve();
24635
+ } else {
24636
+ (_b2 = this._client.socket) == null ? void 0 : _b2.once("connect", resolve);
24637
+ }
24952
24638
  });
24953
- this._pendingOps.length = 0;
24639
+ console.log("[CollabService] socket connected");
24640
+ (_b = this._client.socket) == null ? void 0 : _b.on("ops", ({ changes }) => {
24641
+ console.log(`ops event`);
24642
+ console.log(changes);
24643
+ this._stateManager.applyChanges(changes, { fromSocket: true });
24644
+ });
24645
+ (_c = this._client.socket) == null ? void 0 : _c.on("commit", ({ version: version2 }) => {
24646
+ if (version2) {
24647
+ this._stateManager.setVersion(version2);
24648
+ }
24649
+ rootBus.emit("checkpoint:done", { version: version2, origin: "auto" });
24650
+ });
24651
+ (_d = this._client.socket) == null ? void 0 : _d.on("clients", this._handleClientsEvent.bind(this));
24652
+ (_e = this._client.socket) == null ? void 0 : _e.on(
24653
+ "bundle:done",
24654
+ this._handleBundleDoneEvent.bind(this)
24655
+ );
24656
+ (_f = this._client.socket) == null ? void 0 : _f.on(
24657
+ "bundle:error",
24658
+ this._handleBundleErrorEvent.bind(this)
24659
+ );
24660
+ if (this._pendingOps.length) {
24661
+ console.log(
24662
+ `[CollabService] Flushing ${this._pendingOps.length} offline operation batch(es)`
24663
+ );
24664
+ this._pendingOps.forEach(({ tuples }) => {
24665
+ this.socket.emit("ops", { changes: tuples, ts: Date.now() });
24666
+ });
24667
+ this._pendingOps.length = 0;
24668
+ }
24669
+ this._connected = true;
24670
+ console.log("[CollabService] Connected to project:", projectId);
24671
+ } catch (err) {
24672
+ console.error("[CollabService] Connection failed:", err);
24673
+ throw err;
24954
24674
  }
24955
- this._connected = true;
24956
24675
  }
24957
24676
  disconnect() {
24958
24677
  var _a;
@@ -24990,128 +24709,24 @@ var CollabService = class extends BaseService {
24990
24709
  }
24991
24710
  /* ---------- data helpers ---------- */
24992
24711
  updateData(tuples, options = {}) {
24993
- var _a, _b;
24712
+ var _a;
24994
24713
  this._ensureStateManager();
24995
24714
  const { isUndo = false, isRedo = false } = options;
24996
24715
  if (!isUndo && !isRedo && !this._isUndoRedo) {
24997
24716
  this._trackForUndo(tuples, options);
24998
24717
  }
24999
- const processedTuples = (() => {
25000
- var _a2;
25001
- try {
25002
- const root = (_a2 = this._stateManager) == null ? void 0 : _a2.root;
25003
- const isPlainObject2 = (o) => o && typeof o === "object" && !Array.isArray(o);
25004
- const getByPath = (state2, path) => {
25005
- if (!state2 || typeof state2.getByPath !== "function") {
25006
- return null;
25007
- }
25008
- try {
25009
- return state2.getByPath(path);
25010
- } catch {
25011
- return null;
25012
- }
25013
- };
25014
- const expandTuple = (t) => {
25015
- const [action, path, value2] = t || [];
25016
- const isSchemaPath = Array.isArray(path) && path[0] === "schema";
25017
- if (action === "delete" || isSchemaPath) {
25018
- return [t];
25019
- }
25020
- const canConsiderExpansion = action === "update" && Array.isArray(path) && (path.length === 1 || path.length === 2) && isPlainObject2(value2);
25021
- if (!canConsiderExpansion) {
25022
- return [t];
25023
- }
25024
- const prev = getByPath(root, path) || {};
25025
- const next = value2 || {};
25026
- if (!isPlainObject2(prev) || !isPlainObject2(next)) {
25027
- return [t];
25028
- }
25029
- const ops = diffJson(prev, next, []);
25030
- if (!ops.length) {
25031
- return [];
25032
- }
25033
- const arr = [];
25034
- for (let j = 0; j < ops.length; j++) {
25035
- const op = ops[j];
25036
- const fullPath = [...path, ...op.path];
25037
- const last2 = fullPath[fullPath.length - 1];
25038
- if (op.action === "set") {
25039
- arr.push(["update", fullPath, op.value]);
25040
- } else if (op.action === "del") {
25041
- if (last2 !== "__order") {
25042
- arr.push(["delete", fullPath]);
25043
- }
25044
- }
25045
- }
25046
- return arr;
25047
- };
25048
- const minimizeTuples = (inputTuples) => {
25049
- const out = [];
25050
- for (let i = 0; i < inputTuples.length; i++) {
25051
- const expanded = expandTuple(inputTuples[i]);
25052
- for (let k = 0; k < expanded.length; k++) {
25053
- const tuple = expanded[k];
25054
- const isDelete = Array.isArray(tuple) && tuple[0] === "delete";
25055
- const isOrderKey = isDelete && Array.isArray(tuple[1]) && tuple[1][tuple[1].length - 1] === "__order";
25056
- if (!isOrderKey) {
25057
- out.push(tuple);
25058
- }
25059
- }
25060
- }
25061
- console.log(`Minimized tuples`, out);
25062
- return out;
25063
- };
25064
- console.log(`Processing tuples`, tuples);
25065
- return minimizeTuples(tuples);
25066
- } catch (err) {
25067
- console.warn(
25068
- "[CollabService] Minimal diff expansion failed \u2013 using original tuples",
25069
- err
25070
- );
25071
- return tuples;
25072
- }
25073
- })();
25074
24718
  if (options.append && options.append.length) {
25075
- processedTuples.push(...options.append);
24719
+ tuples.push(...options.append);
25076
24720
  }
25077
24721
  this._stateManager.applyChanges(tuples, { ...options });
25078
- const state = (_a = this._stateManager) == null ? void 0 : _a.root;
25079
- const el = state == null ? void 0 : state.__element;
25080
- const orders = computeOrdersForTuples(state, processedTuples);
25081
- const stringifiedGranularTuples = (el == null ? void 0 : el.call) ? el.call(
25082
- "deepStringifyFunctions",
25083
- processedTuples,
25084
- Array.isArray(processedTuples) ? [] : {}
25085
- ) : deepStringifyFunctions(
25086
- processedTuples,
25087
- Array.isArray(processedTuples) ? [] : {}
25088
- );
25089
- const stringifiedTuples = (el == null ? void 0 : el.call) ? el.call(
25090
- "deepStringifyFunctions",
25091
- tuples,
25092
- Array.isArray(tuples) ? [] : {}
25093
- ) : deepStringifyFunctions(
25094
- tuples,
25095
- Array.isArray(tuples) ? [] : {}
25096
- );
24722
+ tuples = deepStringify(tuples, []);
25097
24723
  if (!this.isConnected()) {
25098
24724
  console.warn("[CollabService] Not connected, queuing real-time update");
25099
- this._pendingOps.push({ changes: stringifiedTuples, granularChanges: stringifiedGranularTuples, orders, options });
24725
+ this._pendingOps.push({ tuples, options });
25100
24726
  return;
25101
24727
  }
25102
- if ((_b = this.socket) == null ? void 0 : _b.connected) {
25103
- console.log("[CollabService] Sending operations to the backend", {
25104
- changes: stringifiedTuples,
25105
- granularChanges: stringifiedGranularTuples,
25106
- orders,
25107
- ts: Date.now()
25108
- });
25109
- this.socket.emit("ops", {
25110
- changes: stringifiedTuples,
25111
- granularChanges: stringifiedGranularTuples,
25112
- orders,
25113
- ts: Date.now()
25114
- });
24728
+ if ((_a = this.socket) == null ? void 0 : _a.connected) {
24729
+ this.socket.emit("ops", { changes: tuples, ts: Date.now() });
25115
24730
  }
25116
24731
  return { success: true };
25117
24732
  }
@@ -25252,7 +24867,7 @@ var CollabService = class extends BaseService {
25252
24867
  const updatedOpts = { ...opts, skipComponentsChangedEvent: true };
25253
24868
  return this.updateData(tuples, updatedOpts);
25254
24869
  } catch (error) {
25255
- throw new Error(`Failed to add item: ${error.message}`, { cause: error });
24870
+ throw new Error(`Failed to add item: ${error.message}`);
25256
24871
  }
25257
24872
  }
25258
24873
  addMultipleItems(items, opts = {}) {
@@ -25281,7 +24896,7 @@ var CollabService = class extends BaseService {
25281
24896
  title: "Failed to add item",
25282
24897
  message: error.message
25283
24898
  });
25284
- throw new Error(`Failed to add item: ${error.message}`, { cause: error });
24899
+ throw new Error(`Failed to add item: ${error.message}`);
25285
24900
  }
25286
24901
  }
25287
24902
  updateItem(type, data2, opts = {}) {
@@ -25303,9 +24918,7 @@ var CollabService = class extends BaseService {
25303
24918
  title: "Failed to update item",
25304
24919
  message: error.message
25305
24920
  });
25306
- throw new Error(`Failed to update item: ${error.message}`, {
25307
- cause: error
25308
- });
24921
+ throw new Error(`Failed to update item: ${error.message}`);
25309
24922
  }
25310
24923
  }
25311
24924
  deleteItem(type, key, opts = {}) {
@@ -25330,9 +24943,7 @@ var CollabService = class extends BaseService {
25330
24943
  title: "Failed to delete item",
25331
24944
  message: error.message
25332
24945
  });
25333
- throw new Error(`Failed to delete item: ${error.message}`, {
25334
- cause: error
25335
- });
24946
+ throw new Error(`Failed to delete item: ${error.message}`);
25336
24947
  }
25337
24948
  }
25338
24949
  /* ---------- socket event helpers ---------- */