@vtex/api 6.48.0 → 6.48.1-beta

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 (402) hide show
  1. package/gen/manifest.schema +0 -3
  2. package/lib/{clients/apps → HttpClient}/AppClient.d.ts +3 -3
  3. package/lib/{clients/apps → HttpClient}/AppClient.js +5 -10
  4. package/lib/{clients/apps → HttpClient}/AppGraphQLClient.d.ts +3 -3
  5. package/lib/{clients/apps → HttpClient}/AppGraphQLClient.js +5 -10
  6. package/lib/{clients/external → HttpClient}/ExternalClient.d.ts +3 -3
  7. package/lib/{clients/external → HttpClient}/ExternalClient.js +2 -9
  8. package/lib/HttpClient/GraphQLClient.d.ts +1 -2
  9. package/lib/HttpClient/GraphQLClient.js +1 -4
  10. package/lib/HttpClient/HttpClient.d.ts +5 -6
  11. package/lib/HttpClient/HttpClient.js +21 -63
  12. package/lib/{clients → HttpClient}/IOClient.d.ts +4 -4
  13. package/lib/HttpClient/IOClient.js +14 -0
  14. package/lib/{clients → HttpClient}/IOGraphQLClient.d.ts +4 -4
  15. package/lib/{clients → HttpClient}/IOGraphQLClient.js +2 -2
  16. package/lib/{clients/infra → HttpClient}/InfraClient.d.ts +3 -3
  17. package/lib/{clients/infra → HttpClient}/InfraClient.js +4 -9
  18. package/lib/{clients/janus → HttpClient}/JanusClient.d.ts +3 -3
  19. package/lib/{clients/janus → HttpClient}/JanusClient.js +3 -7
  20. package/lib/HttpClient/factories/index.d.ts +8 -0
  21. package/lib/HttpClient/factories/index.js +31 -0
  22. package/lib/HttpClient/index.d.ts +7 -1
  23. package/lib/HttpClient/index.js +7 -1
  24. package/lib/HttpClient/middlewares/cache.d.ts +2 -8
  25. package/lib/HttpClient/middlewares/cache.js +31 -120
  26. package/lib/HttpClient/middlewares/cancellationToken.d.ts +1 -1
  27. package/lib/HttpClient/middlewares/cancellationToken.js +1 -2
  28. package/lib/HttpClient/middlewares/memoization.js +1 -8
  29. package/lib/HttpClient/middlewares/metrics.js +31 -12
  30. package/lib/HttpClient/middlewares/recorder.d.ts +1 -1
  31. package/lib/HttpClient/middlewares/recorder.js +13 -16
  32. package/lib/HttpClient/middlewares/request.d.ts +10 -0
  33. package/lib/HttpClient/middlewares/request.js +87 -0
  34. package/lib/HttpClient/typings.d.ts +9 -43
  35. package/lib/IODataSource.d.ts +27 -0
  36. package/lib/IODataSource.js +46 -0
  37. package/lib/caches/LRUCache.js +1 -5
  38. package/lib/caches/LRUDiskCache.js +1 -5
  39. package/lib/clients/Apps.d.ts +84 -0
  40. package/lib/clients/Apps.js +326 -0
  41. package/lib/clients/Assets.d.ts +21 -0
  42. package/lib/clients/{infra/Assets.js → Assets.js} +19 -74
  43. package/lib/clients/Billing.d.ts +11 -0
  44. package/lib/clients/{apps/Billing.js → Billing.js} +3 -8
  45. package/lib/clients/BillingMetrics.d.ts +12 -0
  46. package/lib/clients/BillingMetrics.js +10 -0
  47. package/lib/clients/{apps/Builder.d.ts → Builder.d.ts} +11 -12
  48. package/lib/clients/{apps/Builder.js → Builder.js} +22 -49
  49. package/lib/clients/Events.d.ts +6 -0
  50. package/lib/clients/Events.js +19 -0
  51. package/lib/clients/Housekeeper.d.ts +11 -0
  52. package/lib/clients/Housekeeper.js +24 -0
  53. package/lib/clients/ID.d.ts +22 -0
  54. package/lib/clients/ID.js +48 -0
  55. package/lib/clients/IOClients.d.ts +24 -28
  56. package/lib/clients/IOClients.js +28 -35
  57. package/lib/clients/LicenseManager.d.ts +6 -0
  58. package/lib/clients/{janus/LicenseManager.js → LicenseManager.js} +8 -23
  59. package/lib/clients/Logger.d.ts +27 -0
  60. package/lib/clients/Logger.js +32 -0
  61. package/lib/clients/Messages.d.ts +18 -0
  62. package/lib/clients/Messages.js +20 -0
  63. package/lib/clients/MessagesGraphQL.d.ts +63 -0
  64. package/lib/clients/MessagesGraphQL.js +50 -0
  65. package/lib/clients/Metadata.d.ts +25 -0
  66. package/lib/clients/Metadata.js +53 -0
  67. package/lib/clients/Registry.d.ts +61 -0
  68. package/lib/clients/{infra/Registry.js → Registry.js} +33 -93
  69. package/lib/clients/Router.d.ts +33 -0
  70. package/lib/clients/Router.js +50 -0
  71. package/lib/clients/{janus/Segment.d.ts → Segment.d.ts} +11 -7
  72. package/lib/clients/Segment.js +69 -0
  73. package/lib/clients/{janus/Session.d.ts → Session.d.ts} +4 -4
  74. package/lib/clients/{janus/Session.js → Session.js} +13 -24
  75. package/lib/clients/{apps/Settings.d.ts → Settings.d.ts} +4 -5
  76. package/lib/clients/{apps/Settings.js → Settings.js} +20 -14
  77. package/lib/clients/Sphinx.d.ts +12 -0
  78. package/lib/clients/Sphinx.js +19 -0
  79. package/lib/clients/{janus/Tenant.d.ts → Tenant.d.ts} +7 -6
  80. package/lib/clients/Tenant.js +13 -0
  81. package/lib/clients/VBase.d.ts +57 -0
  82. package/lib/clients/VBase.js +116 -0
  83. package/lib/clients/Workspaces.d.ts +17 -0
  84. package/lib/clients/Workspaces.js +38 -0
  85. package/lib/clients/index.d.ts +21 -9
  86. package/lib/clients/index.js +21 -12
  87. package/lib/constants.d.ts +1 -49
  88. package/lib/constants.js +1 -54
  89. package/lib/errors/ResolverError.d.ts +1 -1
  90. package/lib/errors/ResolverError.js +2 -2
  91. package/lib/errors/ResolverWarning.d.ts +1 -1
  92. package/lib/errors/ResolverWarning.js +2 -2
  93. package/lib/index.d.ts +7 -9
  94. package/lib/index.js +6 -8
  95. package/lib/metrics/MetricsAccumulator.d.ts +18 -1
  96. package/lib/metrics/MetricsAccumulator.js +22 -38
  97. package/lib/responses.d.ts +44 -3
  98. package/lib/service/Runtime.d.ts +18 -0
  99. package/lib/service/Runtime.js +57 -0
  100. package/lib/service/{worker/runtime/Service.d.ts → Service.d.ts} +5 -5
  101. package/lib/service/{worker/runtime/Service.js → Service.js} +1 -2
  102. package/lib/service/events/index.d.ts +3 -0
  103. package/lib/service/events/index.js +21 -0
  104. package/lib/service/graphql/index.d.ts +7 -0
  105. package/lib/service/graphql/index.js +33 -0
  106. package/lib/service/graphql/middlewares/error.js +107 -0
  107. package/lib/service/graphql/middlewares/formatters.d.ts +2 -0
  108. package/lib/service/graphql/middlewares/formatters.js +64 -0
  109. package/lib/service/graphql/middlewares/query.d.ts +2 -0
  110. package/lib/service/graphql/middlewares/query.js +32 -0
  111. package/lib/service/graphql/middlewares/response.js +36 -0
  112. package/lib/service/graphql/middlewares/run.d.ts +4 -0
  113. package/lib/service/graphql/middlewares/run.js +55 -0
  114. package/lib/service/graphql/middlewares/schema.d.ts +2 -0
  115. package/lib/service/graphql/middlewares/schema.js +8 -0
  116. package/lib/service/graphql/middlewares/timings.d.ts +2 -0
  117. package/lib/service/graphql/middlewares/timings.js +10 -0
  118. package/lib/service/graphql/middlewares/upload.d.ts +7 -0
  119. package/lib/service/graphql/schema/index.d.ts +3 -0
  120. package/lib/service/graphql/schema/index.js +66 -0
  121. package/lib/service/graphql/schema/messagesLoader.d.ts +4 -0
  122. package/lib/service/graphql/schema/messagesLoader.js +41 -0
  123. package/lib/service/graphql/schema/messagesLoaderV2.d.ts +5 -0
  124. package/lib/service/graphql/schema/messagesLoaderV2.js +44 -0
  125. package/lib/service/{worker/runtime/graphql → graphql}/schema/schemaDirectives/Auth.d.ts +0 -1
  126. package/lib/service/{worker/runtime/graphql → graphql}/schema/schemaDirectives/Auth.js +10 -16
  127. package/lib/service/{worker/runtime/graphql → graphql}/schema/schemaDirectives/Sanitize.d.ts +0 -1
  128. package/lib/service/{worker/runtime/graphql → graphql}/schema/schemaDirectives/Sanitize.js +0 -6
  129. package/lib/service/{worker/runtime/graphql → graphql}/schema/schemaDirectives/SmartCacheDirective.d.ts +0 -1
  130. package/lib/service/{worker/runtime/graphql → graphql}/schema/schemaDirectives/SmartCacheDirective.js +3 -8
  131. package/lib/service/{worker/runtime/graphql/schema/schemaDirectives/TranslateTo.d.ts → graphql/schema/schemaDirectives/Translatable.d.ts} +1 -2
  132. package/lib/service/graphql/schema/schemaDirectives/Translatable.js +54 -0
  133. package/lib/service/graphql/schema/schemaDirectives/TranslatableV2.d.ts +13 -0
  134. package/lib/service/graphql/schema/schemaDirectives/TranslatableV2.js +67 -0
  135. package/lib/service/graphql/schema/schemaDirectives/index.d.ts +13 -0
  136. package/lib/service/graphql/schema/schemaDirectives/index.js +17 -0
  137. package/lib/service/graphql/schema/typeDefs/index.d.ts +16 -0
  138. package/lib/service/graphql/schema/typeDefs/index.js +21 -0
  139. package/lib/service/graphql/schema/typeDefs/ioMessage.d.ts +8 -0
  140. package/lib/service/graphql/schema/typeDefs/ioMessage.js +33 -0
  141. package/lib/service/{worker/runtime/graphql → graphql}/schema/typeDefs/sanitizedString.js +1 -5
  142. package/lib/service/graphql/typings.d.ts +21 -0
  143. package/lib/service/graphql/utils/cacheControl.d.ts +6 -0
  144. package/lib/service/graphql/utils/cacheControl.js +38 -0
  145. package/lib/service/graphql/utils/maxAgeEnum.d.ts +6 -0
  146. package/lib/service/graphql/utils/maxAgeEnum.js +17 -0
  147. package/lib/service/http/index.d.ts +3 -0
  148. package/lib/service/http/index.js +18 -0
  149. package/lib/service/http/middlewares/authTokens.d.ts +3 -0
  150. package/lib/service/http/middlewares/cancellationToken.d.ts +3 -0
  151. package/lib/service/{worker/runtime/http → http}/middlewares/cancellationToken.js +1 -2
  152. package/lib/service/http/middlewares/clients.d.ts +4 -0
  153. package/lib/service/http/middlewares/error.d.ts +3 -0
  154. package/lib/service/{worker/runtime/http → http}/middlewares/error.js +10 -19
  155. package/lib/service/{worker/runtime/http → http}/middlewares/requestStats.d.ts +3 -3
  156. package/lib/service/http/middlewares/setCookie.d.ts +3 -0
  157. package/lib/service/http/middlewares/timings.d.ts +3 -0
  158. package/lib/service/{worker/runtime/http → http}/middlewares/timings.js +8 -21
  159. package/lib/service/http/middlewares/vary.d.ts +3 -0
  160. package/lib/service/{worker/runtime/http → http}/middlewares/vary.js +3 -3
  161. package/lib/service/logger/index.d.ts +28 -2
  162. package/lib/service/logger/index.js +68 -5
  163. package/lib/service/method.d.ts +9 -0
  164. package/lib/service/{worker/runtime/typings.d.ts → typings.d.ts} +36 -70
  165. package/lib/service/utils/compose.d.ts +4 -0
  166. package/lib/service/{worker/runtime/utils → utils}/compose.js +2 -2
  167. package/lib/utils/MineWinsConflictsResolver.d.ts +4 -6
  168. package/lib/utils/MineWinsConflictsResolver.js +17 -34
  169. package/lib/utils/MineWinsConflictsResolver.test.d.ts +1 -0
  170. package/lib/utils/MineWinsConflictsResolver.test.js +134 -0
  171. package/lib/utils/app.d.ts +1 -3
  172. package/lib/utils/app.js +1 -3
  173. package/lib/utils/appsStaleIfError.d.ts +1 -1
  174. package/lib/utils/appsStaleIfError.js +2 -2
  175. package/lib/utils/billingOptions.d.ts +3 -36
  176. package/lib/utils/billingOptions.js +3 -7
  177. package/lib/utils/binding.d.ts +3 -3
  178. package/lib/utils/cancel.d.ts +2 -2
  179. package/lib/utils/cancel.js +1 -2
  180. package/lib/utils/log.d.ts +3 -1
  181. package/lib/utils/log.js +2 -2
  182. package/lib/utils/message.js +1 -4
  183. package/lib/utils/tenant.d.ts +3 -3
  184. package/lib/utils/time.d.ts +2 -4
  185. package/lib/utils/time.js +2 -9
  186. package/lib/utils/unhandled.d.ts +1 -0
  187. package/lib/{service/worker/listeners.js → utils/unhandled.js} +15 -9
  188. package/package.json +2 -2
  189. package/CHANGELOG.md +0 -1858
  190. package/lib/HttpClient/agents.d.ts +0 -3
  191. package/lib/HttpClient/agents.js +0 -24
  192. package/lib/HttpClient/middlewares/request/HttpAgentSingleton.d.ts +0 -11
  193. package/lib/HttpClient/middlewares/request/HttpAgentSingleton.js +0 -30
  194. package/lib/HttpClient/middlewares/request/index.d.ts +0 -18
  195. package/lib/HttpClient/middlewares/request/index.js +0 -84
  196. package/lib/HttpClient/middlewares/request/setupAxios/index.d.ts +0 -1
  197. package/lib/HttpClient/middlewares/request/setupAxios/index.js +0 -20
  198. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.d.ts +0 -2
  199. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.js +0 -53
  200. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.d.ts +0 -2
  201. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.js +0 -7
  202. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.d.ts +0 -8
  203. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +0 -53
  204. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.d.ts +0 -4
  205. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +0 -29
  206. package/lib/HttpClient/middlewares/tracing.d.ts +0 -15
  207. package/lib/HttpClient/middlewares/tracing.js +0 -56
  208. package/lib/clients/IOClient.js +0 -19
  209. package/lib/clients/apps/Billing.d.ts +0 -12
  210. package/lib/clients/apps/MessagesGraphQL.d.ts +0 -61
  211. package/lib/clients/apps/MessagesGraphQL.js +0 -121
  212. package/lib/clients/apps/catalogGraphQL/brand.d.ts +0 -13
  213. package/lib/clients/apps/catalogGraphQL/brand.js +0 -18
  214. package/lib/clients/apps/catalogGraphQL/category.d.ts +0 -11
  215. package/lib/clients/apps/catalogGraphQL/category.js +0 -16
  216. package/lib/clients/apps/catalogGraphQL/index.d.ts +0 -22
  217. package/lib/clients/apps/catalogGraphQL/index.js +0 -88
  218. package/lib/clients/apps/catalogGraphQL/product.d.ts +0 -25
  219. package/lib/clients/apps/catalogGraphQL/product.js +0 -30
  220. package/lib/clients/apps/catalogGraphQL/sku.d.ts +0 -26
  221. package/lib/clients/apps/catalogGraphQL/sku.js +0 -30
  222. package/lib/clients/apps/index.d.ts +0 -7
  223. package/lib/clients/apps/index.js +0 -12
  224. package/lib/clients/external/ID.d.ts +0 -23
  225. package/lib/clients/external/ID.js +0 -60
  226. package/lib/clients/external/Masterdata.d.ts +0 -94
  227. package/lib/clients/external/Masterdata.js +0 -224
  228. package/lib/clients/external/PaymentProvider.d.ts +0 -31
  229. package/lib/clients/external/PaymentProvider.js +0 -42
  230. package/lib/clients/external/index.d.ts +0 -4
  231. package/lib/clients/external/index.js +0 -9
  232. package/lib/clients/infra/Apps.d.ts +0 -88
  233. package/lib/clients/infra/Apps.js +0 -508
  234. package/lib/clients/infra/Assets.d.ts +0 -34
  235. package/lib/clients/infra/BillingMetrics.d.ts +0 -13
  236. package/lib/clients/infra/BillingMetrics.js +0 -15
  237. package/lib/clients/infra/Events.d.ts +0 -12
  238. package/lib/clients/infra/Events.js +0 -33
  239. package/lib/clients/infra/Housekeeper.d.ts +0 -10
  240. package/lib/clients/infra/Housekeeper.js +0 -30
  241. package/lib/clients/infra/Registry.d.ts +0 -59
  242. package/lib/clients/infra/Router.d.ts +0 -34
  243. package/lib/clients/infra/Router.js +0 -81
  244. package/lib/clients/infra/Sphinx.d.ts +0 -13
  245. package/lib/clients/infra/Sphinx.js +0 -29
  246. package/lib/clients/infra/VBase.d.ts +0 -60
  247. package/lib/clients/infra/VBase.js +0 -196
  248. package/lib/clients/infra/Workspaces.d.ts +0 -18
  249. package/lib/clients/infra/Workspaces.js +0 -65
  250. package/lib/clients/infra/index.d.ts +0 -11
  251. package/lib/clients/infra/index.js +0 -16
  252. package/lib/clients/janus/LicenseManager.d.ts +0 -7
  253. package/lib/clients/janus/Segment.js +0 -88
  254. package/lib/clients/janus/Tenant.js +0 -28
  255. package/lib/clients/janus/index.d.ts +0 -5
  256. package/lib/clients/janus/index.js +0 -10
  257. package/lib/service/index.d.ts +0 -2
  258. package/lib/service/index.js +0 -30
  259. package/lib/service/loaders.d.ts +0 -8
  260. package/lib/service/loaders.js +0 -54
  261. package/lib/service/logger/console.d.ts +0 -10
  262. package/lib/service/logger/console.js +0 -36
  263. package/lib/service/logger/logger.d.ts +0 -29
  264. package/lib/service/logger/logger.js +0 -61
  265. package/lib/service/logger/metricsLogger.d.ts +0 -40
  266. package/lib/service/logger/metricsLogger.js +0 -149
  267. package/lib/service/master.d.ts +0 -2
  268. package/lib/service/master.js +0 -87
  269. package/lib/service/metrics/requestMetricsMiddleware.d.ts +0 -2
  270. package/lib/service/metrics/requestMetricsMiddleware.js +0 -44
  271. package/lib/service/tracing/TracerSingleton.d.ts +0 -7
  272. package/lib/service/tracing/TracerSingleton.js +0 -48
  273. package/lib/service/tracing/metrics/MetricNames.d.ts +0 -60
  274. package/lib/service/tracing/metrics/MetricNames.js +0 -44
  275. package/lib/service/tracing/metrics/instruments.d.ts +0 -9
  276. package/lib/service/tracing/metrics/instruments.js +0 -11
  277. package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.d.ts +0 -9
  278. package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.js +0 -25
  279. package/lib/service/tracing/tracingMiddlewares.d.ts +0 -5
  280. package/lib/service/tracing/tracingMiddlewares.js +0 -107
  281. package/lib/service/worker/index.d.ts +0 -11
  282. package/lib/service/worker/index.js +0 -195
  283. package/lib/service/worker/listeners.d.ts +0 -3
  284. package/lib/service/worker/runtime/builtIn/handlers.d.ts +0 -4
  285. package/lib/service/worker/runtime/builtIn/handlers.js +0 -30
  286. package/lib/service/worker/runtime/builtIn/middlewares.d.ts +0 -4
  287. package/lib/service/worker/runtime/builtIn/middlewares.js +0 -40
  288. package/lib/service/worker/runtime/events/index.d.ts +0 -4
  289. package/lib/service/worker/runtime/events/index.js +0 -46
  290. package/lib/service/worker/runtime/events/middlewares/body.d.ts +0 -3
  291. package/lib/service/worker/runtime/events/middlewares/body.js +0 -22
  292. package/lib/service/worker/runtime/events/middlewares/context.d.ts +0 -3
  293. package/lib/service/worker/runtime/events/middlewares/context.js +0 -22
  294. package/lib/service/worker/runtime/events/router.d.ts +0 -2
  295. package/lib/service/worker/runtime/events/router.js +0 -27
  296. package/lib/service/worker/runtime/graphql/index.d.ts +0 -6
  297. package/lib/service/worker/runtime/graphql/index.js +0 -27
  298. package/lib/service/worker/runtime/graphql/middlewares/context.d.ts +0 -2
  299. package/lib/service/worker/runtime/graphql/middlewares/context.js +0 -16
  300. package/lib/service/worker/runtime/graphql/middlewares/error.js +0 -93
  301. package/lib/service/worker/runtime/graphql/middlewares/query.d.ts +0 -2
  302. package/lib/service/worker/runtime/graphql/middlewares/query.js +0 -52
  303. package/lib/service/worker/runtime/graphql/middlewares/response.js +0 -38
  304. package/lib/service/worker/runtime/graphql/middlewares/run.d.ts +0 -2
  305. package/lib/service/worker/runtime/graphql/middlewares/run.js +0 -19
  306. package/lib/service/worker/runtime/graphql/middlewares/updateSchema.d.ts +0 -4
  307. package/lib/service/worker/runtime/graphql/middlewares/updateSchema.js +0 -28
  308. package/lib/service/worker/runtime/graphql/middlewares/upload.d.ts +0 -4
  309. package/lib/service/worker/runtime/graphql/schema/index.d.ts +0 -7
  310. package/lib/service/worker/runtime/graphql/schema/index.js +0 -31
  311. package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.d.ts +0 -6
  312. package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.js +0 -79
  313. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.d.ts +0 -7
  314. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.js +0 -37
  315. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.d.ts +0 -11
  316. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.js +0 -61
  317. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.d.ts +0 -7
  318. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.js +0 -40
  319. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.d.ts +0 -6
  320. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.js +0 -34
  321. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.d.ts +0 -7
  322. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.js +0 -39
  323. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.js +0 -33
  324. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.d.ts +0 -22
  325. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.js +0 -36
  326. package/lib/service/worker/runtime/graphql/schema/typeDefs/index.d.ts +0 -7
  327. package/lib/service/worker/runtime/graphql/schema/typeDefs/index.js +0 -12
  328. package/lib/service/worker/runtime/graphql/typings.d.ts +0 -31
  329. package/lib/service/worker/runtime/graphql/utils/cacheControl.d.ts +0 -1
  330. package/lib/service/worker/runtime/graphql/utils/cacheControl.js +0 -32
  331. package/lib/service/worker/runtime/graphql/utils/error.d.ts +0 -1
  332. package/lib/service/worker/runtime/graphql/utils/error.js +0 -76
  333. package/lib/service/worker/runtime/graphql/utils/translations.d.ts +0 -14
  334. package/lib/service/worker/runtime/graphql/utils/translations.js +0 -38
  335. package/lib/service/worker/runtime/http/index.d.ts +0 -5
  336. package/lib/service/worker/runtime/http/index.js +0 -58
  337. package/lib/service/worker/runtime/http/middlewares/authTokens.d.ts +0 -3
  338. package/lib/service/worker/runtime/http/middlewares/cancellationToken.d.ts +0 -3
  339. package/lib/service/worker/runtime/http/middlewares/clients.d.ts +0 -4
  340. package/lib/service/worker/runtime/http/middlewares/context.d.ts +0 -4
  341. package/lib/service/worker/runtime/http/middlewares/context.js +0 -36
  342. package/lib/service/worker/runtime/http/middlewares/error.d.ts +0 -2
  343. package/lib/service/worker/runtime/http/middlewares/rateLimit.d.ts +0 -6
  344. package/lib/service/worker/runtime/http/middlewares/rateLimit.js +0 -42
  345. package/lib/service/worker/runtime/http/middlewares/setCookie.d.ts +0 -3
  346. package/lib/service/worker/runtime/http/middlewares/settings.d.ts +0 -9
  347. package/lib/service/worker/runtime/http/middlewares/settings.js +0 -44
  348. package/lib/service/worker/runtime/http/middlewares/timings.d.ts +0 -3
  349. package/lib/service/worker/runtime/http/middlewares/vary.d.ts +0 -3
  350. package/lib/service/worker/runtime/http/router.d.ts +0 -2
  351. package/lib/service/worker/runtime/http/router.js +0 -23
  352. package/lib/service/worker/runtime/http/routes.d.ts +0 -19
  353. package/lib/service/worker/runtime/http/routes.js +0 -12
  354. package/lib/service/worker/runtime/method.d.ts +0 -9
  355. package/lib/service/worker/runtime/statusTrack.d.ts +0 -14
  356. package/lib/service/worker/runtime/statusTrack.js +0 -37
  357. package/lib/service/worker/runtime/utils/compose.d.ts +0 -5
  358. package/lib/service/worker/runtime/utils/context.d.ts +0 -2
  359. package/lib/service/worker/runtime/utils/context.js +0 -40
  360. package/lib/service/worker/runtime/utils/diff.d.ts +0 -12
  361. package/lib/service/worker/runtime/utils/diff.js +0 -21
  362. package/lib/service/worker/runtime/utils/recorder.d.ts +0 -8
  363. package/lib/service/worker/runtime/utils/recorder.js +0 -37
  364. package/lib/service/worker/runtime/utils/tokenBucket.d.ts +0 -2
  365. package/lib/service/worker/runtime/utils/tokenBucket.js +0 -16
  366. package/lib/tracing/LogEvents.d.ts +0 -31
  367. package/lib/tracing/LogEvents.js +0 -3
  368. package/lib/tracing/LogFields.d.ts +0 -66
  369. package/lib/tracing/LogFields.js +0 -3
  370. package/lib/tracing/Tags.d.ts +0 -81
  371. package/lib/tracing/Tags.js +0 -7
  372. package/lib/tracing/UserLandTracer.d.ts +0 -27
  373. package/lib/tracing/UserLandTracer.js +0 -56
  374. package/lib/tracing/errorReporting/ErrorReport.d.ts +0 -31
  375. package/lib/tracing/errorReporting/ErrorReport.js +0 -70
  376. package/lib/tracing/index.d.ts +0 -9
  377. package/lib/tracing/index.js +0 -19
  378. package/lib/tracing/spanReference/SpanReferenceTypes.d.ts +0 -4
  379. package/lib/tracing/spanReference/SpanReferenceTypes.js +0 -7
  380. package/lib/tracing/spanReference/createSpanReference.d.ts +0 -3
  381. package/lib/tracing/spanReference/createSpanReference.js +0 -8
  382. package/lib/tracing/utils.d.ts +0 -13
  383. package/lib/tracing/utils.js +0 -40
  384. package/lib/utils/conflicts.mock.d.ts +0 -17
  385. package/lib/utils/conflicts.mock.js +0 -27
  386. /package/lib/service/{worker/runtime/graphql → graphql}/middlewares/error.d.ts +0 -0
  387. /package/lib/service/{worker/runtime/graphql → graphql}/middlewares/response.d.ts +0 -0
  388. /package/lib/service/{worker/runtime/graphql → graphql}/middlewares/upload.js +0 -0
  389. /package/lib/service/{worker/runtime/graphql → graphql}/schema/typeDefs/ioUpload.d.ts +0 -0
  390. /package/lib/service/{worker/runtime/graphql → graphql}/schema/typeDefs/ioUpload.js +0 -0
  391. /package/lib/service/{worker/runtime/graphql → graphql}/schema/typeDefs/sanitizedString.d.ts +0 -0
  392. /package/lib/service/{worker/runtime/graphql → graphql}/typings.js +0 -0
  393. /package/lib/service/{worker/runtime/utils/toArray.d.ts → graphql/utils/array.d.ts} +0 -0
  394. /package/lib/service/{worker/runtime/utils/toArray.js → graphql/utils/array.js} +0 -0
  395. /package/lib/service/{worker/runtime/graphql → graphql}/utils/pathname.d.ts +0 -0
  396. /package/lib/service/{worker/runtime/graphql → graphql}/utils/pathname.js +0 -0
  397. /package/lib/service/{worker/runtime/http → http}/middlewares/authTokens.js +0 -0
  398. /package/lib/service/{worker/runtime/http → http}/middlewares/clients.js +0 -0
  399. /package/lib/service/{worker/runtime/http → http}/middlewares/requestStats.js +0 -0
  400. /package/lib/service/{worker/runtime/http → http}/middlewares/setCookie.js +0 -0
  401. /package/lib/service/{worker/runtime/method.js → method.js} +0 -0
  402. /package/lib/service/{worker/runtime/typings.js → typings.js} +0 -0
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const apollo_datasource_1 = require("apollo-datasource");
4
+ const HttpClient_1 = require("./HttpClient");
5
+ /**
6
+ * @deprecated Extend one of the subclasses of IOClient instead.
7
+ */
8
+ class IODataSource extends apollo_datasource_1.DataSource {
9
+ constructor(context, options = {}) {
10
+ super();
11
+ this.context = context;
12
+ this.options = options;
13
+ this.service = undefined;
14
+ this.httpClient = undefined;
15
+ this.initialized = false;
16
+ }
17
+ initialize(config) {
18
+ const { context: { vtex: context }, cache: cacheStorage } = config;
19
+ this.context = context;
20
+ this.httpClient = this.httpClientFactory({
21
+ context,
22
+ options: Object.assign({ cacheStorage }, this.options),
23
+ service: this.service,
24
+ });
25
+ this.initialized = true;
26
+ }
27
+ get http() {
28
+ if (!this.initialized) {
29
+ this.initialize({ context: { vtex: this.context } });
30
+ }
31
+ if (this.httpClient) {
32
+ return this.httpClient;
33
+ }
34
+ throw new Error('IO Datasource was not initialized nor constructed with a context');
35
+ }
36
+ }
37
+ exports.IODataSource = IODataSource;
38
+ exports.forWorkspace = ({ context, service, options }) => (context && service)
39
+ ? HttpClient_1.HttpClient.forWorkspace(service, context, options || {})
40
+ : undefined;
41
+ exports.forRoot = ({ context, service, options }) => (context && service)
42
+ ? HttpClient_1.HttpClient.forRoot(service, context, options || {})
43
+ : undefined;
44
+ exports.forExternal = ({ context, service, options }) => (context && service)
45
+ ? HttpClient_1.HttpClient.forExternal(service, context, options || {})
46
+ : undefined;
@@ -37,11 +37,7 @@ class LRUCache {
37
37
  this.hits = 0;
38
38
  this.total = 0;
39
39
  this.disposed = 0;
40
- this.storage = new lru_cache_1.default({
41
- ...options,
42
- dispose: () => this.disposed += 1,
43
- noDisposeOnSet: true,
44
- });
40
+ this.storage = new lru_cache_1.default(Object.assign({}, options, { dispose: () => this.disposed += 1, noDisposeOnSet: true }));
45
41
  this.multilayer = new MultilayeredCache_1.MultilayeredCache([this]);
46
42
  }
