@symbo.ls/sdk 2.32.2 → 2.32.5

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 (90) hide show
  1. package/dist/cjs/config/environment.js +43 -8
  2. package/dist/cjs/index.js +12 -4
  3. package/dist/cjs/services/AdminService.js +4 -4
  4. package/dist/cjs/services/AuthService.js +36 -149
  5. package/dist/cjs/services/BaseService.js +5 -18
  6. package/dist/cjs/services/BranchService.js +10 -10
  7. package/dist/cjs/services/CollabService.js +94 -61
  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 +45 -35
  14. package/dist/cjs/services/PullRequestService.js +7 -7
  15. package/dist/cjs/services/ScreenshotService.js +304 -0
  16. package/dist/cjs/services/SubscriptionService.js +14 -14
  17. package/dist/cjs/services/index.js +4 -0
  18. package/dist/cjs/utils/TokenManager.js +16 -5
  19. package/dist/cjs/utils/changePreprocessor.js +134 -0
  20. package/dist/cjs/utils/jsonDiff.js +46 -4
  21. package/dist/cjs/utils/ordering.js +274 -0
  22. package/dist/cjs/utils/services.js +14 -1
  23. package/dist/esm/config/environment.js +43 -8
  24. package/dist/esm/index.js +1099 -417
  25. package/dist/esm/services/AdminService.js +68 -35
  26. package/dist/esm/services/AuthService.js +100 -168
  27. package/dist/esm/services/BaseService.js +64 -31
  28. package/dist/esm/services/BranchService.js +74 -41
  29. package/dist/esm/services/CollabService.js +570 -97
  30. package/dist/esm/services/CoreService.js +83 -50
  31. package/dist/esm/services/DnsService.js +68 -35
  32. package/dist/esm/services/FileService.js +66 -33
  33. package/dist/esm/services/PaymentService.js +66 -33
  34. package/dist/esm/services/PlanService.js +76 -43
  35. package/dist/esm/services/ProjectService.js +547 -66
  36. package/dist/esm/services/PullRequestService.js +71 -38
  37. package/dist/esm/services/ScreenshotService.js +992 -0
  38. package/dist/esm/services/SubscriptionService.js +78 -45
  39. package/dist/esm/services/index.js +1076 -412
  40. package/dist/esm/utils/CollabClient.js +89 -12
  41. package/dist/esm/utils/TokenManager.js +16 -5
  42. package/dist/esm/utils/changePreprocessor.js +442 -0
  43. package/dist/esm/utils/jsonDiff.js +46 -4
  44. package/dist/esm/utils/ordering.js +256 -0
  45. package/dist/esm/utils/services.js +14 -1
  46. package/dist/node/config/environment.js +43 -8
  47. package/dist/node/index.js +14 -5
  48. package/dist/node/services/AdminService.js +4 -4
  49. package/dist/node/services/AuthService.js +36 -139
  50. package/dist/node/services/BaseService.js +5 -18
  51. package/dist/node/services/BranchService.js +10 -10
  52. package/dist/node/services/CollabService.js +95 -62
  53. package/dist/node/services/CoreService.js +19 -19
  54. package/dist/node/services/DnsService.js +4 -4
  55. package/dist/node/services/FileService.js +2 -2
  56. package/dist/node/services/PaymentService.js +2 -2
  57. package/dist/node/services/PlanService.js +12 -12
  58. package/dist/node/services/ProjectService.js +45 -35
  59. package/dist/node/services/PullRequestService.js +7 -7
  60. package/dist/node/services/ScreenshotService.js +285 -0
  61. package/dist/node/services/SubscriptionService.js +14 -14
  62. package/dist/node/services/index.js +4 -0
  63. package/dist/node/utils/TokenManager.js +16 -5
  64. package/dist/node/utils/changePreprocessor.js +115 -0
  65. package/dist/node/utils/jsonDiff.js +46 -4
  66. package/dist/node/utils/ordering.js +255 -0
  67. package/dist/node/utils/services.js +14 -1
  68. package/package.json +7 -6
  69. package/src/config/environment.js +48 -9
  70. package/src/index.js +38 -22
  71. package/src/services/AdminService.js +4 -4
  72. package/src/services/AuthService.js +42 -175
  73. package/src/services/BaseService.js +7 -24
  74. package/src/services/BranchService.js +10 -10
  75. package/src/services/CollabService.js +115 -74
  76. package/src/services/CoreService.js +19 -19
  77. package/src/services/DnsService.js +4 -4
  78. package/src/services/FileService.js +2 -2
  79. package/src/services/PaymentService.js +2 -2
  80. package/src/services/PlanService.js +12 -12
  81. package/src/services/ProjectService.js +50 -35
  82. package/src/services/PullRequestService.js +7 -7
  83. package/src/services/ScreenshotService.js +258 -0
  84. package/src/services/SubscriptionService.js +14 -14
  85. package/src/services/index.js +6 -1
  86. package/src/utils/TokenManager.js +19 -5
  87. package/src/utils/changePreprocessor.js +139 -0
  88. package/src/utils/jsonDiff.js +40 -5
  89. package/src/utils/ordering.js +244 -0
  90. package/src/utils/services.js +15 -1
@@ -28,18 +28,28 @@ var CONFIG = {
28
28
  // For based api
29
29
  basedOrg: "symbols",
30
30
  // For based api
31
- githubClientId: "Ov23liHxyWFBxS8f1gnF",
31
+ githubClientId: "Ov23liAFrsR0StbAO6PO",
32
32
  // For github api
33
33
  // Environment-specific feature toggles (override common)
34
34
  features: {
35
35
  betaFeatures: true
36
36
  // Enable beta features in local dev
37
- }
37
+ },
38
+ typesenseCollectionName: "docs",
39
+ typesenseApiKey: "vZya3L2zpq8L6iI5WWMUZJZABvT63VDb",
40
+ typesenseHost: "localhost",
41
+ typesensePort: "8108",
42
+ typesenseProtocol: "http"
38
43
  },
