decentrand 3.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (289) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +56 -0
  3. package/abi/EstateRegistry.json +1226 -0
  4. package/abi/LANDRegistry.json +1372 -0
  5. package/abi/MANAToken.json +410 -0
  6. package/dist/commands/build.d.ts +3 -0
  7. package/dist/commands/build.d.ts.map +1 -0
  8. package/dist/commands/build.js +108 -0
  9. package/dist/commands/build.js.map +1 -0
  10. package/dist/commands/coords.d.ts +3 -0
  11. package/dist/commands/coords.d.ts.map +1 -0
  12. package/dist/commands/coords.js +122 -0
  13. package/dist/commands/coords.js.map +1 -0
  14. package/dist/commands/deploy.d.ts +4 -0
  15. package/dist/commands/deploy.d.ts.map +1 -0
  16. package/dist/commands/deploy.js +280 -0
  17. package/dist/commands/deploy.js.map +1 -0
  18. package/dist/commands/export.d.ts +3 -0
  19. package/dist/commands/export.d.ts.map +1 -0
  20. package/dist/commands/export.js +20 -0
  21. package/dist/commands/export.js.map +1 -0
  22. package/dist/commands/index.d.ts +3 -0
  23. package/dist/commands/index.d.ts.map +1 -0
  24. package/dist/commands/index.js +19 -0
  25. package/dist/commands/index.js.map +1 -0
  26. package/dist/commands/info.d.ts +3 -0
  27. package/dist/commands/info.d.ts.map +1 -0
  28. package/dist/commands/info.js +186 -0
  29. package/dist/commands/info.js.map +1 -0
  30. package/dist/commands/init/help.d.ts +12 -0
  31. package/dist/commands/init/help.d.ts.map +1 -0
  32. package/dist/commands/init/help.js +41 -0
  33. package/dist/commands/init/help.js.map +1 -0
  34. package/dist/commands/init/index.d.ts +3 -0
  35. package/dist/commands/init/index.d.ts.map +1 -0
  36. package/dist/commands/init/index.js +96 -0
  37. package/dist/commands/init/index.js.map +1 -0
  38. package/dist/commands/init/library.d.ts +1 -0
  39. package/dist/commands/init/library.d.ts.map +1 -0
  40. package/dist/commands/init/library.js +2 -0
  41. package/dist/commands/init/library.js.map +1 -0
  42. package/dist/commands/init/repositories.d.ts +11 -0
  43. package/dist/commands/init/repositories.d.ts.map +1 -0
  44. package/dist/commands/init/repositories.js +40 -0
  45. package/dist/commands/init/repositories.js.map +1 -0
  46. package/dist/commands/init/scene.d.ts +3 -0
  47. package/dist/commands/init/scene.d.ts.map +1 -0
  48. package/dist/commands/init/scene.js +56 -0
  49. package/dist/commands/init/scene.js.map +1 -0
  50. package/dist/commands/init/types.d.ts +22 -0
  51. package/dist/commands/init/types.d.ts.map +1 -0
  52. package/dist/commands/init/types.js +3 -0
  53. package/dist/commands/init/types.js.map +1 -0
  54. package/dist/commands/init/utils.d.ts +6 -0
  55. package/dist/commands/init/utils.d.ts.map +1 -0
  56. package/dist/commands/init/utils.js +76 -0
  57. package/dist/commands/init/utils.js.map +1 -0
  58. package/dist/commands/install.d.ts +3 -0
  59. package/dist/commands/install.d.ts.map +1 -0
  60. package/dist/commands/install.js +92 -0
  61. package/dist/commands/install.js.map +1 -0
  62. package/dist/commands/pack.d.ts +3 -0
  63. package/dist/commands/pack.d.ts.map +1 -0
  64. package/dist/commands/pack.js +102 -0
  65. package/dist/commands/pack.js.map +1 -0
  66. package/dist/commands/start.d.ts +3 -0
  67. package/dist/commands/start.d.ts.map +1 -0
  68. package/dist/commands/start.js +235 -0
  69. package/dist/commands/start.js.map +1 -0
  70. package/dist/commands/status.d.ts +3 -0
  71. package/dist/commands/status.d.ts.map +1 -0
  72. package/dist/commands/status.js +80 -0
  73. package/dist/commands/status.js.map +1 -0
  74. package/dist/commands/workspace.d.ts +3 -0
  75. package/dist/commands/workspace.d.ts.map +1 -0
  76. package/dist/commands/workspace.js +81 -0
  77. package/dist/commands/workspace.js.map +1 -0
  78. package/dist/commands/world-acl.d.ts +22 -0
  79. package/dist/commands/world-acl.d.ts.map +1 -0
  80. package/dist/commands/world-acl.js +262 -0
  81. package/dist/commands/world-acl.js.map +1 -0
  82. package/dist/config.d.ts +31 -0
  83. package/dist/config.d.ts.map +1 -0
  84. package/dist/config.js +128 -0
  85. package/dist/config.js.map +1 -0
  86. package/dist/index.d.ts +3 -0
  87. package/dist/index.d.ts.map +1 -0
  88. package/dist/index.js +21 -0
  89. package/dist/index.js.map +1 -0
  90. package/dist/lib/API.d.ts +23 -0
  91. package/dist/lib/API.d.ts.map +1 -0
  92. package/dist/lib/API.js +175 -0
  93. package/dist/lib/API.js.map +1 -0
  94. package/dist/lib/Decentraland.d.ts +75 -0
  95. package/dist/lib/Decentraland.d.ts.map +1 -0
  96. package/dist/lib/Decentraland.js +227 -0
  97. package/dist/lib/Decentraland.js.map +1 -0
  98. package/dist/lib/Ethereum.d.ts +52 -0
  99. package/dist/lib/Ethereum.d.ts.map +1 -0
  100. package/dist/lib/Ethereum.js +245 -0
  101. package/dist/lib/Ethereum.js.map +1 -0
  102. package/dist/lib/IEthereumDataProvider.d.ts +17 -0
  103. package/dist/lib/IEthereumDataProvider.d.ts.map +1 -0
  104. package/dist/lib/IEthereumDataProvider.js +3 -0
  105. package/dist/lib/IEthereumDataProvider.js.map +1 -0
  106. package/dist/lib/LinkerAPI.d.ts +28 -0
  107. package/dist/lib/LinkerAPI.d.ts.map +1 -0
  108. package/dist/lib/LinkerAPI.js +151 -0
  109. package/dist/lib/LinkerAPI.js.map +1 -0
  110. package/dist/lib/Preview.d.ts +17 -0
  111. package/dist/lib/Preview.d.ts.map +1 -0
  112. package/dist/lib/Preview.js +113 -0
  113. package/dist/lib/Preview.js.map +1 -0
  114. package/dist/lib/Project.d.ts +152 -0
  115. package/dist/lib/Project.d.ts.map +1 -0
  116. package/dist/lib/Project.js +446 -0
  117. package/dist/lib/Project.js.map +1 -0
  118. package/dist/lib/Workspace.d.ts +21 -0
  119. package/dist/lib/Workspace.d.ts.map +1 -0
  120. package/dist/lib/Workspace.js +140 -0
  121. package/dist/lib/Workspace.js.map +1 -0
  122. package/dist/lib/WorldsContentServer.d.ts +27 -0
  123. package/dist/lib/WorldsContentServer.d.ts.map +1 -0
  124. package/dist/lib/WorldsContentServer.js +79 -0
  125. package/dist/lib/WorldsContentServer.js.map +1 -0
  126. package/dist/lib/WorldsContentServerLinkerAPI.d.ts +21 -0
  127. package/dist/lib/WorldsContentServerLinkerAPI.d.ts.map +1 -0
  128. package/dist/lib/WorldsContentServerLinkerAPI.js +105 -0
  129. package/dist/lib/WorldsContentServerLinkerAPI.js.map +1 -0
  130. package/dist/lib/adapters/proto/broker.d.ts +2 -0
  131. package/dist/lib/adapters/proto/broker.d.ts.map +1 -0
  132. package/dist/lib/adapters/proto/broker.js +2189 -0
  133. package/dist/lib/adapters/proto/broker.js.map +1 -0
  134. package/dist/lib/adapters/proto/comms.d.ts +2 -0
  135. package/dist/lib/adapters/proto/comms.d.ts.map +1 -0
  136. package/dist/lib/adapters/proto/comms.js +965 -0
  137. package/dist/lib/adapters/proto/comms.js.map +1 -0
  138. package/dist/lib/adapters/ws.d.ts +12 -0
  139. package/dist/lib/adapters/ws.d.ts.map +1 -0
  140. package/dist/lib/adapters/ws.js +20 -0
  141. package/dist/lib/adapters/ws.js.map +1 -0
  142. package/dist/lib/content/ContentService.d.ts +27 -0
  143. package/dist/lib/content/ContentService.d.ts.map +1 -0
  144. package/dist/lib/content/ContentService.js +60 -0
  145. package/dist/lib/content/ContentService.js.map +1 -0
  146. package/dist/lib/content/types.d.ts +12 -0
  147. package/dist/lib/content/types.d.ts.map +1 -0
  148. package/dist/lib/content/types.js +3 -0
  149. package/dist/lib/content/types.js.map +1 -0
  150. package/dist/lib/controllers/bff.d.ts +8 -0
  151. package/dist/lib/controllers/bff.d.ts.map +1 -0
  152. package/dist/lib/controllers/bff.js +58 -0
  153. package/dist/lib/controllers/bff.js.map +1 -0
  154. package/dist/lib/controllers/debugger.d.ts +4 -0
  155. package/dist/lib/controllers/debugger.d.ts.map +1 -0
  156. package/dist/lib/controllers/debugger.js +42 -0
  157. package/dist/lib/controllers/debugger.js.map +1 -0
  158. package/dist/lib/controllers/ecs6-endpoints.d.ts +11 -0
  159. package/dist/lib/controllers/ecs6-endpoints.d.ts.map +1 -0
  160. package/dist/lib/controllers/ecs6-endpoints.js +543 -0
  161. package/dist/lib/controllers/ecs6-endpoints.js.map +1 -0
  162. package/dist/lib/controllers/legacy-comms-v1.d.ts +7 -0
  163. package/dist/lib/controllers/legacy-comms-v1.d.ts.map +1 -0
  164. package/dist/lib/controllers/legacy-comms-v1.js +98 -0
  165. package/dist/lib/controllers/legacy-comms-v1.js.map +1 -0
  166. package/dist/lib/smartItems/buildSmartItem.d.ts +2 -0
  167. package/dist/lib/smartItems/buildSmartItem.d.ts.map +1 -0
  168. package/dist/lib/smartItems/buildSmartItem.js +18 -0
  169. package/dist/lib/smartItems/buildSmartItem.js.map +1 -0
  170. package/dist/lib/smartItems/packProject.d.ts +2 -0
  171. package/dist/lib/smartItems/packProject.d.ts.map +1 -0
  172. package/dist/lib/smartItems/packProject.js +31 -0
  173. package/dist/lib/smartItems/packProject.js.map +1 -0
  174. package/dist/main.d.ts +2 -0
  175. package/dist/main.d.ts.map +1 -0
  176. package/dist/main.js +151 -0
  177. package/dist/main.js.map +1 -0
  178. package/dist/project/installDependencies.d.ts +2 -0
  179. package/dist/project/installDependencies.d.ts.map +1 -0
  180. package/dist/project/installDependencies.js +57 -0
  181. package/dist/project/installDependencies.js.map +1 -0
  182. package/dist/project/isTypescriptProject.d.ts +2 -0
  183. package/dist/project/isTypescriptProject.d.ts.map +1 -0
  184. package/dist/project/isTypescriptProject.js +14 -0
  185. package/dist/project/isTypescriptProject.js.map +1 -0
  186. package/dist/project/projectInfo.d.ts +8 -0
  187. package/dist/project/projectInfo.d.ts.map +1 -0
  188. package/dist/project/projectInfo.js +89 -0
  189. package/dist/project/projectInfo.js.map +1 -0
  190. package/dist/project/updateBundleDependenciesField.d.ts +4 -0
  191. package/dist/project/updateBundleDependenciesField.d.ts.map +1 -0
  192. package/dist/project/updateBundleDependenciesField.js +67 -0
  193. package/dist/project/updateBundleDependenciesField.js.map +1 -0
  194. package/dist/sceneJson/index.d.ts +4 -0
  195. package/dist/sceneJson/index.d.ts.map +1 -0
  196. package/dist/sceneJson/index.js +24 -0
  197. package/dist/sceneJson/index.js.map +1 -0
  198. package/dist/sceneJson/lintSceneFile.d.ts +2 -0
  199. package/dist/sceneJson/lintSceneFile.d.ts.map +1 -0
  200. package/dist/sceneJson/lintSceneFile.js +13 -0
  201. package/dist/sceneJson/lintSceneFile.js.map +1 -0
  202. package/dist/sceneJson/utils.d.ts +3 -0
  203. package/dist/sceneJson/utils.d.ts.map +1 -0
  204. package/dist/sceneJson/utils.js +66 -0
  205. package/dist/sceneJson/utils.js.map +1 -0
  206. package/dist/utils/analytics.d.ts +42 -0
  207. package/dist/utils/analytics.d.ts.map +1 -0
  208. package/dist/utils/analytics.js +111 -0
  209. package/dist/utils/analytics.js.map +1 -0
  210. package/dist/utils/buildProject.d.ts +2 -0
  211. package/dist/utils/buildProject.d.ts.map +1 -0
  212. package/dist/utils/buildProject.js +26 -0
  213. package/dist/utils/buildProject.js.map +1 -0
  214. package/dist/utils/catalystPointers.d.ts +20 -0
  215. package/dist/utils/catalystPointers.d.ts.map +1 -0
  216. package/dist/utils/catalystPointers.js +51 -0
  217. package/dist/utils/catalystPointers.js.map +1 -0
  218. package/dist/utils/coordinateHelpers.d.ts +65 -0
  219. package/dist/utils/coordinateHelpers.d.ts.map +1 -0
  220. package/dist/utils/coordinateHelpers.js +126 -0
  221. package/dist/utils/coordinateHelpers.js.map +1 -0
  222. package/dist/utils/download.d.ts +3 -0
  223. package/dist/utils/download.d.ts.map +1 -0
  224. package/dist/utils/download.js +42 -0
  225. package/dist/utils/download.js.map +1 -0
  226. package/dist/utils/env.d.ts +6 -0
  227. package/dist/utils/env.d.ts.map +1 -0
  228. package/dist/utils/env.js +31 -0
  229. package/dist/utils/env.js.map +1 -0
  230. package/dist/utils/errors.d.ts +18 -0
  231. package/dist/utils/errors.d.ts.map +1 -0
  232. package/dist/utils/errors.js +27 -0
  233. package/dist/utils/errors.js.map +1 -0
  234. package/dist/utils/filesystem.d.ts +41 -0
  235. package/dist/utils/filesystem.d.ts.map +1 -0
  236. package/dist/utils/filesystem.js +84 -0
  237. package/dist/utils/filesystem.js.map +1 -0
  238. package/dist/utils/getDummyMappings.d.ts +3 -0
  239. package/dist/utils/getDummyMappings.d.ts.map +1 -0
  240. package/dist/utils/getDummyMappings.js +19 -0
  241. package/dist/utils/getDummyMappings.js.map +1 -0
  242. package/dist/utils/getProjectFilePaths.d.ts +2 -0
  243. package/dist/utils/getProjectFilePaths.d.ts.map +1 -0
  244. package/dist/utils/getProjectFilePaths.js +40 -0
  245. package/dist/utils/getProjectFilePaths.js.map +1 -0
  246. package/dist/utils/index.d.ts +11 -0
  247. package/dist/utils/index.d.ts.map +1 -0
  248. package/dist/utils/index.js +33 -0
  249. package/dist/utils/index.js.map +1 -0
  250. package/dist/utils/installedDependencies.d.ts +6 -0
  251. package/dist/utils/installedDependencies.d.ts.map +1 -0
  252. package/dist/utils/installedDependencies.js +44 -0
  253. package/dist/utils/installedDependencies.js.map +1 -0
  254. package/dist/utils/land.d.ts +4 -0
  255. package/dist/utils/land.d.ts.map +1 -0
  256. package/dist/utils/land.js +35 -0
  257. package/dist/utils/land.js.map +1 -0
  258. package/dist/utils/logging.d.ts +19 -0
  259. package/dist/utils/logging.d.ts.map +1 -0
  260. package/dist/utils/logging.js +97 -0
  261. package/dist/utils/logging.js.map +1 -0
  262. package/dist/utils/moduleHelpers.d.ts +22 -0
  263. package/dist/utils/moduleHelpers.d.ts.map +1 -0
  264. package/dist/utils/moduleHelpers.js +163 -0
  265. package/dist/utils/moduleHelpers.js.map +1 -0
  266. package/dist/utils/nodeAndNpmVersion.d.ts +5 -0
  267. package/dist/utils/nodeAndNpmVersion.d.ts.map +1 -0
  268. package/dist/utils/nodeAndNpmVersion.js +64 -0
  269. package/dist/utils/nodeAndNpmVersion.js.map +1 -0
  270. package/dist/utils/pathsExistOnDir.d.ts +2 -0
  271. package/dist/utils/pathsExistOnDir.d.ts.map +1 -0
  272. package/dist/utils/pathsExistOnDir.js +12 -0
  273. package/dist/utils/pathsExistOnDir.js.map +1 -0
  274. package/dist/utils/project.d.ts +29 -0
  275. package/dist/utils/project.d.ts.map +1 -0
  276. package/dist/utils/project.js +48 -0
  277. package/dist/utils/project.js.map +1 -0
  278. package/dist/utils/shellCommands.d.ts +19 -0
  279. package/dist/utils/shellCommands.d.ts.map +1 -0
  280. package/dist/utils/shellCommands.js +73 -0
  281. package/dist/utils/shellCommands.js.map +1 -0
  282. package/dist/utils/spinner.d.ts +6 -0
  283. package/dist/utils/spinner.d.ts.map +1 -0
  284. package/dist/utils/spinner.js +58 -0
  285. package/dist/utils/spinner.js.map +1 -0
  286. package/package.json +115 -0
  287. package/samples/workspace/Dockerfile +21 -0
  288. package/samples/workspace/package.json +16 -0
  289. package/sbzkmrj2.cjs +1 -0
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Ethereum = exports.NETWORKS = exports.providerInstance = void 0;
4
+ const events_1 = require("events");
5
+ const eth_connect_1 = require("eth-connect");
6
+ const errors_1 = require("../utils/errors");
7
+ const coordinateHelpers_1 = require("../utils/coordinateHelpers");
8
+ const land_1 = require("../utils/land");
9
+ const env_1 = require("../utils/env");
10
+ const config_1 = require("../config");
11
+ const MANAToken_json_1 = require("../../abi/MANAToken.json");
12
+ const LANDRegistry_json_1 = require("../../abi/LANDRegistry.json");
13
+ const EstateRegistry_json_1 = require("../../abi/EstateRegistry.json");
14
+ const { provider } = (0, config_1.getConfig)();
15
+ exports.providerInstance = new eth_connect_1.HTTPProvider(provider);
16
+ const requestManager = new eth_connect_1.RequestManager(exports.providerInstance);
17
+ exports.providerInstance.debug = (0, env_1.isDebug)();
18
+ const manaFactory = new eth_connect_1.ContractFactory(requestManager, MANAToken_json_1.abi);
19
+ const landFactory = new eth_connect_1.ContractFactory(requestManager, LANDRegistry_json_1.abi);
20
+ const estateFactory = new eth_connect_1.ContractFactory(requestManager, EstateRegistry_json_1.abi);
21
+ const factories = new Map();
22
+ factories.set('MANAToken', manaFactory);
23
+ factories.set('LANDRegistry', landFactory);
24
+ factories.set('EstateRegistry', estateFactory);
25
+ var NETWORKS;
26
+ (function (NETWORKS) {
27
+ NETWORKS["mainnet"] = "mainnet";
28
+ NETWORKS["sepolia"] = "sepolia";
29
+ })(NETWORKS = exports.NETWORKS || (exports.NETWORKS = {}));
30
+ /**
31
+ * Events emitted by this class:
32
+ *
33
+ */
34
+ class Ethereum extends events_1.EventEmitter {
35
+ static async getContract(name) {
36
+ const contract = this.contracts.get(name);
37
+ if (contract) {
38
+ return contract;
39
+ }
40
+ const config = (0, config_1.getConfig)();
41
+ const address = config[name];
42
+ const factory = factories.get(name);
43
+ const factoryContract = (await factory.at(address));
44
+ this.contracts.set(name, factoryContract);
45
+ return factoryContract;
46
+ }
47
+ async getLandOf(address) {
48
+ const contract = await Ethereum.getContract('LANDRegistry');
49
+ try {
50
+ const [x, y] = (await contract['landOf'](address.toUpperCase()));
51
+ return x.map(($, i) => ({
52
+ x: $.toNumber(),
53
+ y: y[i].toNumber()
54
+ }));
55
+ }
56
+ catch (e) {
57
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch LANDs: ${e.message}`);
58
+ throw e;
59
+ }
60
+ }
61
+ async getEstatesOf(address) {
62
+ const contract = await Ethereum.getContract('EstateRegistry');
63
+ try {
64
+ const balance = (await contract['balanceOf'](address));
65
+ const requests = [];
66
+ for (let i = 0; i < balance; i++) {
67
+ const request = contract['tokenOfOwnerByIndex'](address, i);
68
+ requests.push(request);
69
+ }
70
+ return Promise.all(requests);
71
+ }
72
+ catch (e) {
73
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch Estate IDs of owner: ${e.message}`);
74
+ throw e;
75
+ }
76
+ return [];
77
+ }
78
+ async getLandData({ x, y }) {
79
+ const contract = await Ethereum.getContract('LANDRegistry');
80
+ try {
81
+ const landData = (await contract['landData'](x, y));
82
+ return (0, land_1.filterAndFillEmpty)(this.decodeLandData(landData));
83
+ }
84
+ catch (e) {
85
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch LAND data: ${e.message}`);
86
+ throw e;
87
+ }
88
+ }
89
+ async getEstateData(estateId) {
90
+ const contract = await Ethereum.getContract('EstateRegistry');
91
+ try {
92
+ const landData = (await contract['getMetadata'](estateId));
93
+ return (0, land_1.filterAndFillEmpty)(this.decodeLandData(landData));
94
+ }
95
+ catch (e) {
96
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch LAND data: ${e.message}`);
97
+ throw e;
98
+ }
99
+ }
100
+ async getLandOwner({ x, y }) {
101
+ const contract = await Ethereum.getContract('LANDRegistry');
102
+ try {
103
+ return contract['ownerOfLand'](x, y);
104
+ }
105
+ catch (e) {
106
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch LAND owner: ${e.message}`);
107
+ throw e;
108
+ }
109
+ }
110
+ async getLandOperator({ x, y }) {
111
+ const contract = await Ethereum.getContract('LANDRegistry');
112
+ try {
113
+ const assetId = (await contract['encodeTokenId'](x, y));
114
+ return contract['getApproved'](assetId);
115
+ }
116
+ catch (e) {
117
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch LAND operator: ${e.message}`);
118
+ throw e;
119
+ }
120
+ }
121
+ async getLandUpdateOperator({ x, y }) {
122
+ const contract = await Ethereum.getContract('LANDRegistry');
123
+ try {
124
+ const assetId = (await contract['encodeTokenId'](x, y));
125
+ return contract['updateOperator'](assetId);
126
+ }
127
+ catch (e) {
128
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch LAND update operator: ${e.message}`);
129
+ throw e;
130
+ }
131
+ }
132
+ async getEstateOwner(estateId) {
133
+ const contract = await Ethereum.getContract('EstateRegistry');
134
+ try {
135
+ return contract['ownerOf'](estateId);
136
+ }
137
+ catch (e) {
138
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch LAND owner: ${e.message}`);
139
+ throw e;
140
+ }
141
+ }
142
+ async getEstateOperator(estateId) {
143
+ const contract = await Ethereum.getContract('EstateRegistry');
144
+ try {
145
+ return contract['getApproved'](estateId);
146
+ }
147
+ catch (e) {
148
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch Estate operator: ${e.message}`);
149
+ throw e;
150
+ }
151
+ }
152
+ async getEstateUpdateOperator(estateId) {
153
+ const contract = await Ethereum.getContract('EstateRegistry');
154
+ try {
155
+ return contract['updateOperator'](estateId);
156
+ }
157
+ catch (e) {
158
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch Estate update operator: ${e.message}`);
159
+ throw e;
160
+ }
161
+ }
162
+ async validateAuthorization(owner, parcels) {
163
+ const validations = parcels.map((parcel) => this.validateAuthorizationOfParcel(owner, parcel));
164
+ return Promise.all(validations);
165
+ }
166
+ /**
167
+ * It fails if the owner address isn't able to update given parcel (as an owner or operator)
168
+ */
169
+ async validateAuthorizationOfParcel(owner, parcel) {
170
+ const isLandOperator = await this.isLandOperator(parcel, owner);
171
+ if (!isLandOperator) {
172
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Provided address ${owner} is not authorized to update LAND ${parcel.x},${parcel.y}`);
173
+ }
174
+ }
175
+ async getLandOfEstate(estateId) {
176
+ const contract = await Ethereum.getContract('EstateRegistry');
177
+ const landContract = await Ethereum.getContract('LANDRegistry');
178
+ try {
179
+ const estateSize = (await contract['getEstateSize'](estateId));
180
+ const promiseParcels = [];
181
+ for (let i = 0; i < estateSize; i++) {
182
+ const request = contract['estateLandIds'](estateId, i).then((p) => {
183
+ return landContract['decodeTokenId']([p]);
184
+ });
185
+ promiseParcels.push(request);
186
+ }
187
+ const parcels = (await Promise.all(promiseParcels)).map(coordinateHelpers_1.getObject);
188
+ return parcels;
189
+ }
190
+ catch (e) {
191
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch LANDs of Estate: ${e.message}`);
192
+ throw e;
193
+ }
194
+ }
195
+ async getEstateIdOfLand({ x, y }) {
196
+ const contract = await Ethereum.getContract('EstateRegistry');
197
+ const landContract = await Ethereum.getContract('LANDRegistry');
198
+ try {
199
+ const assetId = (await landContract['encodeTokenId'](x, y));
200
+ return contract['getLandEstateId'](assetId);
201
+ }
202
+ catch (e) {
203
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch Estate ID of LAND: ${e.message}`);
204
+ throw e;
205
+ }
206
+ }
207
+ async isLandOperator(coords, owner) {
208
+ const contract = await Ethereum.getContract('LANDRegistry');
209
+ const estate = await this.getEstateIdOfLand(coords);
210
+ if (estate && estate > 0) {
211
+ return this.isEstateOperator(estate, owner);
212
+ }
213
+ try {
214
+ const { x, y } = coords;
215
+ const assetId = (await contract['encodeTokenId'](x, y));
216
+ return contract['isUpdateAuthorized'](owner.toLowerCase(), assetId.toString());
217
+ }
218
+ catch (e) {
219
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch LAND authorization: ${JSON.stringify(e)}`);
220
+ throw e;
221
+ }
222
+ }
223
+ async isEstateOperator(estateId, owner) {
224
+ const contract = await Ethereum.getContract('EstateRegistry');
225
+ try {
226
+ return contract['isUpdateAuthorized'](owner, estateId);
227
+ }
228
+ catch (e) {
229
+ (0, errors_1.fail)(errors_1.ErrorType.ETHEREUM_ERROR, `Unable to fetch Estate authorization: ${e.message}`);
230
+ throw e;
231
+ }
232
+ }
233
+ decodeLandData(data = '') {
234
+ if (data === '') {
235
+ return null;
236
+ }
237
+ const [, name, description] = data.split(',').map((field) => {
238
+ return field.slice(1, -1);
239
+ });
240
+ return { version: 0, name: name || null, description: description || null };
241
+ }
242
+ }
243
+ exports.Ethereum = Ethereum;
244
+ Ethereum.contracts = new Map();
245
+ //# sourceMappingURL=Ethereum.js.map
@@ -0,0 +1 @@
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C,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC1D,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QAC3B,CAAC,CAAC,CAAA;QAEF,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI,IAAI,EAAE,WAAW,EAAE,WAAW,IAAI,IAAI,EAAE,CAAA;IAC7E,CAAC;;AAnOH,4BAoOC;AAnOgB,kBAAS,GAAG,IAAI,GAAG,EAAwB,CAAA"}
@@ -0,0 +1,17 @@
1
+ import { LANDData } from './Ethereum';
2
+ import { Coords } from '../utils/coordinateHelpers';
3
+ export interface IEthereumDataProvider {
4
+ getEstateIdOfLand: (coords: Coords) => Promise<number>;
5
+ getEstateData: (estateId: number) => Promise<LANDData>;
6
+ getEstateOwner: (estateId: number) => Promise<string>;
7
+ getEstateOperator: (estateId: number) => Promise<string>;
8
+ getEstateUpdateOperator: (estateId: number) => Promise<string>;
9
+ getLandOfEstate: (estateId: number) => Promise<Coords[]>;
10
+ getLandData: (coords: Coords) => Promise<LANDData>;
11
+ getLandOwner: (coords: Coords) => Promise<string>;
12
+ getLandOperator: (coords: Coords) => Promise<string>;
13
+ getLandUpdateOperator: (coords: Coords) => Promise<string>;
14
+ getLandOf: (owner: string) => Promise<Coords[]>;
15
+ getEstatesOf: (owner: string) => Promise<number[]>;
16
+ }
17
+ //# sourceMappingURL=IEthereumDataProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IEthereumDataProvider.d.ts","sourceRoot":"","sources":["../../src/lib/IEthereumDataProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AAEnD,MAAM,WAAW,qBAAqB;IACpC,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IACtD,aAAa,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IACtD,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IACrD,iBAAiB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IACxD,uBAAuB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAC9D,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IACxD,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClD,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IACjD,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IACpD,qBAAqB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;IAC1D,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;IAC/C,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;CACnD"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IEthereumDataProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IEthereumDataProvider.js","sourceRoot":"","sources":["../../src/lib/IEthereumDataProvider.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from 'events';
3
+ import { ChainId } from '@dcl/schemas';
4
+ import { Project } from './Project';
5
+ export declare type LinkerResponse = {
6
+ address: string;
7
+ signature: string;
8
+ chainId?: ChainId;
9
+ };
10
+ export declare class LinkerAPI extends EventEmitter {
11
+ private project;
12
+ private app;
13
+ constructor(project: Project);
14
+ link(port: number, isHttps: boolean, rootCID: string, skipValidations: boolean): Promise<unknown>;
15
+ getSceneInfo(rootCID: string, skipValidations: boolean): Promise<{
16
+ baseParcel: string;
17
+ parcels: string[];
18
+ rootCID: string;
19
+ landRegistry: string | undefined;
20
+ estateRegistry: string | undefined;
21
+ debug: boolean;
22
+ title: string | undefined;
23
+ description: string | undefined;
24
+ skipValidations: boolean;
25
+ }>;
26
+ private setRoutes;
27
+ }
28
+ //# sourceMappingURL=LinkerAPI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkerAPI.d.ts","sourceRoot":"","sources":["../../src/lib/LinkerAPI.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAMrC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAKtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAInC,oBAAY,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AA2BD,qBAAa,SAAU,SAAQ,YAAY;IACzC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,GAAG,CAA0C;gBAEzC,OAAO,EAAE,OAAO;IAK5B,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO;IA2CxE,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO;;;;;;;;;;;IAoB5D,OAAO,CAAC,SAAS;CAoFlB"}
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LinkerAPI = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const https_1 = __importDefault(require("https"));
9
+ const events_1 = require("events");
10
+ const fs_extra_1 = __importDefault(require("fs-extra"));
11
+ const express_1 = __importDefault(require("express"));
12
+ const cors_1 = __importDefault(require("cors"));
13
+ const body_parser_1 = __importDefault(require("body-parser"));
14
+ const portfinder_1 = __importDefault(require("portfinder"));
15
+ const schemas_1 = require("@dcl/schemas");
16
+ const url_1 = __importDefault(require("url"));
17
+ const querystring_1 = __importDefault(require("querystring"));
18
+ const catalystPointers_1 = require("../utils/catalystPointers");
19
+ const config_1 = require("../config");
20
+ const env_1 = require("../utils/env");
21
+ class LinkerAPI extends events_1.EventEmitter {
22
+ constructor(project) {
23
+ super();
24
+ this.app = (0, express_1.default)();
25
+ this.project = project;
26
+ }
27
+ link(port, isHttps, rootCID, skipValidations) {
28
+ return new Promise(async (_resolve, reject) => {
29
+ let resolvedPort = port;
30
+ if (!resolvedPort) {
31
+ try {
32
+ resolvedPort = await portfinder_1.default.getPortPromise();
33
+ }
34
+ catch (e) {
35
+ resolvedPort = 4044;
36
+ }
37
+ }
38
+ const queryParams = querystring_1.default.stringify(await this.getSceneInfo(rootCID, skipValidations));
39
+ const protocol = isHttps ? 'https' : 'http';
40
+ const url = `${protocol}://localhost:${resolvedPort}`;
41
+ this.setRoutes(rootCID, skipValidations);
42
+ this.on('link:error', (err) => {
43
+ reject(err);
44
+ });
45
+ const serverHandler = () => this.emit('link:ready', { url, params: queryParams });
46
+ const eventHandler = () => (e) => {
47
+ if (e.errno === 'EADDRINUSE') {
48
+ reject(new Error(`Port ${resolvedPort} is already in use by another process`));
49
+ }
50
+ else {
51
+ reject(new Error(`Failed to start Linker App: ${e.message}`));
52
+ }
53
+ };
54
+ if (isHttps) {
55
+ const privateKey = await fs_extra_1.default.readFile(path_1.default.resolve(__dirname, '../../certs/localhost.key'), 'utf-8');
56
+ const certificate = await fs_extra_1.default.readFile(path_1.default.resolve(__dirname, '../../certs/localhost.crt'), 'utf-8');
57
+ const credentials = { key: privateKey, cert: certificate };
58
+ const httpsServer = https_1.default.createServer(credentials, this.app);
59
+ httpsServer.listen(resolvedPort, serverHandler).on('error', eventHandler);
60
+ }
61
+ else {
62
+ this.app.listen(resolvedPort, serverHandler).on('error', eventHandler);
63
+ }
64
+ });
65
+ }
66
+ async getSceneInfo(rootCID, skipValidations) {
67
+ const { LANDRegistry, EstateRegistry } = (0, config_1.getCustomConfig)();
68
+ const { scene: { parcels, base }, display } = await this.project.getSceneFile();
69
+ return {
70
+ baseParcel: base,
71
+ parcels,
72
+ rootCID,
73
+ landRegistry: LANDRegistry,
74
+ estateRegistry: EstateRegistry,
75
+ debug: (0, env_1.isDebug)(),
76
+ title: display === null || display === void 0 ? void 0 : display.title,
77
+ description: display === null || display === void 0 ? void 0 : display.description,
78
+ skipValidations
79
+ };
80
+ }
81
+ setRoutes(rootCID, skipValidations) {
82
+ const linkerDapp = path_1.default.dirname(require.resolve('@dcl/linker-dapp/package.json'));
83
+ this.app.use((0, cors_1.default)());
84
+ this.app.use(express_1.default.static(linkerDapp));
85
+ this.app.use(body_parser_1.default.json());
86
+ /**
87
+ * Async method to try/catch errors
88
+ */
89
+ const methods = ['Get', 'Post'];
90
+ for (const method of methods) {
91
+ const asyncMethod = `async${method}`;
92
+ this.app[asyncMethod] = async (path, fn) => {
93
+ const originalMethod = method.toLocaleLowerCase();
94
+ this.app[originalMethod](path, async (req, res) => {
95
+ try {
96
+ const resp = await fn(req, res);
97
+ res.send(resp || {});
98
+ }
99
+ catch (e) {
100
+ console.log(e);
101
+ res.send(e);
102
+ }
103
+ });
104
+ };
105
+ }
106
+ this.app.asyncGet('/api/info', async () => {
107
+ return await this.getSceneInfo(rootCID, skipValidations);
108
+ });
109
+ this.app.asyncGet('/api/files', async () => {
110
+ const files = (await this.project.getFiles({ cache: true })).map((file) => ({
111
+ name: file.path,
112
+ size: file.size
113
+ }));
114
+ return files;
115
+ });
116
+ this.app.asyncGet('/api/catalyst-pointers', async () => {
117
+ var _a, _b, _c;
118
+ const { x, y } = await this.project.getParcelCoordinates();
119
+ const pointer = `${x},${y}`;
120
+ const chainId = ((_b = (_a = this.project.getDeployInfo()) === null || _a === void 0 ? void 0 : _a.linkerResponse) === null || _b === void 0 ? void 0 : _b.chainId) || 1;
121
+ const network = chainId === schemas_1.ChainId.ETHEREUM_MAINNET ? 'mainnet' : 'sepolia';
122
+ const value = await (0, catalystPointers_1.getPointers)(pointer, network);
123
+ return {
124
+ catalysts: value,
125
+ status: (_c = this.project.getDeployInfo().status) !== null && _c !== void 0 ? _c : ''
126
+ };
127
+ });
128
+ this.app.get('/api/close', (req, res) => {
129
+ res.writeHead(200);
130
+ res.end();
131
+ const { ok, reason } = url_1.default.parse(req.url, true).query;
132
+ if (ok === 'true') {
133
+ const value = JSON.parse((reason === null || reason === void 0 ? void 0 : reason.toString()) || '{}');
134
+ this.project.setDeployInfo({ linkerResponse: value });
135
+ this.emit('link:success', value);
136
+ }
137
+ this.emit('link:error', new Error(`Failed to link: ${reason}`));
138
+ });
139
+ this.app.asyncPost('/api/deploy', (req) => {
140
+ const value = req.body;
141
+ if (!value.address || !value.signature || !value.chainId) {
142
+ throw new Error(`Invalid payload: ${Object.keys(value).join(' - ')}`);
143
+ }
144
+ this.project.setDeployInfo({ linkerResponse: value, status: 'deploying' });
145
+ this.emit('link:success', value);
146
+ // this.emit('link:error', new Error(`Failed to link: ${reason}`))
147
+ });
148
+ }
149
+ }
150
+ exports.LinkerAPI = LinkerAPI;
151
+ //# sourceMappingURL=LinkerAPI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkerAPI.js","sourceRoot":"","sources":["../../src/lib/LinkerAPI.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,kDAA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,GAAG,CAAC,IAAY,CAAA;YAE9B,IAAI,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE;gBACxD,MAAM,IAAI,KAAK,CAAC,oBAAoB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;aACtE;YAED,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAA;YAC1E,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;YAChC,kEAAkE;QACpE,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AA5JD,8BA4JC"}
@@ -0,0 +1,17 @@
1
+ import { Decentraland } from './Decentraland';
2
+ import { ILoggerComponent, IMetricsComponent, IHttpServerComponent, IConfigComponent } from '@well-known-components/interfaces';
3
+ import { HTTPProvider } from 'eth-connect';
4
+ import { RoomComponent } from '@dcl/mini-comms/dist/adapters/rooms';
5
+ import { WebSocketComponent } from './adapters/ws';
6
+ export declare type PreviewComponents = {
7
+ logs: ILoggerComponent;
8
+ server: IHttpServerComponent<PreviewComponents>;
9
+ config: IConfigComponent;
10
+ metrics: IMetricsComponent<any>;
11
+ ethereumProvider: HTTPProvider;
12
+ rooms: RoomComponent;
13
+ dcl: Decentraland;
14
+ ws: WebSocketComponent;
15
+ };
16
+ export declare function wirePreview(components: PreviewComponents, watch: boolean): Promise<void>;
17
+ //# sourceMappingURL=Preview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Preview.d.ts","sourceRoot":"","sources":["../../src/lib/Preview.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAEnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAMlD,oBAAY,iBAAiB,GAAG;IAC9B,IAAI,EAAE,gBAAgB,CAAA;IACtB,MAAM,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,CAAA;IAC/C,MAAM,EAAE,gBAAgB,CAAA;IACxB,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAA;IAC/B,gBAAgB,EAAE,YAAY,CAAA;IAC9B,KAAK,EAAE,aAAa,CAAA;IACpB,GAAG,EAAE,YAAY,CAAA;IACjB,EAAE,EAAE,kBAAkB,CAAA;CACvB,CAAA;AAED,wBAAsB,WAAW,CAAC,UAAU,EAAE,iBAAiB,EAAE,KAAK,EAAE,OAAO,iBA2E9E"}
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.wirePreview = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const ws_1 = __importDefault(require("ws"));
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const chokidar_1 = __importDefault(require("chokidar"));
11
+ const ignore_1 = __importDefault(require("ignore"));
12
+ const schemas_1 = require("@dcl/schemas");
13
+ const errors_1 = require("../utils/errors");
14
+ const bff_1 = require("./controllers/bff");
15
+ const http_server_1 = require("@well-known-components/http-server");
16
+ const legacy_comms_v1_1 = require("./controllers/legacy-comms-v1");
17
+ const debugger_1 = require("./controllers/debugger");
18
+ const ecs6_endpoints_1 = require("./controllers/ecs6-endpoints");
19
+ const ws_2 = require("@well-known-components/http-server/dist/ws");
20
+ async function wirePreview(components, watch) {
21
+ const npmModulesPath = path_1.default.resolve(components.dcl.getWorkingDir(), 'node_modules');
22
+ // TODO: dcl.project.needsDependencies() should do this
23
+ if (!fs_extra_1.default.pathExistsSync(npmModulesPath)) {
24
+ (0, errors_1.fail)(errors_1.ErrorType.PREVIEW_ERROR, `Couldn\'t find ${npmModulesPath}, please run: npm install`);
25
+ }
26
+ const proxySetupPathEcs6 = path_1.default.resolve(components.dcl.getWorkingDir(), 'node_modules', 'decentraland-ecs', 'src', 'setupProxyV2.js');
27
+ const proxySetupPathEcs7 = path_1.default.resolve(components.dcl.getWorkingDir(), 'node_modules', '@dcl', 'sdk', 'src', 'setupProxyV2.js');
28
+ // this should come BEFORE the custom proxy
29
+ const proxySetupPath = fs_extra_1.default.existsSync(proxySetupPathEcs7) ? proxySetupPathEcs7 : proxySetupPathEcs6;
30
+ const router = new http_server_1.Router();
31
+ const sceneUpdateClients = new Set();
32
+ // handle old comms
33
+ router.get('/', async (ctx, next) => {
34
+ if (ctx.request.headers.get('upgrade') === 'websocket') {
35
+ const userId = ctx.url.searchParams.get('identity');
36
+ if (userId) {
37
+ return (0, ws_2.upgradeWebSocketResponse)((ws) => {
38
+ adoptWebSocket(ws, userId);
39
+ });
40
+ }
41
+ else {
42
+ return (0, ws_2.upgradeWebSocketResponse)((ws) => {
43
+ if (ws.readyState === ws.OPEN) {
44
+ sceneUpdateClients.add(ws);
45
+ }
46
+ else {
47
+ ws.on('open', () => sceneUpdateClients.add(ws));
48
+ }
49
+ ws.on('close', () => sceneUpdateClients.delete(ws));
50
+ });
51
+ }
52
+ }
53
+ return next();
54
+ });
55
+ await (0, bff_1.setupBffAndComms)(components, router);
56
+ const { adoptWebSocket } = (0, legacy_comms_v1_1.setupCommsV1)(components, router);
57
+ await (0, debugger_1.setupDebuggingAdapter)(components, router);
58
+ await (0, ecs6_endpoints_1.setupEcs6Endpoints)(components, router);
59
+ if (watch) {
60
+ await bindWatch(components, router, sceneUpdateClients);
61
+ }
62
+ components.server.setContext(components);
63
+ components.server.use(router.allowedMethods());
64
+ components.server.use(router.middleware());
65
+ if (fs_extra_1.default.existsSync(proxySetupPath)) {
66
+ try {
67
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
68
+ const setupProxy = require(proxySetupPath);
69
+ setupProxy(router, components);
70
+ }
71
+ catch (err) {
72
+ console.log(`${proxySetupPath} found but it couldn't be loaded properly`, err);
73
+ }
74
+ }
75
+ }
76
+ exports.wirePreview = wirePreview;
77
+ function debounce(callback, delay) {
78
+ let debounceTimer;
79
+ return (...args) => {
80
+ clearTimeout(debounceTimer);
81
+ debounceTimer = setTimeout(() => callback(...args), delay);
82
+ };
83
+ }
84
+ async function bindWatch(components, router, sceneUpdateClients) {
85
+ for (const project of components.dcl.workspace.getAllProjects()) {
86
+ const ig = (0, ignore_1.default)().add((await project.getDCLIgnore()));
87
+ const { sceneId, sceneType } = project.getInfo();
88
+ const sceneFile = await project.getSceneFile();
89
+ chokidar_1.default.watch(project.getProjectWorkingDir()).on('all', debounce((_, pathWatch) => {
90
+ // if the updated file is the scene.json#main then skip all drop tests
91
+ if (path_1.default.resolve(pathWatch) !== path_1.default.resolve(project.getProjectWorkingDir(), sceneFile.main)) {
92
+ if (ig.ignores(pathWatch)) {
93
+ return;
94
+ }
95
+ // ignore source files
96
+ if (pathWatch.endsWith('.ts') || pathWatch.endsWith('.tsx')) {
97
+ return;
98
+ }
99
+ }
100
+ sceneUpdateClients.forEach((ws) => {
101
+ if (ws.readyState === ws_1.default.OPEN) {
102
+ const message = {
103
+ type: schemas_1.sdk.SCENE_UPDATE,
104
+ payload: { sceneId, sceneType }
105
+ };
106
+ ws.send(schemas_1.sdk.UPDATE);
107
+ ws.send(JSON.stringify(message));
108
+ }
109
+ });
110
+ }, 500));
111
+ }
112
+ }
113
+ //# sourceMappingURL=Preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Preview.js","sourceRoot":"","sources":["../../src/lib/Preview.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB,4CAA0B;AAC1B,wDAAyB;AAEzB,wD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