47
43
  }
@@ -121,11 +121,7 @@ class LRUDiskCache {
121
121
  this.keyToBeDeleted = key;
122
122
  this.disposed += 1;
123
123
  };
124
- const lruOptions = {
125
- ...options,
126
- dispose,
127
- noDisposeOnSet: true,
128
- };
124
+ const lruOptions = Object.assign({}, options, { dispose, noDisposeOnSet: true });
129
125
  this.lruStorage = new lru_cache_1.default(lruOptions);
130
126
  }
131
127
  }
@@ -0,0 +1,84 @@
1
+ /// <reference types="node" />
2
+ import { IncomingMessage } from 'http';
3
+ import { Readable, Writable } from 'stream';
4
+ import { ZlibOptions } from 'zlib';
5
+ import { InfraClient, InstanceOptions } from '../HttpClient';
6
+ import { AppBundleLinked, AppFilesList, AppManifest } from '../responses';
7
+ import { IOContext } from '../service/typings';
8
+ export declare class Apps extends InfraClient {
9
+ private _routes;
10
+ private diskCache;
11
+ private memoryCache;
12
+ private readonly routes;
13
+ constructor(context: IOContext, options?: InstanceOptions);
14
+ installApp: (descriptor: string) => Promise<void>;
15
+ uninstallApp: (app: string) => Promise<import("..").IOResponse<void>>;
16
+ acknowledgeApp: (app: string, service: string) => Promise<void>;
17
+ link: (app: string, files: Change[], { zlib }?: ZipOptions) => Promise<AppBundleLinked>;
18
+ patch: (app: string, changes: Change[], { zlib }?: ZipOptions) => Promise<void>;
19
+ unlink: (app: string) => Promise<import("..").IOResponse<void>>;
20
+ unlinkAll: () => Promise<import("..").IOResponse<void>>;
21
+ saveAppSettings: (app: string, settings: any) => Promise<void>;
22
+ listApps: ({ oldVersion, since, service }?: ListAppsOptions) => Promise<AppsList>;
23
+ listAppFiles: (app: string, { prefix, nextMarker }?: ListFilesOptions) => Promise<AppFilesList>;
24
+ listLinks: () => Promise<string[]>;
25
+ getAppFile: (app: string, path: string, staleIfError?: boolean | undefined) => Promise<{
26
+ data: Buffer;
27
+ headers: any;
28
+ }>;
29
+ getAppJSON: <T extends object | null>(app: string, path: string, nullIfNotFound?: boolean | undefined) => Promise<T>;
30
+ getLinkedAppByWorkspaceJSON: <T extends object | null>(app: string, path: string, nullIfNotFound?: boolean | undefined) => Promise<T>;
31
+ getAppFileStream: (app: string, path: string) => Promise<IncomingMessage>;
32
+ getApp: (app: string) => Promise<AppManifest>;
33
+ getAppSettings: (app: string) => Promise<any>;
34
+ getAllAppsSettings: (listAppsOptions?: ListAppsOptions) => Promise<AppsSettings>;
35
+ getAppBundle: (app: string, bundlePath: string, generatePackageJson: boolean) => Promise<Readable>;
36
+ unpackAppBundle: (app: string, bundlePath: string, unpackPath: string, generatePackageJson: boolean) => Promise<Writable>;
37
+ getAppsMetaInfos: (filter?: string | undefined, staleWhileRevalidate?: boolean) => Promise<AppMetaInfo[]>;
38
+ getDependencies: (filter?: string) => Promise<Record<string, string[]>>;
39
+ updateDependencies: () => Promise<Record<string, string[]>>;
40
+ updateDependency: (name: string, version: string, registry: string) => Promise<void>;
41
+ resolveDependencies: (apps: string[], registries: string[], filter?: string) => Promise<any>;
42
+ resolveDependenciesWithManifest: (manifest: AppManifest, filter?: string) => Promise<Record<string, string[]>>;
43
+ private installRuntime;
44
+ }
45
+ interface ZipOptions {
46
+ zlib?: ZlibOptions;
47
+ }
48
+ export interface AppMetaInfo {
49
+ id: string;
50
+ settingsSchema?: Record<string, any>;
51
+ _resolvedDependencies: Record<string, string>;
52
+ _isRoot: boolean;
53
+ _buildFeatures: Record<string, string[]>;
54
+ }
55
+ export interface WorkspaceMetaInfo {
56
+ apps: AppMetaInfo[];
57
+ }
58
+ export interface AppsListItem {
59
+ app: string;
60
+ id: string;
61
+ location: string;
62
+ }
63
+ export interface AppsList {
64
+ data: AppsListItem[];
65
+ }
66
+ export interface Change {
67
+ path: string;
68
+ content: string | Readable | Buffer;
69
+ }
70
+ export interface ListAppsOptions {
71
+ oldVersion?: string;
72
+ context?: string[];
73
+ since?: string;
74
+ service?: string;
75
+ }
76
+ export interface ListFilesOptions {
77
+ prefix?: string;
78
+ context?: string[];
79
+ nextMarker?: string;
80
+ }
81
+ export interface AppsSettings {
82
+ [app: string]: any;
83
+ }
84
+ export {};
@@ -0,0 +1,326 @@
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
+ const archiver_1 = __importDefault(require("archiver"));
7
+ const ramda_1 = require("ramda");
8
+ const tar_fs_1 = require("tar-fs");
9
+ const zlib_1 = require("zlib");
10
+ const HttpClient_1 = require("../HttpClient");
11
+ const utils_1 = require("../utils");
12
+ const appsStaleIfError_1 = require("../utils/appsStaleIfError");
13
+ const createRoutes = ({ account, workspace }) => {
14
+ const routes = {
15
+ Acknowledge: (app, service) => `${routes.App(app)}/acknowledge/${service}`,
16
+ App: (app) => `${routes.Apps()}/${app}`,
17
+ AppBundle: (locator, path) => `${routes.AppOrRegistry(locator)}/bundle/${path}`,
18
+ AppOrRegistry: ({ name, version, build }) => build
19
+ ? `${routes.Apps()}/${name}@${version}+${build}`
20
+ : `${routes.Registry()}/${name}/${version}`,
21
+ Apps: () => `${routes.Workspace}/apps`,
22
+ Dependencies: () => `${routes.Workspace}/dependencies`,
23
+ File: (locator, path) => `${routes.Files(locator)}/${path}`,
24
+ Files: (locator) => `${routes.AppOrRegistry(locator)}/files`,
25
+ Link: (app) => `${routes.Workspace}/v2/links/${app}`,
26
+ LinkedAppFile: (app, path) => `${routes.Workspace}/apps/${app}/files/${path}`,
27
+ Links: () => `${routes.Workspace}/links`,
28
+ Master: `/${account}/master`,
29
+ Meta: () => `${routes.Workspace}/v2/apps`,
30
+ Registry: () => `${routes.Master}/registry`,
31
+ ResolveDependencies: () => `${routes.Workspace}/dependencies/_resolve`,
32
+ ResolveDependenciesWithManifest: () => `${routes.Workspace}/v2/apps/_resolve`,
33
+ Settings: (app) => `${routes.App(app)}/settings`,
34
+ Unlink: (app) => `${routes.Links()}/${app}`,
35
+ Workspace: `/${account}/${workspace}`,
36
+ };
37
+ return routes;
38
+ };
39
+ const getVendorAndName = ({ id }) => utils_1.removeVersionFromAppId(id);
40
+ const notFound = (e) => {
41
+ if (e.response && e.response.status === 404) {
42
+ return {};
43
+ }
44
+ throw e;
45
+ };
46
+ const zipObj = (keys, values) => {
47
+ let idx = 0;
48
+ const len = Math.min(keys.length, values.length);
49
+ const out = {};
50
+ while (idx < len) {
51
+ out[keys[idx]] = values[idx];
52
+ idx += 1;
53
+ }
54
+ return out;
55
+ };
56
+ const workspaceFields = [
57
+ '_resolvedDependencies',
58
+ 'settingsSchema',
59
+ '_isRoot',
60
+ '_buildFeatures',
61
+ ].join(',');
62
+ class Apps extends HttpClient_1.InfraClient {
63
+ constructor(context, options) {
64
+ super('apps@0.x', context, options, true);
65
+ this.installApp = (descriptor) => {
66
+ if (descriptor.startsWith('infra:service-')) {
67
+ return this.installRuntime(descriptor);
68
+ }
69
+ return this.http.post(this.routes.Apps(), { id: descriptor }, { metric: 'apps-install' });
70
+ };
71
+ this.uninstallApp = (app) => {
72
+ return this.http.delete(this.routes.App(app), { metric: 'apps-uninstall' });
73
+ };
74
+ this.acknowledgeApp = (app, service) => {
75
+ return this.http.put(this.routes.Acknowledge(app, service), null, { metric: 'apps-ack' });
76
+ };
77
+ this.link = async (app, files, { zlib } = {}) => {
78
+ if (!(files[0] && files[0].path)) {
79
+ throw new Error('Argument files must be an array of {path, content}, where content can be a String, a Buffer or a ReadableStream.');
80
+ }
81
+ const emptyChanges = files.filter(file => !file.content);
82
+ if (emptyChanges.length > 0) {
83
+ throw new Error(`Missing content for paths: ${emptyChanges.map(e => e.path).join('; ')}`);
84
+ }
85
+ const indexOfManifest = files.findIndex(({ path }) => path === 'manifest.json');
86
+ if (indexOfManifest === -1) {
87
+ throw new Error('No manifest.json file found in files.');
88
+ }
89
+ const zip = archiver_1.default('zip', { zlib });
90
+ // Throw stream errors so they reject the promise chain.
91
+ zip.on('error', (e) => {
92
+ throw e;
93
+ });
94
+ const request = this.http.put(this.routes.Link(app), zip, {
95
+ headers: { 'Content-Type': 'application/zip' },
96
+ metric: 'apps-link',
97
+ });
98
+ files.forEach(({ content, path }) => zip.append(content, { name: path }));
99
+ const finalize = zip.finalize();
100
+ try {
101
+ const [response] = await Promise.all([request, finalize]);
102
+ response.bundleSize = zip.pointer();
103
+ return response;
104
+ }
105
+ catch (e) {
106
+ e.bundleSize = zip.pointer();
107
+ throw e;
108
+ }
109
+ };
110
+ this.patch = async (app, changes, { zlib } = {}) => {
111
+ if (!(changes[0] && changes[0].path)) {
112
+ throw new Error('Argument changes must be an array of {path, content}, where content can be a String, a Buffer or a ReadableStream.');
113
+ }
114
+ const files = changes.filter(change => !!change.content);
115
+ const deletedFiles = changes
116
+ .filter(change => !change.content)
117
+ .map(change => change.path)
118
+ .join(':');
119
+ const zip = archiver_1.default('zip', { zlib });
120
+ // Throw stream errors so they reject the promise chain.
121
+ zip.on('error', (e) => {
122
+ throw e;
123
+ });
124
+ const request = this.http.patch(this.routes.Link(app), zip, {
125
+ headers: { 'Content-Type': 'application/zip' },
126
+ metric: 'apps-patch',
127
+ params: { deletedFiles },
128
+ });
129
+ files.forEach(({ content, path }) => zip.append(content, { name: path }));
130
+ const finalize = zip.finalize();
131
+ const [response] = await Promise.all([request, finalize]);
132
+ return response;
133
+ };
134
+ this.unlink = (app) => {
135
+ return this.http.delete(this.routes.Unlink(app));
136
+ };
137
+ this.unlinkAll = () => {
138
+ return this.http.delete(this.routes.Links());
139
+ };
140
+ this.saveAppSettings = (app, settings) => {
141
+ const headers = { 'Content-Type': 'application/json' };
142
+ const metric = 'apps-save';
143
+ return this.http.put(this.routes.Settings(app), settings, { headers, metric });
144
+ };
145
+ this.listApps = ({ oldVersion, since, service } = {}) => {
146
+ const params = {
147
+ oldVersion,
148
+ service,
149
+ since,
150
+ };
151
+ const metric = 'apps-list';
152
+ const inflightKey = HttpClient_1.inflightUrlWithQuery;
153
+ return this.http.get(this.routes.Apps(), { params, metric, inflightKey });
154
+ };
155
+ this.listAppFiles = (app, { prefix, nextMarker } = {}) => {
156
+ const locator = utils_1.parseAppId(app);
157
+ const linked = !!locator.build;
158
+ const params = {
159
+ marker: nextMarker,
160
+ prefix,
161
+ };
162
+ const metric = linked ? 'apps-list-files' : 'registry-list-files';
163
+ const inflightKey = HttpClient_1.inflightUrlWithQuery;
164
+ return this.http.get(this.routes.Files(locator), { params, metric, inflightKey });
165
+ };
166
+ this.listLinks = () => {
167
+ const inflightKey = HttpClient_1.inflightURL;
168
+ return this.http.get(this.routes.Links(), { metric: 'apps-list-links', inflightKey });
169
+ };
170
+ this.getAppFile = (app, path, staleIfError) => {
171
+ const { logger } = this.context;
172
+ const locator = utils_1.parseAppId(app);
173
+ const linked = !!locator.build;
174
+ const inflightKey = HttpClient_1.inflightURL;
175
+ if (staleIfError && this.memoryCache) {
176
+ appsStaleIfError_1.saveVersion(app, this.memoryCache);
177
+ }
178
+ try {
179
+ return this.http.getBuffer(this.routes.File(locator, path), {
180
+ cacheable: linked ? HttpClient_1.CacheType.Memory : HttpClient_1.CacheType.Disk,
181
+ inflightKey,
182
+ metric: linked ? 'apps-get-file' : 'registry-get-file',
183
+ });
184
+ }
185
+ catch (error) {
186
+ logger.error({ error, message: 'getAppFile failed', app, path });
187
+ if (staleIfError && this.memoryCache) {
188
+ return appsStaleIfError_1.getFallbackFile(app, path, this.memoryCache, this);
189
+ }
190
+ throw error;
191
+ }
192
+ };
193
+ this.getAppJSON = (app, path, nullIfNotFound) => {
194
+ const locator = utils_1.parseAppId(app);
195
+ const linked = !!locator.build;
196
+ const inflightKey = HttpClient_1.inflightURL;
197
+ return this.http.get(this.routes.File(locator, path), {
198
+ cacheable: linked ? HttpClient_1.CacheType.Memory : HttpClient_1.CacheType.Any,
199
+ inflightKey,
200
+ metric: linked ? 'apps-get-json' : 'registry-get-json',
201
+ nullIfNotFound,
202
+ });
203
+ };
204
+ this.getLinkedAppByWorkspaceJSON = (app, path, nullIfNotFound) => {
205
+ const inflightKey = HttpClient_1.inflightURL;
206
+ return this.http.get(this.routes.LinkedAppFile(app, path), {
207
+ cacheable: HttpClient_1.CacheType.Memory,
208
+ inflightKey,
209
+ metric: 'apps-linked-app-get-json',
210
+ nullIfNotFound,
211
+ });
212
+ };
213
+ this.getAppFileStream = (app, path) => {
214
+ const locator = utils_1.parseAppId(app);
215
+ const metric = locator.build ? 'apps-get-file-s' : 'registry-get-file-s';
216
+ return this.http.getStream(this.routes.File(locator, path), { metric });
217
+ };
218
+ this.getApp = (app) => {
219
+ const metric = 'apps-get-app';
220
+ const inflightKey = HttpClient_1.inflightURL;
221
+ return this.http.get(this.routes.App(app), { metric, inflightKey });
222
+ };
223
+ this.getAppSettings = (app) => {
224
+ const inflightKey = HttpClient_1.inflightURL;
225
+ const metric = 'apps-get-settings';
226
+ return this.http.get(this.routes.Settings(app), { inflightKey, metric });
227
+ };
228
+ this.getAllAppsSettings = (listAppsOptions = {}) => {
229
+ return this.listApps(listAppsOptions).then(({ data: installedApps }) => {
230
+ const names = installedApps.map(getVendorAndName);
231
+ const settingsPromises = names.map(vendorAndName => this.getAppSettings(vendorAndName).catch(notFound));
232
+ return Promise.all(settingsPromises).then((settings) => {
233
+ return zipObj(names, settings);
234
+ });
235
+ });
236
+ };
237
+ this.getAppBundle = (app, bundlePath, generatePackageJson) => {
238
+ const locator = utils_1.parseAppId(app);
239
+ const params = generatePackageJson && { _packageJSONEngine: 'npm', _packageJSONFilter: 'vtex.render-builder@x' };
240
+ const metric = locator.build ? 'apps-get-bundle' : 'registry-get-bundle';
241
+ return this.http.getStream(this.routes.AppBundle(locator, bundlePath), {
242
+ headers: {
243
+ Accept: 'application/x-gzip',
244
+ 'Accept-Encoding': 'gzip',
245
+ },
246
+ metric,
247
+ params,
248
+ });
249
+ };
250
+ this.unpackAppBundle = (app, bundlePath, unpackPath, generatePackageJson) => {
251
+ return this.getAppBundle(app, bundlePath, generatePackageJson)
252
+ .then(stream => stream
253
+ .pipe(zlib_1.createGunzip())
254
+ .pipe(tar_fs_1.extract(unpackPath)));
255
+ };
256
+ this.getAppsMetaInfos = async (filter, staleWhileRevalidate = true) => {
257
+ const { account, production } = this.context;
258
+ const metric = 'get-apps-meta';
259
+ const inflightKey = HttpClient_1.inflightURL;
260
+ const key = appsStaleIfError_1.getMetaInfoKey(account);
261
+ const cachedResponse = this.diskCache && await this.diskCache.get(key);
262
+ if (cachedResponse && this.context.recorder) {
263
+ this.context.recorder(cachedResponse.headers);
264
+ }
265
+ const metaInfoPromise = this.http.getRaw(this.routes.Meta(), { params: { fields: workspaceFields }, metric, inflightKey })
266
+ .then((response) => {
267
+ const { data, headers: responseHeaders } = response;
268
+ if (this.diskCache) {
269
+ this.diskCache.set(key, {
270
+ appsMetaInfo: data.apps || [],
271
+ headers: responseHeaders,
272
+ });
273
+ }
274
+ return response;
275
+ });
276
+ const useCachedResponse = cachedResponse && production && staleWhileRevalidate;
277
+ const appsMetaInfo = useCachedResponse
278
+ ? cachedResponse.appsMetaInfo
279
+ : await metaInfoPromise.then(response => response.data.apps);
280
+ if (filter) {
281
+ return appsMetaInfo.filter(appMeta => !!ramda_1.path(['_resolvedDependencies', filter], appMeta), appsMetaInfo);
282
+ }
283
+ return appsMetaInfo;
284
+ };
285
+ this.getDependencies = (filter = '') => {
286
+ const params = { filter };
287
+ const metric = 'apps-get-deps';
288
+ const inflightKey = HttpClient_1.inflightUrlWithQuery;
289
+ return this.http.get(this.routes.Dependencies(), { params, metric, inflightKey });
290
+ };
291
+ this.updateDependencies = () => {
292
+ return this.http.put(this.routes.Dependencies(), null, { metric: 'apps-update-deps' });
293
+ };
294
+ this.updateDependency = (name, version, registry) => {
295
+ return this.http.patch(this.routes.Apps(), [{ name, version, registry }], { metric: 'apps-update-dep' });
296
+ };
297
+ this.resolveDependencies = (apps, registries, filter = '') => {
298
+ const params = { apps, registries, filter };
299
+ const metric = 'apps-resolve-deps';
300
+ const inflightKey = HttpClient_1.inflightUrlWithQuery;
301
+ return this.http.get(this.routes.ResolveDependencies(), { params, metric, inflightKey });
302
+ };
303
+ this.resolveDependenciesWithManifest = (manifest, filter = '') => {
304
+ const params = { filter };
305
+ const metric = 'apps-resolve-deps-m';
306
+ return this.http.post(this.routes.ResolveDependenciesWithManifest(), manifest, { params, metric });
307
+ };
308
+ this.installRuntime = (descriptor) => {
309
+ const { account, workspace } = this.context;
310
+ const [name, version] = descriptor.split('@');
311
+ return this.http.patch(`http://apps.aws-us-east-1.vtex.io/${account}/${workspace}/apps`, [
312
+ {
313
+ name,
314
+ version,
315
+ },
316
+ ]);
317
+ };
318
+ this.diskCache = options && options.diskCache;
319
+ this.memoryCache = options && options.memoryCache;
320
+ this._routes = createRoutes(context);
321
+ }
322
+ get routes() {
323
+ return this._routes;
324
+ }
325
+ }
326
+ exports.Apps = Apps;
@@ -0,0 +1,21 @@
1
+ /// <reference types="node" />
2
+ import { Readable } from 'stream';
3
+ import { AppMetaInfo } from '..';
4
+ import { InfraClient, InstanceOptions } from '../HttpClient';
5
+ import { IOContext } from '../service/typings';
6
+ export interface AssetsParams {
7
+ files?: string[];
8
+ pick?: string[];
9
+ }
10
+ export declare class Assets extends InfraClient {
11
+ private routes;
12
+ constructor(context: IOContext, options?: InstanceOptions);
13
+ getSettings(dependencies: AppMetaInfo[], appAtMajor: string, params?: AssetsParams): Promise<Record<string, any>[]>;
14
+ getBuildJSONForApp(app: AppMetaInfo, appVendorName: string, pick?: string | string[]): Promise<Record<string, any>>;
15
+ getSettingsFromFilesForApp(app: AppMetaInfo, files?: string | string[]): Promise<Record<string, any>>;
16
+ getFile<T extends object | null>(appId: string, file: string, nullIfNotFound?: boolean): Promise<T>;
17
+ getFilteredDependencies(apps: string | string[], dependencies: AppMetaInfo[]): AppMetaInfo[];
18
+ getAppBundleByVendor: (app: string, bundlePath: string, generatePackageJson: boolean) => Promise<Readable>;
19
+ protected getAppFileByAccount: <T extends object | null>(app: string, path: string, nullIfNotFound?: boolean | undefined) => Promise<T>;
20
+ protected getAppFileByVendor: <T extends object | null>(app: string, path: string, nullIfNotFound?: boolean | undefined) => Promise<T>;
21
+ }
@@ -1,18 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ramda_1 = require("ramda");
4
- const HttpClient_1 = require("../../HttpClient");
5
- const utils_1 = require("../../utils");
6
- const InfraClient_1 = require("./InfraClient");
4
+ const HttpClient_1 = require("../HttpClient");
5
+ const utils_1 = require("../utils");
7
6
  const dependsOnApp = (appsAtMajor) => (a) => {
8
7
  let dependsOn = false;
9
8
  appsAtMajor.forEach(appAtMajor => {
10
9
  const [name, major] = appAtMajor.split('@');
11
- const sanitizedMajor = major.includes('.') ? major.split('.')[0] : major;
12
10
  const version = a._resolvedDependencies[name];
13
11
  if (version) {
14
12
  const [depMajor] = version.split('.');
15
- if (sanitizedMajor === depMajor) {
13
+ if (major === depMajor) {
16
14
  dependsOn = true;
17
15
  }
18
16
  }
@@ -30,10 +28,10 @@ const createRoutes = (workspace) => ({
30
28
  Bundle: (scope, locator, path) => `/${scope}/${appOrRegistry(workspace, locator)}/bundle/${path}`,
31
29
  Files: (scope, locator, path) => `/${scope}/${appOrRegistry(workspace, locator)}/files/${path}`,
32
30
  });
33
- class Assets extends InfraClient_1.InfraClient {
31
+ class Assets extends HttpClient_1.InfraClient {
34
32
  constructor(context, options) {
35
33
  super('apps@0.x', context, options, true);
36
- this.getAppBundleByVendor = (app, bundlePath, generatePackageJson, tracingConfig) => {
34
+ this.getAppBundleByVendor = (app, bundlePath, generatePackageJson) => {
37
35
  const locator = utils_1.parseAppId(app);
38
36
  const params = generatePackageJson && { _packageJSONEngine: 'npm', _packageJSONFilter: 'vtex.render-builder@x' };
39
37
  const metric = locator.build ? 'apps-get-bundle' : 'registry-get-bundle';
@@ -44,117 +42,64 @@ class Assets extends InfraClient_1.InfraClient {
44
42
  },
45
43
  metric,
46
44
  params,
47
- tracing: {
48
- requestSpanNameSuffix: metric,
49
- ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
50
- },
51
45
  });
52
46
  };
53
- this.getAppJSONByAccount = (app, path, nullIfNotFound, tracingConfig) => {
47
+ this.getAppFileByAccount = (app, path, nullIfNotFound) => {
54
48
  const locator = utils_1.parseAppId(app);
55
49
  const inflightKey = HttpClient_1.inflightURL;
56
- const metric = 'assets-get-json-by-account';
57
50
  return this.http.get(this.routes.Files(this.context.account, locator, path), {
58
51
  cacheable: HttpClient_1.CacheType.Memory,
59
52
  inflightKey,
60
- metric,
53
+ metric: 'assets-get-json-by-account',
61
54
  nullIfNotFound,
62
- tracing: {
63
- requestSpanNameSuffix: metric,
64
- ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
65
- },
66
55
  });
67
56
  };
68
- this.getAppJSONByVendor = (app, path, nullIfNotFound, tracingConfig) => {
57
+ this.getAppFileByVendor = (app, path, nullIfNotFound) => {
69
58
  const locator = utils_1.parseAppId(app);
70
59
  const vendor = locator.name.split('.')[0];
71
60
  const inflightKey = HttpClient_1.inflightURL;
72
- const metric = 'assets-get-json-by-vendor';
73
61
  return this.http.get(this.routes.Files(vendor, locator, path), {
74
62
  cacheable: HttpClient_1.CacheType.Any,
75
63
  inflightKey,
76
- metric,
64
+ metric: 'assets-get-json-by-vendor',
77
65
  nullIfNotFound,
78
- tracing: {
79
- requestSpanNameSuffix: metric,
80
- ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
81
- },
82
- });
83
- };
84
- this.getAppFileByAccount = (app, path, nullIfNotFound, tracingConfig) => {
85
- const locator = utils_1.parseAppId(app);
86
- const inflightKey = HttpClient_1.inflightURL;
87
- const metric = 'assets-get-file-by-account';
88
- return this.http.getBuffer(this.routes.Files(this.context.account, locator, path), {
89
- cacheable: HttpClient_1.CacheType.Any,
90
- inflightKey,
91
- metric,
92
- nullIfNotFound,
93
- tracing: {
94
- requestSpanNameSuffix: metric,
95
- ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
96
- },
97
- });
98
- };
99
- this.getAppFileByVendor = (app, path, nullIfNotFound, tracingConfig) => {
100
- const locator = utils_1.parseAppId(app);
101
- const vendor = locator.name.split('.')[0];
102
- const inflightKey = HttpClient_1.inflightURL;
103
- const metric = 'assets-get-file-by-vendor';
104
- return this.http.getBuffer(this.routes.Files(vendor, locator, path), {
105
- cacheable: HttpClient_1.CacheType.Any,
106
- inflightKey,
107
- metric,
108
- nullIfNotFound,
109
- tracing: {
110
- requestSpanNameSuffix: metric,
111
- ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
112
- },
113
66
  });
114
67
  };
115
68
  this.routes = createRoutes(this.context.workspace);
116
69
  }
117
- getSettings(dependencies, appAtMajor, params = {}, tracingConfig) {
70
+ getSettings(dependencies, appAtMajor, params = {}) {
118
71
  const { pick, files } = params;
119
72
  const filtered = this.getFilteredDependencies(appAtMajor, dependencies);
120
73
  return Promise.all(filtered.map(dependency => {
121
74
  const [appVendorName] = appAtMajor.split('@');
122
75
  const buildJson = useBuildJson(dependency, appVendorName);
123
76
  return buildJson
124
- ? this.getBuildJSONForApp(dependency, appVendorName, pick, tracingConfig)
125
- : this.getSettingsFromFilesForApp(dependency, files, tracingConfig);
77
+ ? this.getBuildJSONForApp(dependency, appVendorName, pick)
78
+ : this.getSettingsFromFilesForApp(dependency, files);
126
79
  }));
127
80
  }
128
- async getBuildJSONForApp(app, appVendorName, pick = [], tracingConfig) {
81
+ async getBuildJSONForApp(app, appVendorName, pick = []) {
129
82
  const pickArray = Array.isArray(pick) ? pick : [pick];
130
- const buildJson = await this.getJSON(app.id, `dist/${appVendorName}/build.json`, undefined, tracingConfig);
83
+ const buildJson = await this.getFile(app.id, `dist/${appVendorName}/build.json`);
131
84
  const result = !ramda_1.isEmpty(pickArray) ? ramda_1.pick(pickArray, buildJson) : buildJson;
132
85
  result.declarer = app.id;
133
86
  return result;
134
87
  }
135
- async getSettingsFromFilesForApp(app, files = [], tracingConfig) {
88
+ async getSettingsFromFilesForApp(app, files = []) {
136
89
  // If there's no support for build.json, then fetch individual files and zip them into an {[file]: content} object.
137
90
  const filesArray = Array.isArray(files) ? files : [files];
138
- const fetched = await Promise.all(filesArray.map(file => this.getJSON(app.id, file, true, tracingConfig)));
91
+ const fetched = await Promise.all(filesArray.map(file => this.getFile(app.id, file, true)));
139
92
  const result = ramda_1.zipObj(filesArray, fetched);
140
93
  result.declarer = app.id;
141
94
  return result;
142
95
  }
143
- async getJSON(appId, file, nullIfNotFound, tracingConfig) {
144
- const locator = utils_1.parseAppId(appId);
145
- const linked = !!locator.build;
146
- if (linked) {
147
- return this.getAppJSONByAccount(appId, file, nullIfNotFound, tracingConfig);
148
- }
149
- return this.getAppJSONByVendor(appId, file, nullIfNotFound, tracingConfig);
150
- }
151
- async getFile(appId, file, nullIfNotFound, tracingConfig) {
96
+ async getFile(appId, file, nullIfNotFound) {
152
97
  const locator = utils_1.parseAppId(appId);
153
98
  const linked = !!locator.build;
154
99
  if (linked) {
155
- return this.getAppFileByAccount(appId, file, nullIfNotFound, tracingConfig);
100
+ return this.getAppFileByAccount(appId, file, nullIfNotFound);
156
101
  }
157
- return this.getAppFileByVendor(appId, file, nullIfNotFound, tracingConfig);
102
+ return this.getAppFileByVendor(appId, file, nullIfNotFound);
158
103
  }
159
104
  getFilteredDependencies(apps, dependencies) {
160
105
  const appsAtMajor = typeof (apps) === 'string' ? [apps] : apps;