@salesforce/graphiti 10.10.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 (282) hide show
  1. package/AGENT_GUIDE.md +424 -0
  2. package/CHANGELOG.md +448 -0
  3. package/LICENSE.txt +82 -0
  4. package/README.md +204 -0
  5. package/TASK.md +249 -0
  6. package/dist/cli.d.ts +7 -0
  7. package/dist/cli.js +683 -0
  8. package/dist/cli.js.map +1 -0
  9. package/dist/commands/args.d.ts +13 -0
  10. package/dist/commands/args.js +207 -0
  11. package/dist/commands/args.js.map +1 -0
  12. package/dist/commands/build.d.ts +11 -0
  13. package/dist/commands/build.js +209 -0
  14. package/dist/commands/build.js.map +1 -0
  15. package/dist/commands/connect.d.ts +8 -0
  16. package/dist/commands/connect.js +55 -0
  17. package/dist/commands/connect.js.map +1 -0
  18. package/dist/commands/describe.d.ts +6 -0
  19. package/dist/commands/describe.js +229 -0
  20. package/dist/commands/describe.js.map +1 -0
  21. package/dist/commands/meta.d.ts +9 -0
  22. package/dist/commands/meta.js +140 -0
  23. package/dist/commands/meta.js.map +1 -0
  24. package/dist/commands/navigate.d.ts +14 -0
  25. package/dist/commands/navigate.js +105 -0
  26. package/dist/commands/navigate.js.map +1 -0
  27. package/dist/commands/query-helpers.d.ts +80 -0
  28. package/dist/commands/query-helpers.js +865 -0
  29. package/dist/commands/query-helpers.js.map +1 -0
  30. package/dist/commands/query.d.ts +26 -0
  31. package/dist/commands/query.js +901 -0
  32. package/dist/commands/query.js.map +1 -0
  33. package/dist/commands/review.d.ts +18 -0
  34. package/dist/commands/review.js +533 -0
  35. package/dist/commands/review.js.map +1 -0
  36. package/dist/commands/session-mgmt.d.ts +25 -0
  37. package/dist/commands/session-mgmt.js +206 -0
  38. package/dist/commands/session-mgmt.js.map +1 -0
  39. package/dist/commands/type.d.ts +6 -0
  40. package/dist/commands/type.js +342 -0
  41. package/dist/commands/type.js.map +1 -0
  42. package/dist/commands/validate-input.d.ts +6 -0
  43. package/dist/commands/validate-input.js +32 -0
  44. package/dist/commands/validate-input.js.map +1 -0
  45. package/dist/intent/build-aggregate.d.ts +33 -0
  46. package/dist/intent/build-aggregate.js +134 -0
  47. package/dist/intent/build-aggregate.js.map +1 -0
  48. package/dist/intent/build-create.d.ts +14 -0
  49. package/dist/intent/build-create.js +16 -0
  50. package/dist/intent/build-create.js.map +1 -0
  51. package/dist/intent/build-delete.d.ts +30 -0
  52. package/dist/intent/build-delete.js +53 -0
  53. package/dist/intent/build-delete.js.map +1 -0
  54. package/dist/intent/build-detail.d.ts +32 -0
  55. package/dist/intent/build-detail.js +80 -0
  56. package/dist/intent/build-detail.js.map +1 -0
  57. package/dist/intent/build-discover.d.ts +30 -0
  58. package/dist/intent/build-discover.js +149 -0
  59. package/dist/intent/build-discover.js.map +1 -0
  60. package/dist/intent/build-list.d.ts +28 -0
  61. package/dist/intent/build-list.js +75 -0
  62. package/dist/intent/build-list.js.map +1 -0
  63. package/dist/intent/build-mutation.d.ts +23 -0
  64. package/dist/intent/build-mutation.js +54 -0
  65. package/dist/intent/build-mutation.js.map +1 -0
  66. package/dist/intent/build-output.d.ts +27 -0
  67. package/dist/intent/build-output.js +60 -0
  68. package/dist/intent/build-output.js.map +1 -0
  69. package/dist/intent/build-raw.d.ts +23 -0
  70. package/dist/intent/build-raw.js +54 -0
  71. package/dist/intent/build-raw.js.map +1 -0
  72. package/dist/intent/build-update.d.ts +14 -0
  73. package/dist/intent/build-update.js +16 -0
  74. package/dist/intent/build-update.js.map +1 -0
  75. package/dist/intent/get-schema-with-priming.d.ts +26 -0
  76. package/dist/intent/get-schema-with-priming.js +32 -0
  77. package/dist/intent/get-schema-with-priming.js.map +1 -0
  78. package/dist/intent/select-child-relationship.d.ts +19 -0
  79. package/dist/intent/select-child-relationship.js +38 -0
  80. package/dist/intent/select-child-relationship.js.map +1 -0
  81. package/dist/intent/types.d.ts +159 -0
  82. package/dist/intent/types.js +21 -0
  83. package/dist/intent/types.js.map +1 -0
  84. package/dist/lib/apply-command.d.ts +15 -0
  85. package/dist/lib/apply-command.js +238 -0
  86. package/dist/lib/apply-command.js.map +1 -0
  87. package/dist/lib/auth.d.ts +38 -0
  88. package/dist/lib/auth.js +113 -0
  89. package/dist/lib/auth.js.map +1 -0
  90. package/dist/lib/codegen.d.ts +32 -0
  91. package/dist/lib/codegen.js +700 -0
  92. package/dist/lib/codegen.js.map +1 -0
  93. package/dist/lib/command-registry.d.ts +59 -0
  94. package/dist/lib/command-registry.js +366 -0
  95. package/dist/lib/command-registry.js.map +1 -0
  96. package/dist/lib/formatter.d.ts +76 -0
  97. package/dist/lib/formatter.js +419 -0
  98. package/dist/lib/formatter.js.map +1 -0
  99. package/dist/lib/fs-utils.d.ts +23 -0
  100. package/dist/lib/fs-utils.js +46 -0
  101. package/dist/lib/fs-utils.js.map +1 -0
  102. package/dist/lib/graphql-name.d.ts +27 -0
  103. package/dist/lib/graphql-name.js +32 -0
  104. package/dist/lib/graphql-name.js.map +1 -0
  105. package/dist/lib/interactive.d.ts +6 -0
  106. package/dist/lib/interactive.js +562 -0
  107. package/dist/lib/interactive.js.map +1 -0
  108. package/dist/lib/introspect.d.ts +40 -0
  109. package/dist/lib/introspect.js +280 -0
  110. package/dist/lib/introspect.js.map +1 -0
  111. package/dist/lib/object-info.d.ts +79 -0
  112. package/dist/lib/object-info.js +313 -0
  113. package/dist/lib/object-info.js.map +1 -0
  114. package/dist/lib/path-selection.d.ts +50 -0
  115. package/dist/lib/path-selection.js +146 -0
  116. package/dist/lib/path-selection.js.map +1 -0
  117. package/dist/lib/prime-schema.d.ts +59 -0
  118. package/dist/lib/prime-schema.js +158 -0
  119. package/dist/lib/prime-schema.js.map +1 -0
  120. package/dist/lib/query-builder.d.ts +10 -0
  121. package/dist/lib/query-builder.js +168 -0
  122. package/dist/lib/query-builder.js.map +1 -0
  123. package/dist/lib/query-commands.d.ts +19 -0
  124. package/dist/lib/query-commands.js +262 -0
  125. package/dist/lib/query-commands.js.map +1 -0
  126. package/dist/lib/session.d.ts +205 -0
  127. package/dist/lib/session.js +1075 -0
  128. package/dist/lib/session.js.map +1 -0
  129. package/dist/lib/tokenize.d.ts +12 -0
  130. package/dist/lib/tokenize.js +48 -0
  131. package/dist/lib/tokenize.js.map +1 -0
  132. package/dist/lib/uiapi.d.ts +109 -0
  133. package/dist/lib/uiapi.js +159 -0
  134. package/dist/lib/uiapi.js.map +1 -0
  135. package/dist/lib/validator.d.ts +27 -0
  136. package/dist/lib/validator.js +100 -0
  137. package/dist/lib/validator.js.map +1 -0
  138. package/dist/lib/variable-promotion.d.ts +69 -0
  139. package/dist/lib/variable-promotion.js +95 -0
  140. package/dist/lib/variable-promotion.js.map +1 -0
  141. package/dist/lib/walker.d.ts +147 -0
  142. package/dist/lib/walker.js +723 -0
  143. package/dist/lib/walker.js.map +1 -0
  144. package/dist/mcp/server.d.ts +7 -0
  145. package/dist/mcp/server.js +34 -0
  146. package/dist/mcp/server.js.map +1 -0
  147. package/dist/mcp/stdio.d.ts +7 -0
  148. package/dist/mcp/stdio.js +25 -0
  149. package/dist/mcp/stdio.js.map +1 -0
  150. package/dist/mcp/tools/echo.d.ts +7 -0
  151. package/dist/mcp/tools/echo.js +17 -0
  152. package/dist/mcp/tools/echo.js.map +1 -0
  153. package/dist/mcp/tools/sf-gql-aggregate.d.ts +11 -0
  154. package/dist/mcp/tools/sf-gql-aggregate.js +75 -0
  155. package/dist/mcp/tools/sf-gql-aggregate.js.map +1 -0
  156. package/dist/mcp/tools/sf-gql-create.d.ts +11 -0
  157. package/dist/mcp/tools/sf-gql-create.js +35 -0
  158. package/dist/mcp/tools/sf-gql-create.js.map +1 -0
  159. package/dist/mcp/tools/sf-gql-delete.d.ts +11 -0
  160. package/dist/mcp/tools/sf-gql-delete.js +31 -0
  161. package/dist/mcp/tools/sf-gql-delete.js.map +1 -0
  162. package/dist/mcp/tools/sf-gql-detail.d.ts +11 -0
  163. package/dist/mcp/tools/sf-gql-detail.js +58 -0
  164. package/dist/mcp/tools/sf-gql-detail.js.map +1 -0
  165. package/dist/mcp/tools/sf-gql-discover.d.ts +9 -0
  166. package/dist/mcp/tools/sf-gql-discover.js +51 -0
  167. package/dist/mcp/tools/sf-gql-discover.js.map +1 -0
  168. package/dist/mcp/tools/sf-gql-list.d.ts +11 -0
  169. package/dist/mcp/tools/sf-gql-list.js +53 -0
  170. package/dist/mcp/tools/sf-gql-list.js.map +1 -0
  171. package/dist/mcp/tools/sf-gql-raw.d.ts +11 -0
  172. package/dist/mcp/tools/sf-gql-raw.js +39 -0
  173. package/dist/mcp/tools/sf-gql-raw.js.map +1 -0
  174. package/dist/mcp/tools/sf-gql-update.d.ts +11 -0
  175. package/dist/mcp/tools/sf-gql-update.js +35 -0
  176. package/dist/mcp/tools/sf-gql-update.js.map +1 -0
  177. package/dist/mcp/tools/shared/zod-schemas.d.ts +49 -0
  178. package/dist/mcp/tools/shared/zod-schemas.js +46 -0
  179. package/dist/mcp/tools/shared/zod-schemas.js.map +1 -0
  180. package/package.json +36 -0
  181. package/ralph-loop.sh +120 -0
  182. package/scripts/smoke-orderby.sh +190 -0
  183. package/src/__tests__/helpers/prime-deps.ts +46 -0
  184. package/src/__tests__/helpers/schema.ts +73 -0
  185. package/src/__tests__/helpers/stdout.ts +33 -0
  186. package/src/__tests__/setup.ts +19 -0
  187. package/src/cli.ts +764 -0
  188. package/src/commands/__tests__/query.spec.ts +137 -0
  189. package/src/commands/args.ts +306 -0
  190. package/src/commands/build.ts +288 -0
  191. package/src/commands/connect.ts +60 -0
  192. package/src/commands/describe.ts +246 -0
  193. package/src/commands/meta.ts +171 -0
  194. package/src/commands/navigate.ts +134 -0
  195. package/src/commands/query-helpers.ts +1202 -0
  196. package/src/commands/query.ts +1085 -0
  197. package/src/commands/review.ts +670 -0
  198. package/src/commands/session-mgmt.ts +256 -0
  199. package/src/commands/type.ts +437 -0
  200. package/src/commands/validate-input.ts +38 -0
  201. package/src/intent/__tests__/build-aggregate.spec.ts +931 -0
  202. package/src/intent/__tests__/build-create-validation.spec.ts +135 -0
  203. package/src/intent/__tests__/build-delete.spec.ts +121 -0
  204. package/src/intent/__tests__/build-detail.spec.ts +333 -0
  205. package/src/intent/__tests__/build-discover.spec.ts +432 -0
  206. package/src/intent/__tests__/build-list.spec.ts +284 -0
  207. package/src/intent/__tests__/build-mutation.spec.ts +108 -0
  208. package/src/intent/__tests__/build-output.spec.ts +55 -0
  209. package/src/intent/__tests__/build-raw.spec.ts +153 -0
  210. package/src/intent/__tests__/build-update-validation.spec.ts +134 -0
  211. package/src/intent/build-aggregate.ts +182 -0
  212. package/src/intent/build-create.ts +19 -0
  213. package/src/intent/build-delete.ts +62 -0
  214. package/src/intent/build-detail.ts +95 -0
  215. package/src/intent/build-discover.ts +199 -0
  216. package/src/intent/build-list.ts +91 -0
  217. package/src/intent/build-mutation.ts +75 -0
  218. package/src/intent/build-output.ts +72 -0
  219. package/src/intent/build-raw.ts +61 -0
  220. package/src/intent/build-update.ts +19 -0
  221. package/src/intent/get-schema-with-priming.ts +43 -0
  222. package/src/intent/select-child-relationship.ts +48 -0
  223. package/src/intent/types.ts +181 -0
  224. package/src/lib/__tests__/apply-command.parity.spec.ts +97 -0
  225. package/src/lib/__tests__/apply-command.spec.ts +171 -0
  226. package/src/lib/__tests__/auth.spec.ts +292 -0
  227. package/src/lib/__tests__/formatter.spec.ts +86 -0
  228. package/src/lib/__tests__/graphql-name.spec.ts +64 -0
  229. package/src/lib/__tests__/introspect.spec.ts +399 -0
  230. package/src/lib/__tests__/object-info.spec.ts +124 -0
  231. package/src/lib/__tests__/path-selection.spec.ts +219 -0
  232. package/src/lib/__tests__/prime-schema.spec.ts +269 -0
  233. package/src/lib/__tests__/query-builder.spec.ts +95 -0
  234. package/src/lib/__tests__/query-commands.spec.ts +74 -0
  235. package/src/lib/__tests__/session.spec.ts +292 -0
  236. package/src/lib/__tests__/tokenize.spec.ts +33 -0
  237. package/src/lib/__tests__/uiapi.spec.ts +192 -0
  238. package/src/lib/__tests__/variable-promotion.spec.ts +211 -0
  239. package/src/lib/__tests__/walker.spec.ts +250 -0
  240. package/src/lib/apply-command.ts +286 -0
  241. package/src/lib/auth.ts +157 -0
  242. package/src/lib/codegen.ts +899 -0
  243. package/src/lib/command-registry.ts +434 -0
  244. package/src/lib/formatter.ts +587 -0
  245. package/src/lib/fs-utils.ts +46 -0
  246. package/src/lib/graphql-name.ts +35 -0
  247. package/src/lib/interactive.ts +634 -0
  248. package/src/lib/introspect.ts +320 -0
  249. package/src/lib/object-info.ts +409 -0
  250. package/src/lib/path-selection.ts +162 -0
  251. package/src/lib/prime-schema.ts +195 -0
  252. package/src/lib/query-builder.ts +193 -0
  253. package/src/lib/query-commands.ts +290 -0
  254. package/src/lib/session.ts +1304 -0
  255. package/src/lib/tokenize.ts +43 -0
  256. package/src/lib/uiapi.ts +176 -0
  257. package/src/lib/validator.ts +143 -0
  258. package/src/lib/variable-promotion.ts +145 -0
  259. package/src/lib/walker.ts +975 -0
  260. package/src/mcp/__tests__/server.spec.ts +155 -0
  261. package/src/mcp/server.ts +38 -0
  262. package/src/mcp/stdio.ts +29 -0
  263. package/src/mcp/tools/__tests__/sf-gql-aggregate.spec.ts +173 -0
  264. package/src/mcp/tools/__tests__/sf-gql-create.spec.ts +235 -0
  265. package/src/mcp/tools/__tests__/sf-gql-delete.spec.ts +194 -0
  266. package/src/mcp/tools/__tests__/sf-gql-detail.spec.ts +246 -0
  267. package/src/mcp/tools/__tests__/sf-gql-discover.spec.ts +320 -0
  268. package/src/mcp/tools/__tests__/sf-gql-list.spec.ts +128 -0
  269. package/src/mcp/tools/__tests__/sf-gql-raw.spec.ts +141 -0
  270. package/src/mcp/tools/__tests__/sf-gql-update.spec.ts +207 -0
  271. package/src/mcp/tools/echo.ts +24 -0
  272. package/src/mcp/tools/sf-gql-aggregate.ts +102 -0
  273. package/src/mcp/tools/sf-gql-create.ts +55 -0
  274. package/src/mcp/tools/sf-gql-delete.ts +49 -0
  275. package/src/mcp/tools/sf-gql-detail.ts +85 -0
  276. package/src/mcp/tools/sf-gql-discover.ts +67 -0
  277. package/src/mcp/tools/sf-gql-list.ts +73 -0
  278. package/src/mcp/tools/sf-gql-raw.ts +56 -0
  279. package/src/mcp/tools/sf-gql-update.ts +55 -0
  280. package/src/mcp/tools/shared/zod-schemas.ts +55 -0
  281. package/tsconfig.json +18 -0
  282. package/vitest.config.ts +14 -0
