@symbo.ls/sdk 2.32.0 → 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 +18 -114
  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 +300 -907
  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 +50 -452
  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 -375
  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 +295 -884
  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 +19 -115
  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 +19 -142
  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 -295
  77. package/dist/esm/services/ScreenshotService.js +0 -992
  78. package/dist/esm/utils/ordering.js +0 -277
  79. package/dist/node/services/ScreenshotService.js +0 -285
  80. package/dist/node/utils/ordering.js +0 -276
  81. package/src/services/ScreenshotService.js +0 -258
  82. package/src/utils/ordering.js +0 -240
@@ -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,282 +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 extractTopLevelKeysFromCode(code) {
24680
- const src = normaliseSchemaCode(code);
24681
- if (!src) {
24682
- return [];
24683
- }
24684
- const idx = src.indexOf("export default");
24685
- if (idx === -1) {
24686
- return [];
24687
- }
24688
- let i = src.indexOf("{", idx);
24689
- if (i === -1) {
24690
- return [];
24691
- }
24692
- const keys2 = [];
24693
- let depth = 0;
24694
- let inStr = false;
24695
- let strCh = "";
24696
- let inEsc = false;
24697
- for (; i < src.length; i++) {
24698
- const ch = src[i];
24699
- if (inStr) {
24700
- if (inEsc) {
24701
- inEsc = false;
24702
- } else if (ch === "\\") {
24703
- inEsc = true;
24704
- } else if (ch === strCh) {
24705
- inStr = false;
24706
- strCh = "";
24707
- }
24708
- continue;
24709
- }
24710
- if (ch === '"' || ch === "'" || ch === "`") {
24711
- inStr = true;
24712
- strCh = ch;
24713
- continue;
24714
- }
24715
- if (ch === "{") {
24716
- depth++;
24717
- continue;
24718
- }
24719
- if (ch === "}") {
24720
- depth--;
24721
- if (depth === 0) {
24722
- break;
24723
- }
24724
- continue;
24725
- }
24726
- if (depth !== 1) {
24727
- continue;
24728
- }
24729
- if (/[A-Za-z_$]/u.test(ch)) {
24730
- let j = i;
24731
- while (j < src.length && /[A-Za-z0-9_$]/u.test(src[j])) {
24732
- j++;
24733
- }
24734
- let k = j;
24735
- while (k < src.length && /\s/u.test(src[k])) {
24736
- k++;
24737
- }
24738
- if (src[k] === ":") {
24739
- const key = src.slice(i, j);
24740
- keys2.push(key);
24741
- }
24742
- i = j;
24743
- continue;
24744
- }
24745
- }
24746
- if (!keys2.length) {
24747
- const bodyStart = src.indexOf("{", idx);
24748
- const bodyEnd = src.lastIndexOf("}");
24749
- if (bodyStart === -1 || bodyEnd === -1 || bodyEnd <= bodyStart) {
24750
- return Array.from(new Set(keys2));
24751
- }
24752
- const body = src.slice(bodyStart + 1, bodyEnd);
24753
- const re2 = /(?:[A-Za-z_$][A-Za-z0-9_$]*|"[^"]+"|'[^']+')\s*:/gu;
24754
- for (const m of body.matchAll(re2)) {
24755
- const raw = m[0].split(":")[0].trim();
24756
- const key = raw[0] === '"' || raw[0] === "'" ? raw.slice(1, -1) : raw;
24757
- keys2.push(key);
24758
- }
24759
- }
24760
- return Array.from(new Set(keys2));
24761
- }
24762
- function computeOrdersForTuples(root, tuples = []) {
24763
- const preferredOrderMap = /* @__PURE__ */ new Map();
24764
- for (let i = 0; i < tuples.length; i++) {
24765
- const t = tuples[i];
24766
- if (!Array.isArray(t)) {
24767
- continue;
24768
- }
24769
- const [action, path, value2] = t;
24770
- const p = normalizePath(path);
24771
- if (action !== "update" || !Array.isArray(p) || p.length < 3) {
24772
- continue;
24773
- }
24774
- if (p[0] !== "schema") {
24775
- continue;
24776
- }
24777
- const [, type, key] = p;
24778
- const containerPath = [type, key];
24779
- const uses = value2 && Array.isArray(value2.uses) ? value2.uses : null;
24780
- const code = value2 && value2.code;
24781
- const obj = (() => {
24782
- try {
24783
- return root && typeof root.getByPath === "function" ? root.getByPath(containerPath) : null;
24784
- } catch {
24785
- return null;
24786
- }
24787
- })();
24788
- if (!obj) {
24789
- continue;
24790
- }
24791
- const present = new Set(Object.keys(obj));
24792
- const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
24793
- const codeKeys = extractTopLevelKeysFromCode(code);
24794
- let resolved = [];
24795
- if (Array.isArray(codeKeys) && codeKeys.length) {
24796
- resolved = codeKeys.filter((k) => present.has(k) && !EXCLUDE_KEYS.has(k));
24797
- }
24798
- if (resolved.length && Array.isArray(uses) && uses.length) {
24799
- for (let u = 0; u < uses.length; u++) {
24800
- const keyName = uses[u];
24801
- if (present.has(keyName) && !EXCLUDE_KEYS.has(keyName) && !resolved.includes(keyName)) {
24802
- resolved.push(keyName);
24803
- }
24804
- }
24805
- }
24806
- if (resolved.length) {
24807
- preferredOrderMap.set(JSON.stringify(containerPath), { path: containerPath, keys: resolved });
24808
- }
24809
- }
24810
- const parents = getParentPathsFromTuples(tuples);
24811
- const orders = [];
24812
- const seen = /* @__PURE__ */ new Set();
24813
- preferredOrderMap.forEach((v) => {
24814
- const k = JSON.stringify(v.path);
24815
- if (!seen.has(k)) {
24816
- seen.add(k);
24817
- orders.push(v);
24818
- }
24819
- });
24820
- const fallbackOrders = computeOrdersFromState(root, parents);
24821
- for (let i = 0; i < fallbackOrders.length; i++) {
24822
- const v = fallbackOrders[i];
24823
- const k = JSON.stringify(v.path);
24824
- if (!seen.has(k)) {
24825
- seen.add(k);
24826
- orders.push(v);
24827
- }
24828
- }
24829
- return orders;
24830
- }
24831
-
24832
- // src/services/CollabService.js
24524
+ import { deepStringify } from "@domql/utils";
24833
24525
  var CollabService = class extends BaseService {
24834
24526
  constructor(config) {
24835
24527
  super(config);
@@ -24893,8 +24585,8 @@ var CollabService = class extends BaseService {
24893
24585
  logger(`[Notification] ${title}${message ? ` \u2013 ${message}` : ""}`);
24894
24586
  return;
24895
24587
  }
24896
- case "deepStringifyFunctions": {
24897
- return deepStringifyFunctions(...args2);
24588
+ case "deepStringify": {
24589
+ return deepStringify(...args2);
24898
24590
  }
24899
24591
  default:
24900
24592
  return {};
@@ -24944,8 +24636,10 @@ var CollabService = class extends BaseService {
24944
24636
  (_b2 = this._client.socket) == null ? void 0 : _b2.once("connect", resolve);
24945
24637
  }
24946
24638
  });
24639
+ console.log("[CollabService] socket connected");
24947
24640
  (_b = this._client.socket) == null ? void 0 : _b.on("ops", ({ changes }) => {
24948
24641
  console.log(`ops event`);
24642
+ console.log(changes);
24949
24643
  this._stateManager.applyChanges(changes, { fromSocket: true });
24950
24644
  });
24951
24645
  (_c = this._client.socket) == null ? void 0 : _c.on("commit", ({ version: version2 }) => {
@@ -24967,13 +24661,15 @@ var CollabService = class extends BaseService {
24967
24661
  console.log(
24968
24662
  `[CollabService] Flushing ${this._pendingOps.length} offline operation batch(es)`
24969
24663
  );
24970
- this._pendingOps.forEach(({ changes, orders }) => {
24971
- this.socket.emit("ops", { changes, orders, ts: Date.now() });
24664
+ this._pendingOps.forEach(({ tuples }) => {
24665
+ this.socket.emit("ops", { changes: tuples, ts: Date.now() });
24972
24666
  });
24973
24667
  this._pendingOps.length = 0;
24974
24668
  }
24975
24669
  this._connected = true;
24670
+ console.log("[CollabService] Connected to project:", projectId);
24976
24671
  } catch (err) {
24672
+ console.error("[CollabService] Connection failed:", err);
24977
24673
  throw err;
24978
24674
  }
24979
24675
  }
@@ -25013,118 +24709,24 @@ var CollabService = class extends BaseService {
25013
24709
  }
25014
24710
  /* ---------- data helpers ---------- */
25015
24711
  updateData(tuples, options = {}) {
25016
- var _a, _b;
24712
+ var _a;
25017
24713
  this._ensureStateManager();
25018
24714
  const { isUndo = false, isRedo = false } = options;
25019
24715
  if (!isUndo && !isRedo && !this._isUndoRedo) {
25020
24716
  this._trackForUndo(tuples, options);
25021
24717
  }
25022
- const processedTuples = (() => {
25023
- var _a2;
25024
- try {
25025
- const root = (_a2 = this._stateManager) == null ? void 0 : _a2.root;
25026
- const isPlainObject2 = (o) => o && typeof o === "object" && !Array.isArray(o);
25027
- const getByPath = (state2, path) => {
25028
- if (!state2 || typeof state2.getByPath !== "function") {
25029
- return null;
25030
- }
25031
- try {
25032
- return state2.getByPath(path);
25033
- } catch {
25034
- return null;
25035
- }
25036
- };
25037
- const expandTuple = (t) => {
25038
- const [action, path, value2] = t || [];
25039
- const isSchemaPath = Array.isArray(path) && path[0] === "schema";
25040
- if (action === "delete" || isSchemaPath) {
25041
- return [t];
25042
- }
25043
- const canConsiderExpansion = action === "update" && Array.isArray(path) && (path.length === 1 || path.length === 2) && isPlainObject2(value2);
25044
- if (!canConsiderExpansion) {
25045
- return [t];
25046
- }
25047
- const prev = getByPath(root, path) || {};
25048
- const next = value2 || {};
25049
- if (!isPlainObject2(prev) || !isPlainObject2(next)) {
25050
- return [t];
25051
- }
25052
- const ops = diffJson(prev, next, []);
25053
- if (!ops.length) {
25054
- return [];
25055
- }
25056
- const arr = [];
25057
- for (let j = 0; j < ops.length; j++) {
25058
- const op = ops[j];
25059
- const fullPath = [...path, ...op.path];
25060
- const last2 = fullPath[fullPath.length - 1];
25061
- if (op.action === "set") {
25062
- arr.push(["update", fullPath, op.value]);
25063
- } else if (op.action === "del") {
25064
- if (last2 !== "__order") {
25065
- arr.push(["delete", fullPath]);
25066
- }
25067
- }
25068
- }
25069
- return arr;
25070
- };
25071
- const minimizeTuples = (inputTuples) => {
25072
- const out = [];
25073
- for (let i = 0; i < inputTuples.length; i++) {
25074
- const expanded = expandTuple(inputTuples[i]);
25075
- for (let k = 0; k < expanded.length; k++) {
25076
- const tuple = expanded[k];
25077
- const isDelete = Array.isArray(tuple) && tuple[0] === "delete";
25078
- const isOrderKey = isDelete && Array.isArray(tuple[1]) && tuple[1][tuple[1].length - 1] === "__order";
25079
- if (!isOrderKey) {
25080
- out.push(tuple);
25081
- }
25082
- }
25083
- }
25084
- console.log(`Minimized tuples`, out);
25085
- return out;
25086
- };
25087
- console.log(`Processing tuples`, tuples);
25088
- return minimizeTuples(tuples);
25089
- } catch (err) {
25090
- console.warn(
25091
- "[CollabService] Minimal diff expansion failed \u2013 using original tuples",
25092
- err
25093
- );
25094
- return tuples;
25095
- }
25096
- })();
25097
24718
  if (options.append && options.append.length) {
25098
- processedTuples.push(...options.append);
24719
+ tuples.push(...options.append);
25099
24720
  }
25100
24721
  this._stateManager.applyChanges(tuples, { ...options });
25101
- const state = (_a = this._stateManager) == null ? void 0 : _a.root;
25102
- const el = state == null ? void 0 : state.__element;
25103
- const orders = computeOrdersForTuples(state, processedTuples);
25104
- const stringifiedTuples = (el == null ? void 0 : el.call) ? el.call(
25105
- "deepStringifyFunctions",
25106
- processedTuples,
25107
- Array.isArray(processedTuples) ? [] : {}
25108
- ) : deepStringifyFunctions(
25109
- processedTuples,
25110
- Array.isArray(processedTuples) ? [] : {}
25111
- );
24722
+ tuples = deepStringify(tuples, []);
25112
24723
  if (!this.isConnected()) {
25113
24724
  console.warn("[CollabService] Not connected, queuing real-time update");
25114
- this._pendingOps.push({ changes: stringifiedTuples, orders, options });
24725
+ this._pendingOps.push({ tuples, options });
25115
24726
  return;
25116
24727
  }
25117
- if ((_b = this.socket) == null ? void 0 : _b.connected) {
25118
- console.log("[CollabService] Sending operations to the backend", {
25119
- changes: stringifiedTuples,
25120
- orders,
25121
- ts: Date.now()
25122
- });
25123
- this.socket.emit("ops", {
25124
- changes: stringifiedTuples,
25125
- orders,
25126
- ts: Date.now()
25127
- });
24728
+ if ((_a = this.socket) == null ? void 0 : _a.connected) {
24729
+ this.socket.emit("ops", { changes: tuples, ts: Date.now() });
25128
24730
  }
25129
24731
  return { success: true };
25130
24732
  }
@@ -25265,7 +24867,7 @@ var CollabService = class extends BaseService {
25265
24867
  const updatedOpts = { ...opts, skipComponentsChangedEvent: true };
25266
24868
  return this.updateData(tuples, updatedOpts);
25267
24869
  } catch (error) {
25268
- throw new Error(`Failed to add item: ${error.message}`, { cause: error });
24870
+ throw new Error(`Failed to add item: ${error.message}`);
25269
24871
  }
25270
24872
  }
25271
24873
  addMultipleItems(items, opts = {}) {
@@ -25294,7 +24896,7 @@ var CollabService = class extends BaseService {
25294
24896
  title: "Failed to add item",
25295
24897
  message: error.message
25296
24898
  });
25297
- throw new Error(`Failed to add item: ${error.message}`, { cause: error });
24899
+ throw new Error(`Failed to add item: ${error.message}`);
25298
24900
  }
25299
24901
  }
25300
24902
  updateItem(type, data2, opts = {}) {
@@ -25316,9 +24918,7 @@ var CollabService = class extends BaseService {
25316
24918
  title: "Failed to update item",
25317
24919
  message: error.message
25318
24920
  });
25319
- throw new Error(`Failed to update item: ${error.message}`, {
25320
- cause: error
25321
- });
24921
+ throw new Error(`Failed to update item: ${error.message}`);
25322
24922
  }
25323
24923
  }
25324
24924
  deleteItem(type, key, opts = {}) {
@@ -25343,9 +24943,7 @@ var CollabService = class extends BaseService {
25343
24943
  title: "Failed to delete item",
25344
24944
  message: error.message
25345
24945
  });
25346
- throw new Error(`Failed to delete item: ${error.message}`, {
25347
- cause: error
25348
- });
24946
+ throw new Error(`Failed to delete item: ${error.message}`);
25349
24947
  }
25350
24948
  }
25351
24949
  /* ---------- socket event helpers ---------- */