@trayai/tray-sync-cli 0.0.1

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 (297) hide show
  1. package/LICENSE.md +182 -0
  2. package/README.md +167 -0
  3. package/dist/api/errors.js +29 -0
  4. package/dist/api/trayClient.js +69 -0
  5. package/dist/cli.js +32 -0
  6. package/dist/commands/auth.js +103 -0
  7. package/dist/commands/env.js +534 -0
  8. package/dist/commands/init.js +115 -0
  9. package/dist/commands/project.js +175 -0
  10. package/dist/commands/promote.js +289 -0
  11. package/dist/commands/pull.js +379 -0
  12. package/dist/commands/status.js +126 -0
  13. package/dist/config/credentials.js +10 -0
  14. package/dist/config/environments.js +10 -0
  15. package/dist/config/io.js +36 -0
  16. package/dist/config/mappings.js +9 -0
  17. package/dist/config/paths.js +33 -0
  18. package/dist/config/projectConfig.js +16 -0
  19. package/dist/config/pullProgress.js +9 -0
  20. package/dist/config/state.js +9 -0
  21. package/dist/config/trayYaml.js +9 -0
  22. package/dist/config/types.js +21 -0
  23. package/dist/config/yaml.js +22 -0
  24. package/dist/lib/authDiscovery.js +76 -0
  25. package/dist/lib/checksum.js +5 -0
  26. package/dist/lib/exportStructure.js +23 -0
  27. package/dist/lib/outputFormat.js +12 -0
  28. package/dist/lib/pathContainment.js +37 -0
  29. package/dist/lib/promoteExecute.js +8 -0
  30. package/dist/lib/promoteReconstruct.js +35 -0
  31. package/dist/lib/promoteReport.js +44 -0
  32. package/dist/lib/promoteTarget.js +129 -0
  33. package/dist/lib/region.js +26 -0
  34. package/dist/lib/regionDisplay.js +11 -0
  35. package/dist/lib/regionParsing.js +12 -0
  36. package/dist/lib/scriptExtraction.js +46 -0
  37. package/dist/lib/slug.js +14 -0
  38. package/dist/lib/tokenResolution.js +19 -0
  39. package/dist/lib/uuid.js +5 -0
  40. package/dist/views/env/env.js +89 -0
  41. package/dist/views/env/shared.js +7 -0
  42. package/dist/views/init/init.js +17 -0
  43. package/dist/views/project/project.js +35 -0
  44. package/dist/views/project/shared.js +4 -0
  45. package/dist/views/promote/promote.js +44 -0
  46. package/dist/views/promote/shared.js +4 -0
  47. package/dist/views/pull/pull.js +31 -0
  48. package/dist/views/pull/shared.js +4 -0
  49. package/dist/views/shared.js +8 -0
  50. package/dist/views/status/shared.js +20 -0
  51. package/dist/views/status/status.js +23 -0
  52. package/node_modules/commander/LICENSE +22 -0
  53. package/node_modules/commander/Readme.md +1172 -0
  54. package/node_modules/commander/index.js +21 -0
  55. package/node_modules/commander/lib/argument.js +147 -0
  56. package/node_modules/commander/lib/command.js +2790 -0
  57. package/node_modules/commander/lib/error.js +36 -0
  58. package/node_modules/commander/lib/help.js +731 -0
  59. package/node_modules/commander/lib/option.js +377 -0
  60. package/node_modules/commander/lib/suggestSimilar.js +99 -0
  61. package/node_modules/commander/package-support.json +19 -0
  62. package/node_modules/commander/package.json +64 -0
  63. package/node_modules/commander/typings/index.d.ts +1113 -0
  64. package/node_modules/yaml/LICENSE +13 -0
  65. package/node_modules/yaml/README.md +172 -0
  66. package/node_modules/yaml/bin.mjs +11 -0
  67. package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
  68. package/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
  69. package/node_modules/yaml/browser/dist/compose/compose-node.js +109 -0
  70. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
  71. package/node_modules/yaml/browser/dist/compose/composer.js +219 -0
  72. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
  73. package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
  74. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
  75. package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
  76. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
  77. package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +225 -0
  78. package/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
  79. package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
  80. package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
  81. package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
  82. package/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
  83. package/node_modules/yaml/browser/dist/doc/Document.js +335 -0
  84. package/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
  85. package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
  86. package/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
  87. package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
  88. package/node_modules/yaml/browser/dist/errors.js +57 -0
  89. package/node_modules/yaml/browser/dist/index.js +17 -0
  90. package/node_modules/yaml/browser/dist/log.js +11 -0
  91. package/node_modules/yaml/browser/dist/nodes/Alias.js +116 -0
  92. package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
  93. package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
  94. package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
  95. package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
  96. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
  97. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
  98. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
  99. package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
  100. package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
  101. package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
  102. package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
  103. package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
  104. package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
  105. package/node_modules/yaml/browser/dist/parse/lexer.js +721 -0
  106. package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
  107. package/node_modules/yaml/browser/dist/parse/parser.js +975 -0
  108. package/node_modules/yaml/browser/dist/public-api.js +102 -0
  109. package/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
  110. package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
  111. package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
  112. package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
  113. package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
  114. package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
  115. package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
  116. package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
  117. package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
  118. package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
  119. package/node_modules/yaml/browser/dist/schema/tags.js +96 -0
  120. package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
  121. package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
  122. package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
  123. package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
  124. package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +67 -0
  125. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
  126. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
  127. package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
  128. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
  129. package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
  130. package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
  131. package/node_modules/yaml/browser/dist/stringify/stringify.js +129 -0
  132. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +153 -0
  133. package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
  134. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
  135. package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +25 -0
  136. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
  137. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
  138. package/node_modules/yaml/browser/dist/util.js +11 -0
  139. package/node_modules/yaml/browser/dist/visit.js +233 -0
  140. package/node_modules/yaml/browser/index.js +5 -0
  141. package/node_modules/yaml/browser/package.json +3 -0
  142. package/node_modules/yaml/dist/cli.d.ts +8 -0
  143. package/node_modules/yaml/dist/cli.mjs +201 -0
  144. package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
  145. package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
  146. package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
  147. package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
  148. package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
  149. package/node_modules/yaml/dist/compose/compose-node.js +112 -0
  150. package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
  151. package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
  152. package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
  153. package/node_modules/yaml/dist/compose/composer.js +224 -0
  154. package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
  155. package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
  156. package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
  157. package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
  158. package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
  159. package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
  160. package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
  161. package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
  162. package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
  163. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
  164. package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
  165. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +227 -0
  166. package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
  167. package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
  168. package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
  169. package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
  170. package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
  171. package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
  172. package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  173. package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
  174. package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
  175. package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
  176. package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
  177. package/node_modules/yaml/dist/doc/Document.js +337 -0
  178. package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
  179. package/node_modules/yaml/dist/doc/anchors.js +76 -0
  180. package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
  181. package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
  182. package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
  183. package/node_modules/yaml/dist/doc/createNode.js +90 -0
  184. package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
  185. package/node_modules/yaml/dist/doc/directives.js +178 -0
  186. package/node_modules/yaml/dist/errors.d.ts +21 -0
  187. package/node_modules/yaml/dist/errors.js +62 -0
  188. package/node_modules/yaml/dist/index.d.ts +25 -0
  189. package/node_modules/yaml/dist/index.js +50 -0
  190. package/node_modules/yaml/dist/log.d.ts +3 -0
  191. package/node_modules/yaml/dist/log.js +19 -0
  192. package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
  193. package/node_modules/yaml/dist/nodes/Alias.js +118 -0
  194. package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
  195. package/node_modules/yaml/dist/nodes/Collection.js +151 -0
  196. package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
  197. package/node_modules/yaml/dist/nodes/Node.js +40 -0
  198. package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
  199. package/node_modules/yaml/dist/nodes/Pair.js +39 -0
  200. package/node_modules/yaml/dist/nodes/Scalar.d.ts +47 -0
  201. package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
  202. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
  203. package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
  204. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
  205. package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
  206. package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
  207. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
  208. package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
  209. package/node_modules/yaml/dist/nodes/identity.js +53 -0
  210. package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
  211. package/node_modules/yaml/dist/nodes/toJS.js +39 -0
  212. package/node_modules/yaml/dist/options.d.ts +350 -0
  213. package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
  214. package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
  215. package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
  216. package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
  217. package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
  218. package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
  219. package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
  220. package/node_modules/yaml/dist/parse/cst.js +112 -0
  221. package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
  222. package/node_modules/yaml/dist/parse/lexer.js +723 -0
  223. package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
  224. package/node_modules/yaml/dist/parse/line-counter.js +41 -0
  225. package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
  226. package/node_modules/yaml/dist/parse/parser.js +980 -0
  227. package/node_modules/yaml/dist/public-api.d.ts +44 -0
  228. package/node_modules/yaml/dist/public-api.js +107 -0
  229. package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
  230. package/node_modules/yaml/dist/schema/Schema.js +39 -0
  231. package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
  232. package/node_modules/yaml/dist/schema/common/map.js +19 -0
  233. package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
  234. package/node_modules/yaml/dist/schema/common/null.js +17 -0
  235. package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
  236. package/node_modules/yaml/dist/schema/common/seq.js +19 -0
  237. package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
  238. package/node_modules/yaml/dist/schema/common/string.js +16 -0
  239. package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
  240. package/node_modules/yaml/dist/schema/core/bool.js +21 -0
  241. package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
  242. package/node_modules/yaml/dist/schema/core/float.js +47 -0
  243. package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
  244. package/node_modules/yaml/dist/schema/core/int.js +42 -0
  245. package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
  246. package/node_modules/yaml/dist/schema/core/schema.js +25 -0
  247. package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
  248. package/node_modules/yaml/dist/schema/json/schema.js +64 -0
  249. package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
  250. package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
  251. package/node_modules/yaml/dist/schema/tags.js +99 -0
  252. package/node_modules/yaml/dist/schema/types.d.ts +92 -0
  253. package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
  254. package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
  255. package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
  256. package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
  257. package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
  258. package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
  259. package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
  260. package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
  261. package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
  262. package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
  263. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
  264. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
  265. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
  266. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
  267. package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
  268. package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
  269. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
  270. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
  271. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
  272. package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
  273. package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
  274. package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
  275. package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
  276. package/node_modules/yaml/dist/stringify/stringify.js +132 -0
  277. package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
  278. package/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
  279. package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
  280. package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
  281. package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
  282. package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
  283. package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
  284. package/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
  285. package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
  286. package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
  287. package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
  288. package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
  289. package/node_modules/yaml/dist/test-events.d.ts +4 -0
  290. package/node_modules/yaml/dist/test-events.js +134 -0
  291. package/node_modules/yaml/dist/util.d.ts +16 -0
  292. package/node_modules/yaml/dist/util.js +28 -0
  293. package/node_modules/yaml/dist/visit.d.ts +102 -0
  294. package/node_modules/yaml/dist/visit.js +236 -0
  295. package/node_modules/yaml/package.json +97 -0
  296. package/node_modules/yaml/util.js +2 -0
  297. package/package.json +42 -0