@@ -0,0 +1,399 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ import fs from "fs";
8
+ import os from "os";
9
+ import path from "path";
10
+ import { describe, expect, it, vi } from "vitest";
11
+ import {
12
+ downloadSchema,
13
+ getSchemaFilePath,
14
+ normalizeInstanceUrl,
15
+ schemaExists,
16
+ schemaCacheKeyForInstanceUrl,
17
+ stripDataCloudTypes,
18
+ } from "../introspect.js";
19
+
20
+ vi.mock("@salesforce/core", () => {
21
+ const request = vi.fn().mockResolvedValue({ data: { ok: true } });
22
+ return {
23
+ Org: {
24
+ create: vi.fn().mockResolvedValue({
25
+ getConnection: () => ({ getApiVersion: () => "67.0", request }),
26
+ }),
27
+ },
28
+ __request: request,
29
+ };
30
+ });
31
+
32
+ describe("introspect", () => {
33
+ describe("schema cache keys", () => {
34
+ it("are derived from normalized instance URLs", () => {
35
+ const first = "https://Example.My.Salesforce.com/";
36
+ const second = "https://example.my.salesforce.com";
37
+ const third = "https://different.my.salesforce.com";
38
+
39
+ expect(normalizeInstanceUrl(first)).toBe("https://example.my.salesforce.com");
40
+ expect(schemaCacheKeyForInstanceUrl(first)).toBe(schemaCacheKeyForInstanceUrl(second));
41
+ expect(schemaCacheKeyForInstanceUrl(first)).not.toBe(schemaCacheKeyForInstanceUrl(third));
42
+ });
43
+ });
44
+
45
+ describe("stripDataCloudTypes", () => {
46
+ function makeTypeRef(name: string, kind = "OBJECT") {
47
+ return { kind, name, ofType: null };
48
+ }
49
+
50
+ function makeWrappedTypeRef(name: string) {
51
+ return { kind: "NON_NULL", name: null, ofType: { kind: "OBJECT", name, ofType: null } };
52
+ }
53
+
54
+ function makeIntrospectionResult(types: any[]) {
55
+ return { data: { __schema: { types } } };
56
+ }
57
+
58
+ it("removes __dlm types and references", () => {
59
+ const raw = makeIntrospectionResult([
60
+ {
61
+ name: "Query",
62
+ kind: "OBJECT",
63
+ fields: [
64
+ { name: "Account", type: makeTypeRef("AccountConnection") },
65
+ { name: "ssot__Account__dlm", type: makeTypeRef("ssot__Account__dlmConnection") },
66
+ { name: "Case", type: makeTypeRef("CaseConnection") },
67
+ ],
68
+ inputFields: null,
69
+ interfaces: [],
70
+ enumValues: null,
71
+ possibleTypes: null,
72
+ },
73
+ {
74
+ name: "AccountConnection",
75
+ kind: "OBJECT",
76
+ fields: [],
77
+ inputFields: null,
78
+ interfaces: [],
79
+ enumValues: null,
80
+ possibleTypes: null,
81
+ },
82
+ {
83
+ name: "ssot__Account__dlmConnection",
84
+ kind: "OBJECT",
85
+ fields: [],
86
+ inputFields: null,
87
+ interfaces: [],
88
+ enumValues: null,
89
+ possibleTypes: null,
90
+ },
91
+ {
92
+ name: "ssot__Account__dlm",
93
+ kind: "OBJECT",
94
+ fields: [],
95
+ inputFields: null,
96
+ interfaces: [],
97
+ enumValues: null,
98
+ possibleTypes: null,
99
+ },
100
+ {
101
+ name: "CaseConnection",
102
+ kind: "OBJECT",
103
+ fields: [],
104
+ inputFields: null,
105
+ interfaces: [],
106
+ enumValues: null,
107
+ possibleTypes: null,
108
+ },
109
+ ]);
110
+
111
+ const { result, removedCount } = stripDataCloudTypes(raw);
112
+ const types = result.data.__schema.types;
113
+ const typeNames = types.map((t: any) => t.name);
114
+
115
+ expect(removedCount).toBe(2);
116
+ expect(typeNames).not.toContain("ssot__Account__dlm");
117
+ expect(typeNames).not.toContain("ssot__Account__dlmConnection");
118
+ expect(typeNames).toContain("AccountConnection");
119
+ expect(typeNames).toContain("CaseConnection");
120
+
121
+ const queryType = types.find((t: any) => t.name === "Query");
122
+ const queryFieldNames = queryType.fields.map((f: any) => f.name);
123
+ expect(queryFieldNames).not.toContain("ssot__Account__dlm");
124
+ expect(queryFieldNames).toContain("Account");
125
+ expect(queryFieldNames).toContain("Case");
126
+ });
127
+
128
+ it("removes ssot__ prefixed types", () => {
129
+ const raw = makeIntrospectionResult([
130
+ {
131
+ name: "Query",
132
+ kind: "OBJECT",
133
+ fields: [
134
+ { name: "Account", type: makeTypeRef("AccountConnection") },
135
+ { name: "ssot__SomeEntity", type: makeTypeRef("ssot__SomeEntityConnection") },
136
+ ],
137
+ inputFields: null,
138
+ interfaces: [],
139
+ enumValues: null,
140
+ possibleTypes: null,
141
+ },
142
+ {
143
+ name: "AccountConnection",
144
+ kind: "OBJECT",
145
+ fields: [],
146
+ inputFields: null,
147
+ interfaces: [],
148
+ enumValues: null,
149
+ possibleTypes: null,
150
+ },
151
+ {
152
+ name: "ssot__SomeEntityConnection",
153
+ kind: "OBJECT",
154
+ fields: [],
155
+ inputFields: null,
156
+ interfaces: [],
157
+ enumValues: null,
158
+ possibleTypes: null,
159
+ },
160
+ {
161
+ name: "ssot__SomeEntity",
162
+ kind: "OBJECT",
163
+ fields: [],
164
+ inputFields: null,
165
+ interfaces: [],
166
+ enumValues: null,
167
+ possibleTypes: null,
168
+ },
169
+ ]);
170
+
171
+ const { result, removedCount } = stripDataCloudTypes(raw);
172
+ const typeNames = result.data.__schema.types.map((t: any) => t.name);
173
+
174
+ expect(removedCount).toBe(2);
175
+ expect(typeNames).not.toContain("ssot__SomeEntity");
176
+ expect(typeNames).not.toContain("ssot__SomeEntityConnection");
177
+ expect(typeNames).toContain("AccountConnection");
178
+ });
179
+
180
+ it("handles wrapped type refs (NON_NULL)", () => {
181
+ const raw = makeIntrospectionResult([
182
+ {
183
+ name: "Query",
184
+ kind: "OBJECT",
185
+ fields: [
186
+ { name: "Account", type: makeWrappedTypeRef("AccountConnection") },
187
+ { name: "ssot__Lead__dlm", type: makeWrappedTypeRef("ssot__Lead__dlmConnection") },
188
+ ],
189
+ inputFields: null,
190
+ interfaces: [],
191
+ enumValues: null,
192
+ possibleTypes: null,
193
+ },
194
+ {
195
+ name: "AccountConnection",
196
+ kind: "OBJECT",
197
+ fields: [],
198
+ inputFields: null,
199
+ interfaces: [],
200
+ enumValues: null,
201
+ possibleTypes: null,
202
+ },
203
+ {
204
+ name: "ssot__Lead__dlmConnection",
205
+ kind: "OBJECT",
206
+ fields: [],
207
+ inputFields: null,
208
+ interfaces: [],
209
+ enumValues: null,
210
+ possibleTypes: null,
211
+ },
212
+ {
213
+ name: "ssot__Lead__dlm",
214
+ kind: "OBJECT",
215
+ fields: [],
216
+ inputFields: null,
217
+ interfaces: [],
218
+ enumValues: null,
219
+ possibleTypes: null,
220
+ },
221
+ ]);
222
+
223
+ const { result } = stripDataCloudTypes(raw);
224
+ const queryType = result.data.__schema.types.find((t: any) => t.name === "Query");
225
+ expect(queryType.fields).toHaveLength(1);
226
+ expect(queryType.fields[0].name).toBe("Account");
227
+ });
228
+
229
+ it("cleans up possibleTypes on unions", () => {
230
+ const raw = makeIntrospectionResult([
231
+ {
232
+ name: "RecordUnion",
233
+ kind: "UNION",
234
+ fields: null,
235
+ inputFields: null,
236
+ interfaces: null,
237
+ enumValues: null,
238
+ possibleTypes: [
239
+ { kind: "OBJECT", name: "Account" },
240
+ { kind: "OBJECT", name: "ssot__Foo__dlm" },
241
+ ],
242
+ },
243
+ {
244
+ name: "Account",
245
+ kind: "OBJECT",
246
+ fields: [],
247
+ inputFields: null,
248
+ interfaces: [],
249
+ enumValues: null,
250
+ possibleTypes: null,
251
+ },
252
+ {
253
+ name: "ssot__Foo__dlm",
254
+ kind: "OBJECT",
255
+ fields: [],
256
+ inputFields: null,
257
+ interfaces: [],
258
+ enumValues: null,
259
+ possibleTypes: null,
260
+ },
261
+ ]);
262
+
263
+ const { result } = stripDataCloudTypes(raw);
264
+ const union = result.data.__schema.types.find((t: any) => t.name === "RecordUnion");
265
+ expect(union.possibleTypes).toHaveLength(1);
266
+ expect(union.possibleTypes[0].name).toBe("Account");
267
+ });
268
+
269
+ it("is a no-op when no DLM/SSOT types exist", () => {
270
+ const raw = makeIntrospectionResult([
271
+ {
272
+ name: "Query",
273
+ kind: "OBJECT",
274
+ fields: [{ name: "Account", type: makeTypeRef("Account") }],
275
+ inputFields: null,
276
+ interfaces: [],
277
+ enumValues: null,
278
+ possibleTypes: null,
279
+ },
280
+ {
281
+ name: "Account",
282
+ kind: "OBJECT",
283
+ fields: [],
284
+ inputFields: null,
285
+ interfaces: [],
286
+ enumValues: null,
287
+ possibleTypes: null,
288
+ },
289
+ ]);
290
+
291
+ const { result, removedCount } = stripDataCloudTypes(raw);
292
+ expect(removedCount).toBe(0);
293
+ expect(result.data.__schema.types).toHaveLength(2);
294
+ });
295
+ });
296
+
297
+ describe("schema helpers take instanceUrl (no auth)", () => {
298
+ it("getSchemaFilePath derives a stable path from a normalized URL", () => {
299
+ const a = getSchemaFilePath("https://Example.My.salesforce.com/");
300
+ const b = getSchemaFilePath("https://example.my.salesforce.com");
301
+ expect(a).toBe(b); // normalization: trailing slash + case ignored
302
+ expect(a.endsWith(".json")).toBe(true);
303
+ });
304
+
305
+ it("schemaExists is false for an unknown URL", () => {
306
+ expect(schemaExists("https://nope.my.salesforce.com")).toBe(false);
307
+ });
308
+ });
309
+
310
+ describe("executeGraphQL", () => {
311
+ it("posts via connection.request with the org API version", async () => {
312
+ const { executeGraphQL } = await import("../introspect.js");
313
+ const core = (await import("@salesforce/core")) as unknown as {
314
+ __request: ReturnType<typeof vi.fn>;
315
+ };
316
+ core.__request.mockClear();
317
+ const auth = {
318
+ alias: "o",
319
+ username: "u",
320
+ instanceUrl: "https://o.my.salesforce.com",
321
+ accessToken: "t",
322
+ orgId: "00D",
323
+ };
324
+ const result = await executeGraphQL(auth as never, "query { x }", { a: 1 });
325
+ expect(result).toEqual({ data: { ok: true } });
326
+ expect(core.__request).toHaveBeenCalledWith(
327
+ expect.objectContaining({
328
+ method: "POST",
329
+ url: expect.stringContaining("/services/data/v67.0/graphql"),
330
+ body: JSON.stringify({ query: "query { x }", variables: { a: 1 } }),
331
+ headers: expect.objectContaining({ "Content-Type": "application/json" }),
332
+ }),
333
+ );
334
+ });
335
+ });
336
+
337
+ describe("downloadSchema", () => {
338
+ const auth = {
339
+ alias: "o",
340
+ username: "u",
341
+ instanceUrl: "https://o.my.salesforce.com",
342
+ accessToken: "t",
343
+ orgId: "00D",
344
+ } as never;
345
+
346
+ it("happy path: writes cache file and returns correct metadata", async () => {
347
+ const core = (await import("@salesforce/core")) as unknown as {
348
+ __request: ReturnType<typeof vi.fn>;
349
+ };
350
+ core.__request.mockClear();
351
+ core.__request.mockResolvedValueOnce({
352
+ data: {
353
+ __schema: {
354
+ types: [
355
+ { name: "Account", kind: "OBJECT" },
356
+ { name: "__Type", kind: "SCALAR" },
357
+ ],
358
+ },
359
+ },
360
+ });
361
+
362
+ const tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "graphiti-dl-"));
363
+ const prevHome = process.env.GRAPHITI_HOME;
364
+ process.env.GRAPHITI_HOME = tmpRoot;
365
+ try {
366
+ const result = await downloadSchema(auth);
367
+
368
+ expect(result.instanceUrl).toBe("https://o.my.salesforce.com");
369
+ expect(result.filePath.endsWith(".json")).toBe(true);
370
+ expect(fs.existsSync(result.filePath)).toBe(true);
371
+ // Only "Account" counts — "__Type" starts with "__"
372
+ expect(result.typeCount).toBe(1);
373
+ } finally {
374
+ process.env.GRAPHITI_HOME = prevHome;
375
+ fs.rmSync(tmpRoot, { recursive: true, force: true });
376
+ }
377
+ });
378
+
379
+ it("throws when the response contains GraphQL errors", async () => {
380
+ const core = (await import("@salesforce/core")) as unknown as {
381
+ __request: ReturnType<typeof vi.fn>;
382
+ };
383
+ core.__request.mockClear();
384
+ core.__request.mockResolvedValueOnce({ errors: [{ message: "boom" }] });
385
+
386
+ await expect(downloadSchema(auth)).rejects.toThrow(/Introspection query returned errors/);
387
+ });
388
+
389
+ it("throws when the response has no __schema field", async () => {
390
+ const core = (await import("@salesforce/core")) as unknown as {
391
+ __request: ReturnType<typeof vi.fn>;
392
+ };
393
+ core.__request.mockClear();
394
+ core.__request.mockResolvedValueOnce({ data: {} });
395
+
396
+ await expect(downloadSchema(auth)).rejects.toThrow(/did not return a __schema/);
397
+ });
398
+ });
399
+ });
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ import fs from "node:fs";
8
+ import path from "node:path";
9
+ import { afterEach, describe, expect, it, vi } from "vitest";
10
+ import { graphitiHome } from "../fs-utils.js";
11
+ import type * as IntrospectModule from "../introspect.js";
12
+
13
+ vi.mock("../introspect.js", async () => {
14
+ const actual = await vi.importActual<typeof IntrospectModule>("../introspect.js");
15
+ return {
16
+ ...actual,
17
+ executeGraphQL: vi.fn(),
18
+ };
19
+ });
20
+
21
+ const { executeGraphQL } = await import("../introspect.js");
22
+ const { clearObjectInfoCache, getObjectInfo } = await import("../object-info.js");
23
+
24
+ const auth = {
25
+ alias: "test-cache",
26
+ username: "u",
27
+ instanceUrl: "https://test-cache.my.salesforce.com",
28
+ accessToken: "t",
29
+ orgId: "00D",
30
+ };
31
+
32
+ const minimalObjectInfoResponse = {
33
+ data: {
34
+ uiapi: {
35
+ objectInfos: [
36
+ {
37
+ ApiName: "Account",
38
+ label: "Account",
39
+ labelPlural: "Accounts",
40
+ createable: true,
41
+ deletable: true,
42
+ updateable: true,
43
+ queryable: true,
44
+ searchable: true,
45
+ custom: false,
46
+ keyPrefix: "001",
47
+ nameFields: ["Name"],
48
+ defaultRecordTypeId: "012000000000000AAA",
49
+ recordTypeInfos: [],
50
+ childRelationships: [],
51
+ fields: [],
52
+ },
53
+ ],
54
+ },
55
+ },
56
+ };
57
+
58
+ afterEach(() => {
59
+ vi.mocked(executeGraphQL).mockReset();
60
+ clearObjectInfoCache();
61
+ });
62
+
63
+ describe("object-info cache hardening", () => {
64
+ function listCacheFiles(): string[] {
65
+ const root = path.join(graphitiHome(), "cache", "objectInfos");
66
+ if (!fs.existsSync(root)) return [];
67
+ return fs
68
+ .readdirSync(root, { recursive: true, withFileTypes: true })
69
+ .filter((d) => d.isFile())
70
+ .map((d) => d.name);
71
+ }
72
+
73
+ it("rejects path-traversal in orgAlias when fetching ObjectInfo", async () => {
74
+ vi.mocked(executeGraphQL).mockResolvedValue(minimalObjectInfoResponse);
75
+ const before = listCacheFiles();
76
+ await getObjectInfo(auth, "../escaped", "Account");
77
+ const after = listCacheFiles();
78
+ // writeDiskCache silently refuses; no new files anywhere under cacheDir
79
+ expect(after).toEqual(before);
80
+ });
81
+
82
+ it("rejects SObject names with disallowed characters when fetching ObjectInfo", async () => {
83
+ vi.mocked(executeGraphQL).mockResolvedValue(minimalObjectInfoResponse);
84
+ await getObjectInfo(auth, "test-cache", "../passwd");
85
+ expect(listCacheFiles().find((n) => n.includes("passwd"))).toBeUndefined();
86
+ });
87
+
88
+ it("clearObjectInfoCache silently ignores invalid org alias", () => {
89
+ expect(() => clearObjectInfoCache("../escaped")).not.toThrow();
90
+ });
91
+
92
+ it("clearObjectInfoCache accepts a valid alias", () => {
93
+ expect(() => clearObjectInfoCache("test-cache")).not.toThrow();
94
+ });
95
+
96
+ it("treats cache entries with corrupt fetchedAt as stale", async () => {
97
+ vi.mocked(executeGraphQL).mockResolvedValue(minimalObjectInfoResponse);
98
+
99
+ // First call seeds the disk cache.
100
+ await getObjectInfo(auth, "test-cache", "Account");
101
+
102
+ // Corrupt the on-disk fetchedAt to a non-parseable value.
103
+ const cacheFile = path.join(
104
+ graphitiHome(),
105
+ "cache",
106
+ "objectInfos",
107
+ "test-cache",
108
+ "Account.json",
109
+ );
110
+ const raw = JSON.parse(fs.readFileSync(cacheFile, "utf-8"));
111
+ raw.fetchedAt = "not-a-date";
112
+ fs.writeFileSync(cacheFile, JSON.stringify(raw), "utf-8");
113
+
114
+ // Clear the in-memory cache so the next call hits disk.
115
+ clearObjectInfoCache();
116
+
117
+ // A naive Date.now() - new Date(undefined).getTime() yields NaN,
118
+ // which compares false against CACHE_TTL_MS — without the NaN
119
+ // guard the corrupt entry would read as fresh forever. With the
120
+ // guard, getObjectInfo refuses the disk entry and re-fetches.
121
+ await getObjectInfo(auth, "test-cache", "Account");
122
+ expect(vi.mocked(executeGraphQL)).toHaveBeenCalledTimes(2);
123
+ });
124
+ });