39
44
  development: {
40
45
  socketUrl: "https://dev.api.symbols.app",
41
46
  apiUrl: "https://dev.api.symbols.app",
42
- githubClientId: "Ov23liHxyWFBxS8f1gnF"
47
+ githubClientId: "Ov23liHxyWFBxS8f1gnF",
48
+ typesenseCollectionName: "docs",
49
+ typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
50
+ typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
51
+ typesensePort: "443",
52
+ typesenseProtocol: "https"
43
53
  },
44
54
  testing: {
45
55
  socketUrl: "https://test.api.symbols.app",
@@ -47,12 +57,22 @@ var CONFIG = {
47
57
  basedEnv: "testing",
48
58
  basedProject: "platform-v2-sm",
49
59
  basedOrg: "symbols",
50
- githubClientId: "Ov23liHxyWFBxS8f1gnF"
60
+ githubClientId: "Ov23liHxyWFBxS8f1gnF",
61
+ typesenseCollectionName: "docs",
62
+ typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
63
+ typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
64
+ typesensePort: "443",
65
+ typesenseProtocol: "https"
51
66
  },
52
67
  upcoming: {
53
68
  socketUrl: "https://upcoming.api.symbols.app",
54
69
  apiUrl: "https://upcoming.api.symbols.app",
55
- githubClientId: "Ov23liWF7NvdZ056RV5J"
70
+ githubClientId: "Ov23liWF7NvdZ056RV5J",
71
+ typesenseCollectionName: "docs",
72
+ typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
73
+ typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
74
+ typesensePort: "443",
75
+ typesenseProtocol: "https"
56
76
  },
57
77
  staging: {
58
78
  socketUrl: "https://staging.api.symbols.app",
@@ -60,7 +80,12 @@ var CONFIG = {
60
80
  basedEnv: "staging",
61
81
  basedProject: "platform-v2-sm",
62
82
  basedOrg: "symbols",
63
- githubClientId: "Ov23ligwZDQVD0VfuWNa"
83
+ githubClientId: "Ov23ligwZDQVD0VfuWNa",
84
+ typesenseCollectionName: "docs",
85
+ typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
86
+ typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
87
+ typesensePort: "443",
88
+ typesenseProtocol: "https"
64
89
  },
65
90
  production: {
66
91
  socketUrl: "https://api.symbols.app",
@@ -68,7 +93,12 @@ var CONFIG = {
68
93
  basedEnv: "production",
69
94
  basedProject: "platform-v2-sm",
70
95
  basedOrg: "symbols",
71
- githubClientId: "Ov23liFAlOEIXtX3dBtR"
96
+ githubClientId: "Ov23liFAlOEIXtX3dBtR",
97
+ typesenseCollectionName: "docs",
98
+ typesenseApiKey: "awmcVpbWqZi9IUgmvslp1C5LKDU8tMjA",
99
+ typesenseHost: "tl2qpnwxev4cjm36p-1.a1.typesense.net",
100
+ typesensePort: "443",
101
+ typesenseProtocol: "https"
72
102
  }
73
103
  };
74
104
  var getEnvironment = () => {
@@ -90,6 +120,11 @@ var getConfig = () => {
90
120
  basedProject: process.env.SYMBOLS_APP_BASED_PROJECT || envConfig.basedProject,
91
121
  basedOrg: process.env.SYMBOLS_APP_BASED_ORG || envConfig.basedOrg,
92
122
  githubClientId: process.env.SYMBOLS_APP_GITHUB_CLIENT_ID || envConfig.githubClientId,
123
+ typesenseCollectionName: process.env.TYPESENSE_COLLECTION_NAME || envConfig.typesenseCollectionName,
124
+ typesenseApiKey: process.env.TYPESENSE_API_KEY || envConfig.typesenseApiKey,
125
+ typesenseHost: process.env.TYPESENSE_HOST || envConfig.typesenseHost,
126
+ typesensePort: process.env.TYPESENSE_PORT || envConfig.typesensePort,
127
+ typesenseProtocol: process.env.TYPESENSE_PROTOCOL || envConfig.typesenseProtocol,
93
128
  isDevelopment: isDevelopment(env),
94
129
  isTesting: env === "testing",
95
130
  isStaging: env === "staging",
@@ -109,7 +144,7 @@ var getConfig = () => {
109
144
  );
110
145
  }
111
146
  if (finalConfig.isDevelopment) {
112
- console.log(
147
+ console.warn(
113
148
  "environment in SDK:",
114
149
  env || process.env.NODE_ENV || process.env.NODE_ENV
115
150
  );
@@ -148,7 +183,7 @@ var TokenManager = class {
148
183
  });
149
184
  this.config = {
150
185
  storagePrefix: "symbols_",
151
- storageType: typeof window === "undefined" || process.env.NODE_ENV === "test" ? "memory" : "localStorage",
186
+ storageType: typeof window === "undefined" || process.env.NODE_ENV === "test" || process.env.NODE_ENV === "testing" ? "memory" : "localStorage",
152
187
  // 'localStorage' | 'sessionStorage' | 'memory'
153
188
  refreshBuffer: 60 * 1e3,
154
189
  // Refresh 1 minute before expiry
@@ -188,15 +223,26 @@ var TokenManager = class {
188
223
  if (typeof window === "undefined") {
189
224
  return this._memoryStorage;
190
225
  }
191
- const hasLocalStorage = typeof window.localStorage !== "undefined";
192
- const hasSessionStorage = typeof window.sessionStorage !== "undefined";
226
+ const safeGetStorage = (provider) => {
227
+ try {
228
+ const storage = provider();
229
+ const testKey = `${this.config.storagePrefix}__tm_test__`;
230
+ storage.setItem(testKey, "1");
231
+ storage.removeItem(testKey);
232
+ return storage;
233
+ } catch {
234
+ return null;
235
+ }
236
+ };
237
+ const localStorageInstance = safeGetStorage(() => window.localStorage);
238
+ const sessionStorageInstance = safeGetStorage(() => window.sessionStorage);
193
239
  switch (this.config.storageType) {
194
240
  case "sessionStorage":
195
- return hasSessionStorage ? window.sessionStorage : this._memoryStorage;
241
+ return sessionStorageInstance || this._memoryStorage;
196
242
  case "memory":
197
243
  return this._memoryStorage;
198
244
  default:
199
- return hasLocalStorage ? window.localStorage : this._memoryStorage;
245
+ return localStorageInstance || this._memoryStorage;
200
246
  }
201
247
  }
202
248
  /**
@@ -535,20 +581,10 @@ var BaseService = class {
535
581
  }
536
582
  this._tokenManager = getTokenManager({
537
583
  apiUrl: this._apiUrl,
538
- onTokenRefresh: (tokens) => {
539
- this.updateContext({ authToken: tokens.accessToken });
540
- },
541
- onTokenExpired: () => {
542
- this.updateContext({ authToken: null });
543
- },
544
584
  onTokenError: (error) => {
545
585
  console.error("Token management error:", error);
546
586
  }
547
587
  });
548
- const { authToken } = this._context;
549
- if (authToken && !this._tokenManager.hasTokens()) {
550
- this._tokenManager.setTokens({ access_token: authToken });
551
- }
552
588
  this._setReady();
553
589
  } catch (error) {
554
590
  this._setError(error);
@@ -557,7 +593,9 @@ var BaseService = class {
557
593
  }
558
594
  // Update context
559
595
  updateContext(context) {
560
- this._context = { ...this._context, ...context };
596
+ if (context && typeof context === "object") {
597
+ Object.assign(this._context, context);
598
+ }
561
599
  }
562
600
  // Get service status
563
601
  getStatus() {
@@ -612,11 +650,6 @@ var BaseService = class {
612
650
  error
613
651
  );
614
652
  }
615
- } else if (this._requiresInit(options.methodName)) {
616
- const { authToken } = this._context;
617
- if (authToken) {
618
- defaultHeaders.Authorization = `Bearer ${authToken}`;
619
- }
620
653
  }
621
654
  try {
622
655
  const response = await fetch(url, {
@@ -634,11 +667,11 @@ var BaseService = class {
634
667
  error = await response.json();
635
668
  } catch {
636
669
  }
637
- throw new Error(error.message || error.error || "Request failed");
670
+ throw new Error(error.message || error.error || "Request failed", { cause: error });
638
671
  }
639
672
  return response.status === 204 ? null : response.json();
640
673
  } catch (error) {
641
- throw new Error(`Request failed: ${error.message}`);
674
+ throw new Error(`Request failed: ${error.message}`, { cause: error });
642
675
  }
643
676
  }
644
677
  // Helper method to determine if a method requires initialization
@@ -671,7 +704,448 @@ var BaseService = class {
671
704
  }
672
705
  };
673
706
 
707
+ // src/utils/ordering.js
708
+ function isObjectLike(val) {
709
+ return val && typeof val === "object" && !Array.isArray(val);
710
+ }
711
+ function normalizePath(path) {
712
+ if (Array.isArray(path)) {
713
+ return path;
714
+ }
715
+ if (typeof path === "string") {
716
+ return [path];
717
+ }
718
+ return [];
719
+ }
720
+ function getParentPathsFromTuples(tuples = []) {
721
+ const seen = /* @__PURE__ */ new Set();
722
+ const parents = [];
723
+ const META_KEYS = /* @__PURE__ */ new Set([
724
+ "style",
725
+ "class",
726
+ "text",
727
+ "html",
728
+ "content",
729
+ "data",
730
+ "attr",
731
+ "state",
732
+ "scope",
733
+ "define",
734
+ "on",
735
+ "extend",
736
+ "extends",
737
+ "childExtend",
738
+ "childExtends",
739
+ "children",
740
+ "component",
741
+ "context",
742
+ "tag",
743
+ "key",
744
+ "__order",
745
+ "if"
746
+ ]);
747
+ for (let i = 0; i < tuples.length; i++) {
748
+ const tuple = tuples[i];
749
+ if (!Array.isArray(tuple) || tuple.length < 2) {
750
+ continue;
751
+ }
752
+ const path = normalizePath(tuple[1]);
753
+ if (!path.length) {
754
+ continue;
755
+ }
756
+ if (path[0] === "schema") {
757
+ continue;
758
+ }
759
+ const immediateParent = path.slice(0, -1);
760
+ if (immediateParent.length) {
761
+ const key = JSON.stringify(immediateParent);
762
+ if (!seen.has(key)) {
763
+ seen.add(key);
764
+ parents.push(immediateParent);
765
+ }
766
+ }
767
+ const last = path[path.length - 1];
768
+ if (META_KEYS.has(last) && path.length >= 2) {
769
+ const containerParent = path.slice(0, -2);
770
+ if (containerParent.length) {
771
+ const key2 = JSON.stringify(containerParent);
772
+ if (!seen.has(key2)) {
773
+ seen.add(key2);
774
+ parents.push(containerParent);
775
+ }
776
+ }
777
+ }
778
+ for (let j = 0; j < path.length; j++) {
779
+ const seg = path[j];
780
+ if (!META_KEYS.has(seg)) {
781
+ continue;
782
+ }
783
+ const containerParent2 = path.slice(0, j);
784
+ if (!containerParent2.length) {
785
+ continue;
786
+ }
787
+ const key3 = JSON.stringify(containerParent2);
788
+ if (!seen.has(key3)) {
789
+ seen.add(key3);
790
+ parents.push(containerParent2);
791
+ }
792
+ }
793
+ }
794
+ return parents;
795
+ }
796
+ function computeOrdersFromState(root, parentPaths = []) {
797
+ if (!root || typeof root.getByPath !== "function") {
798
+ return [];
799
+ }
800
+ const orders = [];
801
+ const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
802
+ for (let i = 0; i < parentPaths.length; i++) {
803
+ const parentPath = parentPaths[i];
804
+ const obj = (() => {
805
+ try {
806
+ return root.getByPath(parentPath);
807
+ } catch {
808
+ return null;
809
+ }
810
+ })();
811
+ if (!isObjectLike(obj)) {
812
+ continue;
813
+ }
814
+ const keys = Object.keys(obj).filter((k) => !EXCLUDE_KEYS.has(k));
815
+ orders.push({ path: parentPath, keys });
816
+ }
817
+ return orders;
818
+ }
819
+ function normaliseSchemaCode(code) {
820
+ if (typeof code !== "string" || !code.length) {
821
+ return "";
822
+ }
823
+ return code.replaceAll("/////n", "\n").replaceAll("/////tilde", "`");
824
+ }
825
+ function parseExportedObject(code) {
826
+ const src = normaliseSchemaCode(code);
827
+ if (!src) {
828
+ return null;
829
+ }
830
+ const body = src.replace(/^\s*export\s+default\s*/u, "return ");
831
+ try {
832
+ return new Function(body)();
833
+ } catch {
834
+ return null;
835
+ }
836
+ }
837
+ function extractTopLevelKeysFromCode(code) {
838
+ const obj = parseExportedObject(code);
839
+ if (!obj || typeof obj !== "object") {
840
+ return [];
841
+ }
842
+ return Object.keys(obj);
843
+ }
844
+ function computeOrdersForTuples(root, tuples = []) {
845
+ const pendingChildrenByContainer = /* @__PURE__ */ new Map();
846
+ for (let i = 0; i < tuples.length; i++) {
847
+ const t = tuples[i];
848
+ if (!Array.isArray(t)) {
849
+ continue;
850
+ }
851
+ const [action, path] = t;
852
+ const p = normalizePath(path);
853
+ if (!Array.isArray(p) || p.length < 3) {
854
+ continue;
855
+ }
856
+ if (p[0] === "schema") {
857
+ continue;
858
+ }
859
+ const [typeName, containerKey, childKey] = p;
860
+ const containerPath = [typeName, containerKey];
861
+ const key = JSON.stringify(containerPath);
862
+ if (!pendingChildrenByContainer.has(key)) {
863
+ pendingChildrenByContainer.set(key, /* @__PURE__ */ new Set());
864
+ }
865
+ if (action === "update" || action === "set") {
866
+ pendingChildrenByContainer.get(key).add(childKey);
867
+ }
868
+ }
869
+ const preferredOrderMap = /* @__PURE__ */ new Map();
870
+ for (let i = 0; i < tuples.length; i++) {
871
+ const t = tuples[i];
872
+ if (!Array.isArray(t)) {
873
+ continue;
874
+ }
875
+ const [action, path, value] = t;
876
+ const p = normalizePath(path);
877
+ if (action !== "update" || !Array.isArray(p) || p.length < 3) {
878
+ continue;
879
+ }
880
+ if (p[0] !== "schema") {
881
+ continue;
882
+ }
883
+ const [, type, key] = p;
884
+ const containerPath = [type, key];
885
+ const uses = value && Array.isArray(value.uses) ? value.uses : null;
886
+ const code = value && value.code;
887
+ const obj = (() => {
888
+ try {
889
+ return root && typeof root.getByPath === "function" ? root.getByPath(containerPath) : null;
890
+ } catch {
891
+ return null;
892
+ }
893
+ })();
894
+ if (!obj) {
895
+ continue;
896
+ }
897
+ const present = new Set(Object.keys(obj));
898
+ const EXCLUDE_KEYS = /* @__PURE__ */ new Set(["__order"]);
899
+ const codeKeys = extractTopLevelKeysFromCode(code);
900
+ let resolved = [];
901
+ const pendingKey = JSON.stringify(containerPath);
902
+ const pendingChildren = pendingChildrenByContainer.get(pendingKey) || /* @__PURE__ */ new Set();
903
+ const eligible = /* @__PURE__ */ new Set([...present, ...pendingChildren]);
904
+ if (Array.isArray(codeKeys) && codeKeys.length) {
905
+ resolved = codeKeys.filter((k) => eligible.has(k) && !EXCLUDE_KEYS.has(k));
906
+ }
907
+ if (Array.isArray(uses) && uses.length) {
908
+ for (let u = 0; u < uses.length; u++) {
909
+ const keyName = uses[u];
910
+ if (eligible.has(keyName) && !EXCLUDE_KEYS.has(keyName) && !resolved.includes(keyName)) {
911
+ resolved.push(keyName);
912
+ }
913
+ }
914
+ }
915
+ if (pendingChildren.size) {
916
+ for (const child of pendingChildren) {
917
+ if (!EXCLUDE_KEYS.has(child) && !resolved.includes(child)) {
918
+ resolved.push(child);
919
+ }
920
+ }
921
+ }
922
+ if (resolved.length) {
923
+ preferredOrderMap.set(JSON.stringify(containerPath), { path: containerPath, keys: resolved });
924
+ }
925
+ }
926
+ const parents = getParentPathsFromTuples(tuples);
927
+ const orders = [];
928
+ const seen = /* @__PURE__ */ new Set();
929
+ preferredOrderMap.forEach((v) => {
930
+ const k = JSON.stringify(v.path);
931
+ if (!seen.has(k)) {
932
+ seen.add(k);
933
+ orders.push(v);
934
+ }
935
+ });
936
+ const fallbackOrders = computeOrdersFromState(root, parents);
937
+ for (let i = 0; i < fallbackOrders.length; i++) {
938
+ const v = fallbackOrders[i];
939
+ const k = JSON.stringify(v.path);
940
+ if (seen.has(k)) {
941
+ continue;
942
+ }
943
+ const pending = pendingChildrenByContainer.get(k);
944
+ if (pending && pending.size) {
945
+ const existing = new Set(v.keys);
946
+ for (const child of pending) {
947
+ if (existing.has(child)) {
948
+ continue;
949
+ }
950
+ v.keys.push(child);
951
+ }
952
+ }
953
+ seen.add(k);
954
+ orders.push(v);
955
+ }
956
+ return orders;
957
+ }
958
+
959
+ // src/utils/jsonDiff.js
960
+ function isPlainObject(o) {
961
+ return o && typeof o === "object" && !Array.isArray(o);
962
+ }
963
+ function deepEqual(a, b) {
964
+ if (Object.is(a, b)) {
965
+ return true;
966
+ }
967
+ if (typeof a === "function" && typeof b === "function") {
968
+ try {
969
+ return a.toString() === b.toString();
970
+ } catch {
971
+ return false;
972
+ }
973
+ }
974
+ if (typeof a === "function" || typeof b === "function") {
975
+ return false;
976
+ }
977
+ if (a instanceof Date && b instanceof Date) {
978
+ return a.getTime() === b.getTime();
979
+ }
980
+ if (a instanceof RegExp && b instanceof RegExp) {
981
+ return String(a) === String(b);
982
+ }
983
+ if (Array.isArray(a) && Array.isArray(b)) {
984
+ if (a.length !== b.length) {
985
+ return false;
986
+ }
987
+ for (let i = 0; i < a.length; i++) {
988
+ if (!deepEqual(a[i], b[i])) {
989
+ return false;
990
+ }
991
+ }
992
+ return true;
993
+ }
994
+ if (a && b && typeof a === "object" && typeof b === "object") {
995
+ const aKeys = Object.keys(a);
996
+ const bKeys = Object.keys(b);
997
+ if (aKeys.length !== bKeys.length) {
998
+ return false;
999
+ }
1000
+ for (let i = 0; i < aKeys.length; i++) {
1001
+ const key = aKeys[i];
1002
+ if (!Object.hasOwn(b, key)) {
1003
+ return false;
1004
+ }
1005
+ if (!deepEqual(a[key], b[key])) {
1006
+ return false;
1007
+ }
1008
+ }
1009
+ return true;
1010
+ }
1011
+ return false;
1012
+ }
1013
+ function diffJson(prev, next, prefix = []) {
1014
+ const ops = [];
1015
+ const _prefix = Array.isArray(prefix) ? prefix : [];
1016
+ for (const key in prev) {
1017
+ if (Object.hasOwn(prev, key) && !(key in next)) {
1018
+ ops.push({ action: "del", path: [..._prefix, key] });
1019
+ }
1020
+ }
1021
+ for (const key in next) {
1022
+ if (Object.hasOwn(next, key)) {
1023
+ const pVal = prev == null ? void 0 : prev[key];
1024
+ const nVal = next[key];
1025
+ if (isPlainObject(pVal) && isPlainObject(nVal)) {
1026
+ ops.push(...diffJson(pVal, nVal, [..._prefix, key]));
1027
+ } else if (!deepEqual(pVal, nVal)) {
1028
+ ops.push({ action: "set", path: [..._prefix, key], value: nVal });
1029
+ }
1030
+ }
1031
+ }
1032
+ return ops;
1033
+ }
1034
+
1035
+ // src/utils/changePreprocessor.js
1036
+ function isPlainObject2(val) {
1037
+ return val && typeof val === "object" && !Array.isArray(val);
1038
+ }
1039
+ function getByPathSafe(root, path) {
1040
+ if (!root || typeof root.getByPath !== "function") {
1041
+ return null;
1042
+ }
1043
+ try {
1044
+ return root.getByPath(path);
1045
+ } catch {
1046
+ return null;
1047
+ }
1048
+ }
1049
+ function preprocessChanges(root, tuples = [], options = {}) {
1050
+ const expandTuple = (t) => {
1051
+ const [action, path, value] = t || [];
1052
+ const isSchemaPath = Array.isArray(path) && path[0] === "schema";
1053
+ if (action === "delete") {
1054
+ return [t];
1055
+ }
1056
+ const canConsiderExpansion = action === "update" && Array.isArray(path) && (path.length === 1 || path.length === 2 || isSchemaPath && path.length === 3) && isPlainObject2(value);
1057
+ if (!canConsiderExpansion) {
1058
+ return [t];
1059
+ }
1060
+ const prev = getByPathSafe(root, path) || {};
1061
+ const next = value || {};
1062
+ if (!isPlainObject2(prev) || !isPlainObject2(next)) {
1063
+ return [t];
1064
+ }
1065
+ const ops = diffJson(prev, next, []);
1066
+ if (!ops.length) {
1067
+ return [t];
1068
+ }
1069
+ const out = [];
1070
+ for (let i = 0; i < ops.length; i++) {
1071
+ const op = ops[i];
1072
+ const fullPath = [...path, ...op.path];
1073
+ const last = fullPath[fullPath.length - 1];
1074
+ if (op.action === "set") {
1075
+ out.push(["update", fullPath, op.value]);
1076
+ } else if (op.action === "del") {
1077
+ if (last !== "__order") {
1078
+ out.push(["delete", fullPath]);
1079
+ }
1080
+ }
1081
+ }
1082
+ return out;
1083
+ };
1084
+ const minimizeTuples = (input) => {
1085
+ const out = [];
1086
+ const seen2 = /* @__PURE__ */ new Set();
1087
+ for (let i = 0; i < input.length; i++) {
1088
+ const expanded = expandTuple(input[i]);
1089
+ for (let k = 0; k < expanded.length; k++) {
1090
+ const tuple = expanded[k];
1091
+ const isDelete = Array.isArray(tuple) && tuple[0] === "delete";
1092
+ const isOrderKey = isDelete && Array.isArray(tuple[1]) && tuple[1][tuple[1].length - 1] === "__order";
1093
+ if (!isOrderKey) {
1094
+ const key = JSON.stringify(tuple);
1095
+ if (!seen2.has(key)) {
1096
+ seen2.add(key);
1097
+ out.push(tuple);
1098
+ }
1099
+ }
1100
+ }
1101
+ }
1102
+ return out;
1103
+ };
1104
+ const granularChanges = (() => {
1105
+ try {
1106
+ const res = minimizeTuples(tuples);
1107
+ if (options.append && options.append.length) {
1108
+ res.push(...options.append);
1109
+ }
1110
+ return res;
1111
+ } catch {
1112
+ return Array.isArray(tuples) ? tuples.slice() : [];
1113
+ }
1114
+ })();
1115
+ const baseOrders = computeOrdersForTuples(root, granularChanges);
1116
+ const preferOrdersMap = /* @__PURE__ */ new Map();
1117
+ for (let i = 0; i < tuples.length; i++) {
1118
+ const t = tuples[i];
1119
+ if (!Array.isArray(t) || t.length < 3) {
1120
+ continue;
1121
+ }
1122
+ const [action, path, value] = t;
1123
+ if (action !== "update" || !Array.isArray(path) || path.length !== 1 && path.length !== 2 || !isPlainObject2(value)) {
1124
+ continue;
1125
+ }
1126
+ const keys = Object.keys(value).filter((k) => k !== "__order");
1127
+ const key = JSON.stringify(path);
1128
+ preferOrdersMap.set(key, { path, keys });
1129
+ }
1130
+ const mergedOrders = [];
1131
+ const seen = /* @__PURE__ */ new Set();
1132
+ preferOrdersMap.forEach((v, k) => {
1133
+ seen.add(k);
1134
+ mergedOrders.push(v);
1135
+ });
1136
+ for (let i = 0; i < baseOrders.length; i++) {
1137
+ const v = baseOrders[i];
1138
+ const k = JSON.stringify(v.path);
1139
+ if (!seen.has(k)) {
1140
+ seen.add(k);
1141
+ mergedOrders.push(v);
1142
+ }
1143
+ }
1144
+ return { granularChanges, orders: mergedOrders };
1145
+ }
1146
+
674
1147
  // src/services/ProjectService.js
1148
+ import { deepStringifyFunctions } from "@domql/utils";
675
1149
  var ProjectService = class extends BaseService {
676
1150
  // ==================== PROJECT METHODS ====================
677
1151
  async createProject(projectData) {
@@ -687,7 +1161,7 @@ var ProjectService = class extends BaseService {
687
1161
  }
688
1162
  throw new Error(response.message);
689
1163
  } catch (error) {
690
- throw new Error(`Failed to create project: ${error.message}`);
1164
+ throw new Error(`Failed to create project: ${error.message}`, { cause: error });
691
1165
  }
692
1166
  }
693
1167
  async getProjects(params = {}) {
@@ -710,7 +1184,7 @@ var ProjectService = class extends BaseService {
710
1184
  }
711
1185
  throw new Error(response.message);
712
1186
  } catch (error) {
713
- throw new Error(`Failed to get projects: ${error.message}`);
1187
+ throw new Error(`Failed to get projects: ${error.message}`, { cause: error });
714
1188
  }
715
1189
  }
716
1190
  /**
@@ -741,7 +1215,7 @@ var ProjectService = class extends BaseService {
741
1215
  }
742
1216
  throw new Error(response.message);
743
1217
  } catch (error) {
744
- throw new Error(`Failed to list public projects: ${error.message}`);
1218
+ throw new Error(`Failed to list public projects: ${error.message}`, { cause: error });
745
1219
  }
746
1220
  }
747
1221
  async getProject(projectId) {
@@ -763,7 +1237,7 @@ var ProjectService = class extends BaseService {
763
1237
  }
764
1238
  throw new Error(response.message);
765
1239
  } catch (error) {
766
- throw new Error(`Failed to get project: ${error.message}`);
1240
+ throw new Error(`Failed to get project: ${error.message}`, { cause: error });
767
1241
  }
768
1242
  }
769
1243
  /**
@@ -788,7 +1262,7 @@ var ProjectService = class extends BaseService {
788
1262
  }
789
1263
  throw new Error(response.message);
790
1264
  } catch (error) {
791
- throw new Error(`Failed to get public project: ${error.message}`);
1265
+ throw new Error(`Failed to get public project: ${error.message}`, { cause: error });
792
1266
  }
793
1267
  }
794
1268
  async getProjectByKey(key) {
@@ -810,7 +1284,7 @@ var ProjectService = class extends BaseService {
810
1284
  }
811
1285
  throw new Error(response.message);
812
1286
  } catch (error) {
813
- throw new Error(`Failed to get project by key: ${error.message}`);
1287
+ throw new Error(`Failed to get project by key: ${error.message}`, { cause: error });
814
1288
  }
815
1289
  }
816
1290
  /**
@@ -844,7 +1318,7 @@ var ProjectService = class extends BaseService {
844
1318
  }
845
1319
  throw new Error(response.message);
846
1320
  } catch (error) {
847
- throw new Error(`Failed to get project data by key: ${error.message}`);
1321
+ throw new Error(`Failed to get project data by key: ${error.message}`, { cause: error });
848
1322
  }
849
1323
  }
850
1324
  async updateProject(projectId, data) {
@@ -863,7 +1337,7 @@ var ProjectService = class extends BaseService {
863
1337
  }
864
1338
  throw new Error(response.message);
865
1339
  } catch (error) {
866
- throw new Error(`Failed to update project: ${error.message}`);
1340
+ throw new Error(`Failed to update project: ${error.message}`, { cause: error });
867
1341
  }
868
1342
  }
869
1343
  async updateProjectComponents(projectId, components) {
@@ -885,7 +1359,7 @@ var ProjectService = class extends BaseService {
885
1359
  }
886
1360
  throw new Error(response.message);
887
1361
  } catch (error) {
888
- throw new Error(`Failed to update project components: ${error.message}`);
1362
+ throw new Error(`Failed to update project components: ${error.message}`, { cause: error });
889
1363
  }
890
1364
  }
891
1365
  async updateProjectSettings(projectId, settings) {
@@ -904,7 +1378,7 @@ var ProjectService = class extends BaseService {
904
1378
  }
905
1379
  throw new Error(response.message);
906
1380
  } catch (error) {
907
- throw new Error(`Failed to update project settings: ${error.message}`);
1381
+ throw new Error(`Failed to update project settings: ${error.message}`, { cause: error });
908
1382
  }
909
1383
  }
910
1384
  async updateProjectName(projectId, name) {
@@ -923,7 +1397,7 @@ var ProjectService = class extends BaseService {
923
1397
  }
924
1398
  throw new Error(response.message);
925
1399
  } catch (error) {
926
- throw new Error(`Failed to update project name: ${error.message}`);
1400
+ throw new Error(`Failed to update project name: ${error.message}`, { cause: error });
927
1401
  }
928
1402
  }
929
1403
  async updateProjectPackage(projectId, pkg) {
@@ -942,7 +1416,7 @@ var ProjectService = class extends BaseService {
942
1416
  }
943
1417
  throw new Error(response.message);
944
1418
  } catch (error) {
945
- throw new Error(`Failed to update project package: ${error.message}`);
1419
+ throw new Error(`Failed to update project package: ${error.message}`, { cause: error });
946
1420
  }
947
1421
  }
948
1422
  async duplicateProject(projectId, newName, newKey, targetUserId) {
@@ -961,7 +1435,7 @@ var ProjectService = class extends BaseService {
961
1435
  }
962
1436
  throw new Error(response.message);
963
1437
  } catch (error) {
964
- throw new Error(`Failed to duplicate project: ${error.message}`);
1438
+ throw new Error(`Failed to duplicate project: ${error.message}`, { cause: error });
965
1439
  }
966
1440
  }
967
1441
  async removeProject(projectId) {
@@ -979,7 +1453,7 @@ var ProjectService = class extends BaseService {
979
1453
  }
980
1454
  throw new Error(response.message);
981
1455
  } catch (error) {
982
- throw new Error(`Failed to remove project: ${error.message}`);
1456
+ throw new Error(`Failed to remove project: ${error.message}`, { cause: error });
983
1457
  }
984
1458
  }
985
1459
  async checkProjectKeyAvailability(key) {
@@ -998,7 +1472,8 @@ var ProjectService = class extends BaseService {
998
1472
  throw new Error(response.message);
999
1473
  } catch (error) {
1000
1474
  throw new Error(
1001
- `Failed to check project key availability: ${error.message}`
1475
+ `Failed to check project key availability: ${error.message}`,
1476
+ { cause: error }
1002
1477
  );
1003
1478
  }
1004
1479
  }
@@ -1018,7 +1493,7 @@ var ProjectService = class extends BaseService {
1018
1493
  }
1019
1494
  throw new Error(response.message);
1020
1495
  } catch (error) {
1021
- throw new Error(`Failed to get project members: ${error.message}`);
1496
+ throw new Error(`Failed to get project members: ${error.message}`, { cause: error });
1022
1497
  }
1023
1498
  }
1024
1499
  async inviteMember(projectId, email, role = "guest", options = {}) {
@@ -1047,7 +1522,7 @@ var ProjectService = class extends BaseService {
1047
1522
  }
1048
1523
  throw new Error(response.message);
1049
1524
  } catch (error) {
1050
- throw new Error(`Failed to invite member: ${error.message}`);
1525
+ throw new Error(`Failed to invite member: ${error.message}`, { cause: error });
1051
1526
  }
1052
1527
  }
1053
1528
  async acceptInvite(token) {
@@ -1066,7 +1541,7 @@ var ProjectService = class extends BaseService {
1066
1541
  }
1067
1542
  throw new Error(response.message);
1068
1543
  } catch (error) {
1069
- throw new Error(`Failed to accept invite: ${error.message}`);
1544
+ throw new Error(`Failed to accept invite: ${error.message}`, { cause: error });
1070
1545
  }
1071
1546
  }
1072
1547
  async updateMemberRole(projectId, memberId, role) {
@@ -1088,7 +1563,7 @@ var ProjectService = class extends BaseService {
1088
1563
  }
1089
1564
  throw new Error(response.message);
1090
1565
  } catch (error) {
1091
- throw new Error(`Failed to update member role: ${error.message}`);
1566
+ throw new Error(`Failed to update member role: ${error.message}`, { cause: error });
1092
1567
  }
1093
1568
  }
1094
1569
  async removeMember(projectId, memberId) {
@@ -1109,7 +1584,7 @@ var ProjectService = class extends BaseService {
1109
1584
  }
1110
1585
  throw new Error(response.message);
1111
1586
  } catch (error) {
1112
- throw new Error(`Failed to remove member: ${error.message}`);
1587
+ throw new Error(`Failed to remove member: ${error.message}`, { cause: error });
1113
1588
  }
1114
1589
  }
1115
1590
  // ==================== PROJECT LIBRARY METHODS ====================
@@ -1129,7 +1604,7 @@ var ProjectService = class extends BaseService {
1129
1604
  }
1130
1605
  throw new Error(response.message);
1131
1606
  } catch (error) {
1132
- throw new Error(`Failed to get available libraries: ${error.message}`);
1607
+ throw new Error(`Failed to get available libraries: ${error.message}`, { cause: error });
1133
1608
  }
1134
1609
  }
1135
1610
  async getProjectLibraries(projectId) {
@@ -1147,7 +1622,7 @@ var ProjectService = class extends BaseService {
1147
1622
  }
1148
1623
  throw new Error(response.message);
1149
1624
  } catch (error) {
1150
- throw new Error(`Failed to get project libraries: ${error.message}`);
1625
+ throw new Error(`Failed to get project libraries: ${error.message}`, { cause: error });
1151
1626
  }
1152
1627
  }
1153
1628
  async addProjectLibraries(projectId, libraryIds) {
@@ -1162,11 +1637,11 @@ var ProjectService = class extends BaseService {
1162
1637
  methodName: "addProjectLibraries"
1163
1638
  });
1164
1639
  if (response.success) {
1165
- return response.data;
1640
+ return response;
1166
1641
  }
1167
1642
  throw new Error(response.message);
1168
1643
  } catch (error) {
1169
- throw new Error(`Failed to add project libraries: ${error.message}`);
1644
+ throw new Error(`Failed to add project libraries: ${error.message}`, { cause: error });
1170
1645
  }
1171
1646
  }
1172
1647
  async removeProjectLibraries(projectId, libraryIds) {
@@ -1185,7 +1660,7 @@ var ProjectService = class extends BaseService {
1185
1660
  }
1186
1661
  throw new Error(response.message);
1187
1662
  } catch (error) {
1188
- throw new Error(`Failed to remove project libraries: ${error.message}`);
1663
+ throw new Error(`Failed to remove project libraries: ${error.message}`, { cause: error });
1189
1664
  }
1190
1665
  }
1191
1666
  // ==================== PROJECT DATA METHODS (SYMSTORY REPLACEMENT) ====================
@@ -1202,14 +1677,20 @@ var ProjectService = class extends BaseService {
1202
1677
  throw new Error("Changes must be an array");
1203
1678
  }
1204
1679
  const { message, branch = "main", type = "patch" } = options;
1680
+ const state = this._context && this._context.state;
1681
+ const { granularChanges, orders: preprocessorOrders } = preprocessChanges(state, changes, options);
1682
+ const derivedOrders = options.orders || (preprocessorOrders && preprocessorOrders.length ? preprocessorOrders : state ? computeOrdersForTuples(state, granularChanges) : []);
1683
+ const stringify = (val) => deepStringifyFunctions(val, Array.isArray(val) ? [] : {});
1205
1684
  try {
1206
1685
  const response = await this._request(`/projects/${projectId}/changes`, {
1207
1686
  method: "POST",
1208
1687
  body: JSON.stringify({
1209
- changes,
1688
+ changes: stringify(changes),
1689
+ granularChanges: stringify(granularChanges),
1210
1690
  message,
1211
1691
  branch,
1212
- type
1692
+ type,
1693
+ ...derivedOrders && derivedOrders.length ? { orders: derivedOrders } : {}
1213
1694
  }),
1214
1695
  methodName: "applyProjectChanges"
1215
1696
  });
@@ -1218,7 +1699,7 @@ var ProjectService = class extends BaseService {
1218
1699
  }
1219
1700
  throw new Error(response.message);
1220
1701
  } catch (error) {
1221
- throw new Error(`Failed to apply project changes: ${error.message}`);
1702
+ throw new Error(`Failed to apply project changes: ${error.message}`, { cause: error });
1222
1703
  }
1223
1704
  }
1224
1705
  /**
@@ -1253,7 +1734,7 @@ var ProjectService = class extends BaseService {
1253
1734
  }
1254
1735
  throw new Error(response.message);
1255
1736
  } catch (error) {
1256
- throw new Error(`Failed to get project data: ${error.message}`);
1737
+ throw new Error(`Failed to get project data: ${error.message}`, { cause: error });
1257
1738
  }
1258
1739
  }
1259
1740
  /**
@@ -1283,7 +1764,7 @@ var ProjectService = class extends BaseService {
1283
1764
  }
1284
1765
  throw new Error(response.message);
1285
1766
  } catch (error) {
1286
- throw new Error(`Failed to get project versions: ${error.message}`);
1767
+ throw new Error(`Failed to get project versions: ${error.message}`, { cause: error });
1287
1768
  }
1288
1769
  }
1289
1770
  /**
@@ -1315,7 +1796,7 @@ var ProjectService = class extends BaseService {
1315
1796
  }
1316
1797
  throw new Error(response.message);
1317
1798
  } catch (error) {
1318
- throw new Error(`Failed to restore project version: ${error.message}`);
1799
+ throw new Error(`Failed to restore project version: ${error.message}`, { cause: error });
1319
1800
  }
1320
1801
  }
1321
1802
  /**
@@ -1415,7 +1896,7 @@ var ProjectService = class extends BaseService {
1415
1896
  }
1416
1897
  throw new Error(response.message);
1417
1898
  } catch (error) {
1418
- throw new Error(`Failed to get favorite projects: ${error.message}`);
1899
+ throw new Error(`Failed to get favorite projects: ${error.message}`, { cause: error });
1419
1900
  }
1420
1901
  }
1421
1902
  async addFavoriteProject(projectId) {
@@ -1433,7 +1914,7 @@ var ProjectService = class extends BaseService {
1433
1914
  }
1434
1915
  throw new Error(response.message);
1435
1916
  } catch (error) {
1436
- throw new Error(`Failed to add favorite project: ${error.message}`);
1917
+ throw new Error(`Failed to add favorite project: ${error.message}`, { cause: error });
1437
1918
  }
1438
1919
  }
1439
1920
  async removeFavoriteProject(projectId) {
@@ -1451,7 +1932,7 @@ var ProjectService = class extends BaseService {
1451
1932
  }
1452
1933
  throw new Error(response.message);
1453
1934
  } catch (error) {
1454
- throw new Error(`Failed to remove favorite project: ${error.message}`);
1935
+ throw new Error(`Failed to remove favorite project: ${error.message}`, { cause: error });
1455
1936
  }
1456
1937
  }
1457
1938
  // ==================== RECENT PROJECT METHODS ====================
@@ -1480,7 +1961,7 @@ var ProjectService = class extends BaseService {
1480
1961
  }
1481
1962
  throw new Error(response.message);
1482
1963
  } catch (error) {
1483
- throw new Error(`Failed to get recent projects: ${error.message}`);
1964
+ throw new Error(`Failed to get recent projects: ${error.message}`, { cause: error });
1484
1965
  }
1485
1966
  }
1486
1967
  };