@@ -0,0 +1,379 @@
1
+ import { readdir as fsReaddir, rename as fsRename, rm as fsRm } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { Command, InvalidArgumentError } from "commander";
4
+ import { createTrayClientForRegion } from "../api/trayClient.js";
5
+ import { readCredentials } from "../config/credentials.js";
6
+ import { writeJson, writeText } from "../config/io.js";
7
+ import { readProjectMappings, writeProjectMappings } from "../config/mappings.js";
8
+ import { readPullProgress, writePullProgress } from "../config/pullProgress.js";
9
+ import { readProjectState, writeProjectState } from "../config/state.js";
10
+ import { readTrayYaml, writeTrayYaml } from "../config/trayYaml.js";
11
+ import { Scopes, TrayTypes, } from "../config/types.js";
12
+ import { entityDirName } from "../lib/slug.js";
13
+ import { entityDisplayName, parseExportStructure, } from "../lib/exportStructure.js";
14
+ import { extractScripts } from "../lib/scriptExtraction.js";
15
+ import { sha256 } from "../lib/checksum.js";
16
+ import { assertNoSymlinkInPath, resolveContained, resolveContainedSafe } from "../lib/pathContainment.js";
17
+ import { resolveToken } from "../lib/tokenResolution.js";
18
+ import { isUuid } from "../lib/uuid.js";
19
+ import { OutputFormats, parseFormat } from "../lib/outputFormat.js";
20
+ import { IncompatibleApiError } from "../api/errors.js";
21
+ import { printError, printPulled, printPulledUnchanged, printRemovedStaleProjectDir, printRenamedProjectDir, printSolutionDropped, printTrayYamlNotFound, printWouldPullProject, printWouldRenameProjectDir, printWouldSkipUnchangedProject, } from "../views/pull/pull.js";
22
+ import { printPullResultJson } from "../views/pull/shared.js";
23
+ const ASSET_DIRS = [
24
+ { field: "workflows", dirName: "workflows", fileName: "workflow.json", trayType: TrayTypes.WORKFLOW },
25
+ {
26
+ field: "data_tables",
27
+ dirName: "data-tables",
28
+ fileName: "data-table.json",
29
+ trayType: TrayTypes.DATA_TABLE,
30
+ },
31
+ {
32
+ field: "vector_tables",
33
+ dirName: "vector-tables",
34
+ fileName: "vector-table.json",
35
+ trayType: TrayTypes.VECTOR_TABLE,
36
+ },
37
+ { field: "agents", dirName: "agents", fileName: "agent.json", trayType: TrayTypes.AGENT },
38
+ {
39
+ field: "apim_operations",
40
+ dirName: "api-operations",
41
+ fileName: "api-operation.json",
42
+ trayType: TrayTypes.API_OPERATION,
43
+ },
44
+ ];
45
+ const EXPORT_PROJECT_QUERY = `
46
+ mutation ExportProject($projectId: ID!, $exportSolution: Boolean!) {
47
+ exportProject(input: { projectId: $projectId, exportSolution: $exportSolution }) {
48
+ exportedProjectJson
49
+ }
50
+ }
51
+ `;
52
+ function requireUuid(id, context) {
53
+ if (!isUuid(id)) {
54
+ throw new IncompatibleApiError(`${context}: expected a UUID, got "${id}"`);
55
+ }
56
+ return id;
57
+ }
58
+ export async function listProjectIds(client, workspaceId) {
59
+ const result = (await client.request("GET", `/v2/projects/workspaces/${workspaceId}`));
60
+ return result.projects.map((p) => requireUuid(p.id, "listProjects: projects[].id"));
61
+ }
62
+ export async function writeExportedProject(projectDirPath, exportStructure, stdout) {
63
+ const project = exportStructure.projects[0];
64
+ const projectJsonPath = path.join(projectDirPath, "project.json");
65
+ await assertNoSymlinkInPath(projectDirPath, projectJsonPath);
66
+ await writeJson(projectJsonPath, project);
67
+ const order = {
68
+ workflows: [],
69
+ data_tables: [],
70
+ vector_tables: [],
71
+ agents: [],
72
+ apim_operations: [],
73
+ };
74
+ const resources = {};
75
+ for (const { field, dirName, fileName, trayType } of ASSET_DIRS) {
76
+ const entities = exportStructure[field] ?? [];
77
+ for (const entity of entities) {
78
+ const entityId = requireUuid(entity.id, `exportProject: ${field}[].id`);
79
+ const entityDirName_ = entityDirName(entityId, entityDisplayName(entity));
80
+ const entityDir = resolveContained(path.join(projectDirPath, dirName), entityDirName_);
81
+ const entityJsonPath = path.join(entityDir, fileName);
82
+ await assertNoSymlinkInPath(projectDirPath, entityJsonPath);
83
+ await writeJson(entityJsonPath, entity);
84
+ order[field].push(entityId);
85
+ resources[entityId] = {
86
+ tray_type: trayType,
87
+ path: path.relative(projectDirPath, entityJsonPath),
88
+ local_checksum: sha256(JSON.stringify(entity, null, 2) + "\n"),
89
+ };
90
+ if (field === "workflows") {
91
+ for (const script of extractScripts(entity)) {
92
+ const scriptPath = resolveContained(path.join(entityDir, "scripts"), script.fileName);
93
+ await assertNoSymlinkInPath(projectDirPath, scriptPath);
94
+ await writeText(scriptPath, script.content);
95
+ const resourceKey = `${entityId}.${script.stepKey}`;
96
+ resources[resourceKey] = {
97
+ tray_type: TrayTypes.SCRIPT,
98
+ path: path.relative(projectDirPath, scriptPath),
99
+ local_checksum: sha256(script.content),
100
+ };
101
+ }
102
+ }
103
+ }
104
+ }
105
+ const solutionDropped = Boolean(exportStructure.solution);
106
+ if (solutionDropped) {
107
+ printSolutionDropped(stdout, project.id);
108
+ }
109
+ return { order, resources, solutionDropped };
110
+ }
111
+ const SCAFFOLD_ENV_NAME_PLACEHOLDER = "<target-env-name-placeholder>";
112
+ function emptyEnvironmentMapping() {
113
+ return { target_project_id: "", authentications: {}, config: {}, connectors: [], services: [] };
114
+ }
115
+ async function ensureProjectMappings(projectDirPath) {
116
+ const existing = await readProjectMappings(projectDirPath);
117
+ if (!existing) {
118
+ await writeProjectMappings(projectDirPath, {
119
+ version: 1,
120
+ environments: { [SCAFFOLD_ENV_NAME_PLACEHOLDER]: emptyEnvironmentMapping() },
121
+ });
122
+ }
123
+ }
124
+ function newPullProgress(trayYaml, planned) {
125
+ return {
126
+ pull_id: `${trayYaml.workspace_id}-${planned.length}`,
127
+ started_at: new Date().toISOString(),
128
+ workspace_id: trayYaml.workspace_id,
129
+ region: trayYaml.region,
130
+ planned,
131
+ completed: [],
132
+ failed: [],
133
+ };
134
+ }
135
+ export async function runPull(deps, options) {
136
+ const { cwd, createClient, readdir, rm, rename, stdout } = deps;
137
+ if (options.resume && options.resetState) {
138
+ throw new Error("--resume and --reset-state are mutually exclusive.");
139
+ }
140
+ const trayYaml = await readTrayYaml(cwd);
141
+ if (!trayYaml) {
142
+ throw new Error("tray.yaml not found. Run `tray init` first.");
143
+ }
144
+ const client = createClient(trayYaml.region, options.token);
145
+ const targeted = options.projectIds !== undefined && options.projectIds.length > 0;
146
+ let plannedIds;
147
+ if (targeted) {
148
+ plannedIds = options.projectIds;
149
+ }
150
+ else if (trayYaml.scope === Scopes.WORKSPACE) {
151
+ plannedIds = (await listProjectIds(client, trayYaml.workspace_id)).slice().sort();
152
+ if (!options.dryRun) {
153
+ await writeTrayYaml({ ...trayYaml, projects: plannedIds }, cwd);
154
+ }
155
+ }
156
+ else {
157
+ plannedIds = trayYaml.projects;
158
+ }
159
+ let progress;
160
+ if (!options.dryRun) {
161
+ if (options.resume) {
162
+ progress = await readPullProgress(cwd);
163
+ if (progress) {
164
+ plannedIds = progress.planned;
165
+ }
166
+ else {
167
+ progress = newPullProgress(trayYaml, plannedIds);
168
+ await writePullProgress(progress, cwd);
169
+ }
170
+ }
171
+ else {
172
+ progress = newPullProgress(trayYaml, plannedIds);
173
+ await writePullProgress(progress, cwd);
174
+ }
175
+ }
176
+ const alreadyCompleted = new Set(progress?.completed ?? []);
177
+ const asJson = options.format === OutputFormats.JSON;
178
+ const events = [];
179
+ for (const projectId of plannedIds) {
180
+ if (alreadyCompleted.has(projectId)) {
181
+ continue;
182
+ }
183
+ const raw = await client.graphql(EXPORT_PROJECT_QUERY, {
184
+ projectId,
185
+ exportSolution: true,
186
+ });
187
+ const exportedJson = raw.exportProject
188
+ .exportedProjectJson;
189
+ const exportStructure = parseExportStructure(JSON.parse(exportedJson));
190
+ const project = exportStructure.projects[0];
191
+ const validatedProjectId = requireUuid(project.id, "exportProject: projects[0].id");
192
+ const projectName = entityDisplayName(project);
193
+ const projectsRoot = path.join(cwd, "projects");
194
+ const newDirName = entityDirName(validatedProjectId, projectName);
195
+ const dir = await resolveContainedSafe(projectsRoot, newDirName);
196
+ let existingDirName;
197
+ try {
198
+ existingDirName = (await readdir(projectsRoot)).find((name) => name.split("--")[0] === validatedProjectId && name !== newDirName);
199
+ }
200
+ catch {
201
+ existingDirName = undefined;
202
+ }
203
+ let existingDirPath;
204
+ if (existingDirName) {
205
+ existingDirPath = await resolveContainedSafe(projectsRoot, existingDirName);
206
+ }
207
+ const existingState = await readProjectState(existingDirPath ?? dir);
208
+ const exportChecksum = sha256(exportedJson);
209
+ const unchanged = !options.resetState && existingState?.export_checksum === exportChecksum;
210
+ const renamedDir = existingDirName && existingDirName !== newDirName
211
+ ? { from: existingDirName, to: newDirName }
212
+ : undefined;
213
+ if (options.dryRun) {
214
+ if (renamedDir && !asJson) {
215
+ printWouldRenameProjectDir(stdout, renamedDir.from, renamedDir.to);
216
+ }
217
+ const action = unchanged ? "would_skip_unchanged" : "would_pull";
218
+ if (asJson) {
219
+ events.push({ project_id: projectId, project_name: projectName, action, renamed_dir: renamedDir });
220
+ }
221
+ else if (unchanged) {
222
+ printWouldSkipUnchangedProject(stdout, projectId, projectName);
223
+ }
224
+ else {
225
+ printWouldPullProject(stdout, projectId, projectName);
226
+ }
227
+ continue;
228
+ }
229
+ if (renamedDir) {
230
+ await rename(existingDirPath, dir);
231
+ if (!asJson) {
232
+ printRenamedProjectDir(stdout, renamedDir.from, renamedDir.to);
233
+ }
234
+ }
235
+ if (options.resetState) {
236
+ const preservedMappings = await readProjectMappings(dir);
237
+ await rm(dir).catch(() => { });
238
+ if (preservedMappings) {
239
+ await writeProjectMappings(dir, preservedMappings);
240
+ }
241
+ }
242
+ if (unchanged) {
243
+ await writeProjectState(dir, { ...existingState, last_sync: new Date().toISOString() });
244
+ if (asJson) {
245
+ events.push({ project_id: projectId, project_name: projectName, action: "pulled_unchanged", renamed_dir: renamedDir });
246
+ }
247
+ else {
248
+ printPulledUnchanged(stdout, projectId, projectName);
249
+ }
250
+ }
251
+ else {
252
+ const { order, resources, solutionDropped } = await writeExportedProject(dir, exportStructure, asJson ? () => { } : stdout);
253
+ const state = {
254
+ version: 1,
255
+ project_id: validatedProjectId,
256
+ tray_export_version: exportStructure.tray_export_version,
257
+ last_sync: new Date().toISOString(),
258
+ export_checksum: exportChecksum,
259
+ order,
260
+ resources,
261
+ };
262
+ await writeProjectState(dir, state);
263
+ if (asJson) {
264
+ events.push({
265
+ project_id: projectId,
266
+ project_name: projectName,
267
+ action: "pulled",
268
+ renamed_dir: renamedDir,
269
+ solution_dropped: solutionDropped,
270
+ });
271
+ }
272
+ else {
273
+ printPulled(stdout, projectId, projectName);
274
+ }
275
+ }
276
+ await ensureProjectMappings(dir);
277
+ if (progress) {
278
+ progress = { ...progress, completed: [...progress.completed, projectId] };
279
+ await writePullProgress(progress, cwd);
280
+ }
281
+ }
282
+ if (options.dryRun) {
283
+ if (asJson) {
284
+ printPullResultJson(stdout, { dry_run: true, projects: events, removed_stale_dirs: [] });
285
+ }
286
+ return 0;
287
+ }
288
+ if (targeted) {
289
+ const merged = Array.from(new Set([...trayYaml.projects, ...plannedIds])).sort();
290
+ await writeTrayYaml({ ...trayYaml, projects: merged }, cwd);
291
+ }
292
+ const removedStaleDirs = [];
293
+ if (!targeted && trayYaml.scope === Scopes.WORKSPACE) {
294
+ const projectsRoot = path.join(cwd, "projects");
295
+ let existingDirs;
296
+ try {
297
+ existingDirs = await readdir(projectsRoot);
298
+ }
299
+ catch {
300
+ existingDirs = [];
301
+ }
302
+ const plannedIdSet = new Set(plannedIds);
303
+ for (const dirName of existingDirs) {
304
+ const dirId = dirName.split("--")[0];
305
+ if (!plannedIdSet.has(dirId)) {
306
+ await rm(path.join(projectsRoot, dirName));
307
+ if (asJson) {
308
+ removedStaleDirs.push(dirName);
309
+ }
310
+ else {
311
+ printRemovedStaleProjectDir(stdout, dirName);
312
+ }
313
+ }
314
+ }
315
+ }
316
+ if (progress) {
317
+ await rm(path.join(cwd, ".pull-progress.json")).catch(() => { });
318
+ }
319
+ if (asJson) {
320
+ printPullResultJson(stdout, { dry_run: false, projects: events, removed_stale_dirs: removedStaleDirs });
321
+ }
322
+ return 0;
323
+ }
324
+ function parseUuid(value, previous) {
325
+ if (!isUuid(value)) {
326
+ throw new InvalidArgumentError("--project must be a UUID");
327
+ }
328
+ return [...(previous ?? []), value];
329
+ }
330
+ export const pullCommand = new Command("pull")
331
+ .description("Export tracked projects from Tray and materialise them on disk")
332
+ .option("-p, --project <id...>", "pull only these project IDs, adding any not yet tracked to tray.yaml", parseUuid)
333
+ .option("--resume", "resume a previously interrupted pull")
334
+ .option("--reset-state", "ignore existing state and rewrite everything from a fresh export")
335
+ .option("--dry-run", "report what would change without writing anything")
336
+ .option("-t, --token <token>", "Tray API token")
337
+ .option("--format <format>", "human or json", parseFormat, OutputFormats.HUMAN)
338
+ .action(async (opts) => {
339
+ const cwd = process.cwd();
340
+ const stderr = (line) => console.error(line);
341
+ const trayYaml = await readTrayYaml(cwd);
342
+ if (!trayYaml) {
343
+ printTrayYamlNotFound(stderr);
344
+ process.exitCode = 1;
345
+ return;
346
+ }
347
+ const credentials = await readCredentials(process.env);
348
+ let token;
349
+ try {
350
+ token = resolveToken({
351
+ tokenFlag: opts.token,
352
+ credentials,
353
+ workspaceId: trayYaml.workspace_id,
354
+ env: process.env,
355
+ });
356
+ }
357
+ catch (err) {
358
+ printError(stderr, err.message);
359
+ process.exitCode = 1;
360
+ return;
361
+ }
362
+ const exitCode = await runPull({
363
+ cwd,
364
+ createClient: (region, tok) => createTrayClientForRegion(region, tok),
365
+ readdir: (dir) => fsReaddir(dir),
366
+ rm: (dir) => fsRm(dir, { recursive: true, force: true }),
367
+ rename: (oldPath, newPath) => fsRename(oldPath, newPath),
368
+ stdout: (line) => console.log(line),
369
+ }, {
370
+ token,
371
+ projectIds: opts.project,
372
+ resume: Boolean(opts.resume),
373
+ resetState: Boolean(opts.resetState),
374
+ dryRun: Boolean(opts.dryRun),
375
+ format: opts.format,
376
+ });
377
+ process.exitCode = exitCode;
378
+ });
379
+ //# sourceMappingURL=pull.js.map
@@ -0,0 +1,126 @@
1
+ import path from "node:path";
2
+ import { readdir as fsReaddir, readFile as fsReadFile } from "node:fs/promises";
3
+ import { Command, InvalidArgumentError } from "commander";
4
+ import { readTrayYaml } from "../config/trayYaml.js";
5
+ import { readProjectState } from "../config/state.js";
6
+ import { sha256 } from "../lib/checksum.js";
7
+ import { isUuid } from "../lib/uuid.js";
8
+ import { resolveContainedSafe } from "../lib/pathContainment.js";
9
+ import { OutputFormats, parseFormat } from "../lib/outputFormat.js";
10
+ import { printStatusReports } from "../views/status/status.js";
11
+ import { printStatusReportsJson } from "../views/status/shared.js";
12
+ export const DriftStatuses = {
13
+ CLEAN: "CLEAN",
14
+ LOCAL_MODIFIED: "LOCAL_MODIFIED",
15
+ LOCAL_DELETED: "LOCAL_DELETED",
16
+ LOCAL_ADDED: "LOCAL_ADDED",
17
+ INVALID_PATH: "INVALID_PATH",
18
+ };
19
+ export async function checkProjectDrift(deps, projectId, projectDirPath) {
20
+ const state = await readProjectState(projectDirPath);
21
+ if (!state) {
22
+ return { project_id: projectId, project_dir: projectDirPath, never_pulled: true, drift: [] };
23
+ }
24
+ const drift = [];
25
+ const trackedPaths = new Set();
26
+ for (const resource of Object.values(state.resources)) {
27
+ trackedPaths.add(resource.path);
28
+ let resolvedPath;
29
+ try {
30
+ resolvedPath = await resolveContainedSafe(projectDirPath, resource.path);
31
+ }
32
+ catch {
33
+ drift.push({ path: resource.path, status: DriftStatuses.INVALID_PATH });
34
+ continue;
35
+ }
36
+ let content;
37
+ try {
38
+ content = await deps.readFile(resolvedPath);
39
+ }
40
+ catch {
41
+ drift.push({ path: resource.path, status: DriftStatuses.LOCAL_DELETED });
42
+ continue;
43
+ }
44
+ const status = sha256(content) === resource.local_checksum ? DriftStatuses.CLEAN : DriftStatuses.LOCAL_MODIFIED;
45
+ drift.push({ path: resource.path, status });
46
+ }
47
+ const excluded = new Set(["project.json", "state.json", "mappings.json"]);
48
+ const allFiles = await deps.readdirRecursive(projectDirPath);
49
+ for (const filePath of allFiles) {
50
+ if (excluded.has(filePath) || trackedPaths.has(filePath))
51
+ continue;
52
+ drift.push({ path: filePath, status: DriftStatuses.LOCAL_ADDED });
53
+ }
54
+ return { project_id: projectId, project_dir: projectDirPath, never_pulled: false, drift };
55
+ }
56
+ export async function runStatus(deps, options) {
57
+ const { cwd, readdir, stdout } = deps;
58
+ const trayYaml = await readTrayYaml(cwd);
59
+ if (!trayYaml) {
60
+ throw new Error("tray.yaml not found. Run `tray init` first.");
61
+ }
62
+ const targetIds = options.projectIds && options.projectIds.length > 0 ? options.projectIds : trayYaml.projects;
63
+ const projectsRoot = path.join(cwd, "projects");
64
+ let existingDirs;
65
+ try {
66
+ existingDirs = await readdir(projectsRoot);
67
+ }
68
+ catch {
69
+ existingDirs = [];
70
+ }
71
+ const reports = [];
72
+ for (const projectId of targetIds) {
73
+ const dirName = existingDirs.find((name) => name.split("--")[0] === projectId);
74
+ if (!dirName) {
75
+ reports.push({ projectId });
76
+ continue;
77
+ }
78
+ const projectDirPath = path.join(projectsRoot, dirName);
79
+ const result = await checkProjectDrift(deps, projectId, projectDirPath);
80
+ reports.push({ dirName, projectId, result });
81
+ }
82
+ const isClean = (r) => r.result !== undefined &&
83
+ !r.result.never_pulled &&
84
+ r.result.drift.every((d) => d.status === DriftStatuses.CLEAN);
85
+ const sorted = [...reports].sort((a, b) => Number(isClean(b)) - Number(isClean(a)));
86
+ if (options.format === OutputFormats.JSON) {
87
+ printStatusReportsJson(stdout, DriftStatuses.CLEAN, sorted);
88
+ }
89
+ else {
90
+ printStatusReports(stdout, DriftStatuses.CLEAN, sorted);
91
+ }
92
+ return 0;
93
+ }
94
+ function parseUuid(value, previous) {
95
+ if (!isUuid(value)) {
96
+ throw new InvalidArgumentError("--project must be a UUID");
97
+ }
98
+ return [...(previous ?? []), value];
99
+ }
100
+ async function readdirRecursiveReal(dirPath) {
101
+ try {
102
+ const entries = await fsReaddir(dirPath, { recursive: true, withFileTypes: true });
103
+ return entries
104
+ .filter((entry) => entry.isFile())
105
+ .map((entry) => path.relative(dirPath, path.join(entry.parentPath, entry.name)));
106
+ }
107
+ catch {
108
+ return [];
109
+ }
110
+ }
111
+ export const statusCommand = new Command("status")
112
+ .description("Local checksum-based drift detection (zero API calls)")
113
+ .option("-p, --project <id...>", "check only these project IDs", parseUuid)
114
+ .option("--format <format>", "human or json", parseFormat, OutputFormats.HUMAN)
115
+ .action(async (opts) => {
116
+ const cwd = process.cwd();
117
+ const exitCode = await runStatus({
118
+ cwd,
119
+ readdir: (dir) => fsReaddir(dir),
120
+ readdirRecursive: (dir) => readdirRecursiveReal(dir),
121
+ readFile: (filePath) => fsReadFile(filePath, "utf8"),
122
+ stdout: (line) => console.log(line),
123
+ }, { projectIds: opts.project, format: opts.format });
124
+ process.exitCode = exitCode;
125
+ });
126
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1,10 @@
1
+ import { OWNER_ONLY_FILE_MODE, readJson, writeJson } from "./io.js";
2
+ import { credentialsPath } from "./paths.js";
3
+ export async function readCredentials(env) {
4
+ const data = await readJson(credentialsPath(env));
5
+ return data ?? { version: 1, workspaces: {} };
6
+ }
7
+ export async function writeCredentials(data, env) {
8
+ await writeJson(credentialsPath(env), data, { mode: OWNER_ONLY_FILE_MODE });
9
+ }
10
+ //# sourceMappingURL=credentials.js.map
@@ -0,0 +1,10 @@
1
+ import { readJson, writeJson } from "./io.js";
2
+ import { environmentsPath } from "./paths.js";
3
+ export async function readEnvironments(cwd) {
4
+ const data = await readJson(environmentsPath(cwd));
5
+ return data ?? { version: 1, environments: {} };
6
+ }
7
+ export async function writeEnvironments(data, cwd) {
8
+ await writeJson(environmentsPath(cwd), data);
9
+ }
10
+ //# sourceMappingURL=environments.js.map
@@ -0,0 +1,36 @@
1
+ import { chmod, mkdir, readFile, rename, writeFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ export async function readJson(filePath) {
4
+ try {
5
+ const raw = await readFile(filePath, "utf8");
6
+ return JSON.parse(raw);
7
+ }
8
+ catch (err) {
9
+ if (err.code === "ENOENT")
10
+ return undefined;
11
+ throw err;
12
+ }
13
+ }
14
+ export const OWNER_ONLY_FILE_MODE = 0o600;
15
+ export const OWNER_ONLY_DIR_MODE = 0o700;
16
+ export async function writeJson(filePath, data, options = {}) {
17
+ const dir = path.dirname(filePath);
18
+ await mkdir(dir, { recursive: true, mode: options.mode ? OWNER_ONLY_DIR_MODE : undefined });
19
+ if (options.mode)
20
+ await chmod(dir, OWNER_ONLY_DIR_MODE);
21
+ const tmpPath = `${filePath}.tmp-${process.pid}`;
22
+ await writeFile(tmpPath, `${JSON.stringify(data, null, 2)}\n`, {
23
+ encoding: "utf8",
24
+ mode: options.mode,
25
+ });
26
+ if (options.mode)
27
+ await chmod(tmpPath, options.mode);
28
+ await rename(tmpPath, filePath);
29
+ }
30
+ export async function writeText(filePath, content) {
31
+ await mkdir(path.dirname(filePath), { recursive: true });
32
+ const tmpPath = `${filePath}.tmp-${process.pid}`;
33
+ await writeFile(tmpPath, content, "utf8");
34
+ await rename(tmpPath, filePath);
35
+ }
36
+ //# sourceMappingURL=io.js.map
@@ -0,0 +1,9 @@
1
+ import { projectMappingsPath } from "./paths.js";
2
+ import { readJson, writeJson } from "./io.js";
3
+ export async function readProjectMappings(projectDirPath) {
4
+ return readJson(projectMappingsPath(projectDirPath));
5
+ }
6
+ export async function writeProjectMappings(projectDirPath, data) {
7
+ await writeJson(projectMappingsPath(projectDirPath), data);
8
+ }
9
+ //# sourceMappingURL=mappings.js.map
@@ -0,0 +1,33 @@
1
+ import os from "node:os";
2
+ import path from "node:path";
3
+ export function userConfigDir(env = process.env) {
4
+ return env.TRAY_CONFIG_DIR ?? path.join(os.homedir(), ".tray");
5
+ }
6
+ export function credentialsPath(env) {
7
+ return path.join(userConfigDir(env), "credentials.json");
8
+ }
9
+ export function versionCheckPath(env) {
10
+ return path.join(userConfigDir(env), "version-check.json");
11
+ }
12
+ export function trayYamlPath(cwd = process.cwd()) {
13
+ return path.join(cwd, "tray.yaml");
14
+ }
15
+ export function environmentsPath(cwd = process.cwd()) {
16
+ return path.join(cwd, "environments.json");
17
+ }
18
+ export function pullProgressPath(cwd = process.cwd()) {
19
+ return path.join(cwd, ".pull-progress.json");
20
+ }
21
+ export function promoteProgressPath(cwd = process.cwd()) {
22
+ return path.join(cwd, ".promote-progress.json");
23
+ }
24
+ export function projectDir(cwd, projectId, slug) {
25
+ return path.join(cwd, "projects", `${projectId}--${slug}`);
26
+ }
27
+ export function projectMappingsPath(projectDirPath) {
28
+ return path.join(projectDirPath, "mappings.json");
29
+ }
30
+ export function projectStatePath(projectDirPath) {
31
+ return path.join(projectDirPath, "state.json");
32
+ }
33
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1,16 @@
1
+ import { readJson, writeJson } from "./io.js";
2
+ import { projectMappingsPath, projectStatePath } from "./paths.js";
3
+ export async function readMappings(projectDir) {
4
+ const data = await readJson(projectMappingsPath(projectDir));
5
+ return data ?? { version: 1, environments: {} };
6
+ }
7
+ export async function writeMappings(projectDir, data) {
8
+ await writeJson(projectMappingsPath(projectDir), data);
9
+ }
10
+ export async function readState(projectDir) {
11
+ return readJson(projectStatePath(projectDir));
12
+ }
13
+ export async function writeState(projectDir, data) {
14
+ await writeJson(projectStatePath(projectDir), data);
15
+ }
16
+ //# sourceMappingURL=projectConfig.js.map
@@ -0,0 +1,9 @@
1
+ import { pullProgressPath } from "./paths.js";
2
+ import { readJson, writeJson } from "./io.js";
3
+ export async function readPullProgress(cwd) {
4
+ return readJson(pullProgressPath(cwd));
5
+ }
6
+ export async function writePullProgress(data, cwd) {
7
+ await writeJson(pullProgressPath(cwd), data);
8
+ }
9
+ //# sourceMappingURL=pullProgress.js.map
@@ -0,0 +1,9 @@
1
+ import { projectStatePath } from "./paths.js";
2
+ import { readJson, writeJson } from "./io.js";
3
+ export async function readProjectState(projectDirPath) {
4
+ return readJson(projectStatePath(projectDirPath));
5
+ }
6
+ export async function writeProjectState(projectDirPath, data) {
7
+ await writeJson(projectStatePath(projectDirPath), data);
8
+ }
9
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1,9 @@
1
+ import { trayYamlPath } from "./paths.js";
2
+ import { readYaml, writeYaml } from "./yaml.js";
3
+ export async function readTrayYaml(cwd) {
4
+ return readYaml(trayYamlPath(cwd));
5
+ }
6
+ export async function writeTrayYaml(data, cwd) {
7
+ await writeYaml(trayYamlPath(cwd), data);
8
+ }
9
+ //# sourceMappingURL=trayYaml.js.map
@@ -0,0 +1,21 @@
1
+ export const Regions = {
2
+ US1: "us1",
3
+ EU1: "eu1",
4
+ AP1: "ap1",
5
+ AP2: "ap2",
6
+ STAGING: "staging",
7
+ };
8
+ export const Scopes = {
9
+ PROJECT: "project",
10
+ WORKSPACE: "workspace",
11
+ };
12
+ export const TrayTypes = {
13
+ PROJECT: "project",
14
+ WORKFLOW: "workflow",
15
+ DATA_TABLE: "data_table",
16
+ VECTOR_TABLE: "vector_table",
17
+ AGENT: "agent",
18
+ API_OPERATION: "api_operation",
19
+ SCRIPT: "script",
20
+ };
21
+ //# sourceMappingURL=types.js.map