@vtex/api 6.48.1-beta → 6.48.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (440) hide show
  1. package/gen/manifest.schema +5 -3
  2. package/lib/HttpClient/GraphQLClient.d.ts +3 -2
  3. package/lib/HttpClient/GraphQLClient.js +5 -1
  4. package/lib/HttpClient/HttpClient.d.ts +9 -7
  5. package/lib/HttpClient/HttpClient.js +70 -27
  6. package/lib/HttpClient/agents.d.ts +6 -0
  7. package/lib/HttpClient/agents.js +43 -0
  8. package/lib/HttpClient/index.d.ts +1 -7
  9. package/lib/HttpClient/index.js +22 -16
  10. package/lib/HttpClient/middlewares/cache.d.ts +9 -3
  11. package/lib/HttpClient/middlewares/cache.js +130 -35
  12. package/lib/HttpClient/middlewares/cancellationToken.d.ts +2 -2
  13. package/lib/HttpClient/middlewares/cancellationToken.js +5 -2
  14. package/lib/HttpClient/middlewares/inflight.d.ts +1 -1
  15. package/lib/HttpClient/middlewares/inflight.js +7 -3
  16. package/lib/HttpClient/middlewares/memoization.d.ts +1 -1
  17. package/lib/HttpClient/middlewares/memoization.js +13 -4
  18. package/lib/HttpClient/middlewares/metrics.js +25 -38
  19. package/lib/HttpClient/middlewares/notFound.d.ts +1 -1
  20. package/lib/HttpClient/middlewares/notFound.js +5 -2
  21. package/lib/HttpClient/middlewares/recorder.d.ts +1 -1
  22. package/lib/HttpClient/middlewares/recorder.js +21 -12
  23. package/lib/HttpClient/middlewares/request/HttpAgentSingleton.d.ts +11 -0
  24. package/lib/HttpClient/middlewares/request/HttpAgentSingleton.js +31 -0
  25. package/lib/HttpClient/middlewares/request/index.d.ts +18 -0
  26. package/lib/HttpClient/middlewares/request/index.js +88 -0
  27. package/lib/HttpClient/middlewares/request/setupAxios/index.d.ts +1 -0
  28. package/lib/HttpClient/middlewares/request/setupAxios/index.js +22 -0
  29. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.d.ts +2 -0
  30. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.js +55 -0
  31. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.d.ts +2 -0
  32. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.js +8 -0
  33. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.d.ts +8 -0
  34. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +56 -0
  35. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.d.ts +4 -0
  36. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +32 -0
  37. package/lib/HttpClient/middlewares/tracing.d.ts +15 -0
  38. package/lib/HttpClient/middlewares/tracing.js +62 -0
  39. package/lib/HttpClient/typings.d.ts +46 -12
  40. package/lib/HttpClient/typings.js +1 -0
  41. package/lib/caches/DiskCache.d.ts +1 -1
  42. package/lib/caches/DiskCache.js +3 -2
  43. package/lib/caches/LRUCache.d.ts +3 -3
  44. package/lib/caches/LRUCache.js +6 -1
  45. package/lib/caches/LRUDiskCache.d.ts +2 -2
  46. package/lib/caches/LRUDiskCache.js +8 -3
  47. package/lib/caches/MultilayeredCache.d.ts +2 -2
  48. package/lib/caches/MultilayeredCache.js +8 -7
  49. package/lib/caches/index.js +20 -7
  50. package/lib/caches/typings.d.ts +5 -5
  51. package/lib/clients/IOClient.d.ts +13 -0
  52. package/lib/clients/IOClient.js +20 -0
  53. package/lib/clients/IOClients.d.ts +29 -25
  54. package/lib/clients/IOClients.js +36 -28
  55. package/lib/{HttpClient → clients}/IOGraphQLClient.d.ts +4 -4
  56. package/lib/{HttpClient → clients}/IOGraphQLClient.js +3 -2
  57. package/lib/{HttpClient → clients/apps}/AppClient.d.ts +3 -3
  58. package/lib/{HttpClient → clients/apps}/AppClient.js +11 -5
  59. package/lib/{HttpClient → clients/apps}/AppGraphQLClient.d.ts +3 -3
  60. package/lib/{HttpClient → clients/apps}/AppGraphQLClient.js +11 -5
  61. package/lib/clients/apps/Billing.d.ts +12 -0
  62. package/lib/clients/{Billing.js → apps/Billing.js} +9 -3
  63. package/lib/clients/{Builder.d.ts → apps/Builder.d.ts} +12 -11
  64. package/lib/clients/{Builder.js → apps/Builder.js} +51 -23
  65. package/lib/clients/apps/MessagesGraphQL.d.ts +61 -0
  66. package/lib/clients/apps/MessagesGraphQL.js +122 -0
  67. package/lib/clients/{Settings.d.ts → apps/Settings.d.ts} +5 -4
  68. package/lib/clients/apps/Settings.js +39 -0
  69. package/lib/clients/apps/catalogGraphQL/brand.d.ts +13 -0
  70. package/lib/clients/apps/catalogGraphQL/brand.js +19 -0
  71. package/lib/clients/apps/catalogGraphQL/category.d.ts +11 -0
  72. package/lib/clients/apps/catalogGraphQL/category.js +17 -0
  73. package/lib/clients/apps/catalogGraphQL/index.d.ts +22 -0
  74. package/lib/clients/apps/catalogGraphQL/index.js +89 -0
  75. package/lib/clients/apps/catalogGraphQL/product.d.ts +25 -0
  76. package/lib/clients/apps/catalogGraphQL/product.js +31 -0
  77. package/lib/clients/apps/catalogGraphQL/sku.d.ts +26 -0
  78. package/lib/clients/apps/catalogGraphQL/sku.js +31 -0
  79. package/lib/clients/apps/index.d.ts +7 -0
  80. package/lib/clients/apps/index.js +23 -0
  81. package/lib/{HttpClient → clients/external}/ExternalClient.d.ts +3 -3
  82. package/lib/{HttpClient → clients/external}/ExternalClient.js +10 -2
  83. package/lib/clients/external/ID.d.ts +23 -0
  84. package/lib/clients/external/ID.js +61 -0
  85. package/lib/clients/external/Masterdata.d.ts +94 -0
  86. package/lib/clients/external/Masterdata.js +225 -0
  87. package/lib/clients/external/PaymentProvider.d.ts +31 -0
  88. package/lib/clients/external/PaymentProvider.js +43 -0
  89. package/lib/clients/external/index.d.ts +4 -0
  90. package/lib/clients/external/index.js +20 -0
  91. package/lib/clients/index.d.ts +9 -21
  92. package/lib/clients/index.js +27 -24
  93. package/lib/clients/infra/Apps.d.ts +93 -0
  94. package/lib/clients/infra/Apps.js +511 -0
  95. package/lib/clients/infra/Assets.d.ts +35 -0
  96. package/lib/clients/infra/Assets.js +166 -0
  97. package/lib/clients/infra/BillingMetrics.d.ts +13 -0
  98. package/lib/clients/infra/BillingMetrics.js +16 -0
  99. package/lib/clients/infra/Events.d.ts +12 -0
  100. package/lib/clients/infra/Events.js +34 -0
  101. package/lib/clients/infra/Housekeeper.d.ts +10 -0
  102. package/lib/clients/infra/Housekeeper.js +31 -0
  103. package/lib/{HttpClient → clients/infra}/InfraClient.d.ts +3 -3
  104. package/lib/{HttpClient → clients/infra}/InfraClient.js +10 -4
  105. package/lib/clients/infra/Registry.d.ts +65 -0
  106. package/lib/clients/infra/Registry.js +209 -0
  107. package/lib/clients/infra/Router.d.ts +34 -0
  108. package/lib/clients/infra/Router.js +82 -0
  109. package/lib/clients/infra/Sphinx.d.ts +13 -0
  110. package/lib/clients/infra/Sphinx.js +30 -0
  111. package/lib/clients/infra/VBase.d.ts +61 -0
  112. package/lib/clients/infra/VBase.js +197 -0
  113. package/lib/clients/infra/Workspaces.d.ts +18 -0
  114. package/lib/clients/infra/Workspaces.js +66 -0
  115. package/lib/clients/infra/index.d.ts +11 -0
  116. package/lib/clients/infra/index.js +27 -0
  117. package/lib/{HttpClient → clients/janus}/JanusClient.d.ts +4 -4
  118. package/lib/{HttpClient → clients/janus}/JanusClient.js +8 -3
  119. package/lib/clients/janus/LicenseManager.d.ts +7 -0
  120. package/lib/clients/janus/LicenseManager.js +59 -0
  121. package/lib/clients/{Segment.d.ts → janus/Segment.d.ts} +7 -11
  122. package/lib/clients/janus/Segment.js +89 -0
  123. package/lib/clients/{Session.d.ts → janus/Session.d.ts} +4 -4
  124. package/lib/clients/{Session.js → janus/Session.js} +25 -13
  125. package/lib/clients/{Tenant.d.ts → janus/Tenant.d.ts} +7 -8
  126. package/lib/clients/janus/Tenant.js +29 -0
  127. package/lib/clients/janus/index.d.ts +5 -0
  128. package/lib/clients/janus/index.js +21 -0
  129. package/lib/constants.d.ts +50 -2
  130. package/lib/constants.js +55 -1
  131. package/lib/errors/AuthenticationError.js +1 -0
  132. package/lib/errors/ForbiddenError.js +1 -0
  133. package/lib/errors/NotFoundError.js +1 -0
  134. package/lib/errors/RequestCancelledError.js +1 -0
  135. package/lib/errors/ResolverError.d.ts +1 -1
  136. package/lib/errors/ResolverError.js +4 -3
  137. package/lib/errors/ResolverWarning.d.ts +1 -1
  138. package/lib/errors/ResolverWarning.js +3 -2
  139. package/lib/errors/TooManyRequestsError.js +1 -0
  140. package/lib/errors/UserInputError.js +1 -0
  141. package/lib/errors/index.js +22 -11
  142. package/lib/index.d.ts +9 -7
  143. package/lib/index.js +31 -16
  144. package/lib/metrics/MetricsAccumulator.d.ts +3 -20
  145. package/lib/metrics/MetricsAccumulator.js +44 -27
  146. package/lib/responses.d.ts +5 -46
  147. package/lib/service/index.d.ts +2 -0
  148. package/lib/service/index.js +35 -0
  149. package/lib/service/loaders.d.ts +8 -0
  150. package/lib/service/loaders.js +57 -0
  151. package/lib/service/logger/console.d.ts +10 -0
  152. package/lib/service/logger/console.js +40 -0
  153. package/lib/service/logger/index.d.ts +2 -28
  154. package/lib/service/logger/index.js +16 -68
  155. package/lib/service/logger/logger.d.ts +29 -0
  156. package/lib/service/logger/logger.js +62 -0
  157. package/lib/service/logger/metricsLogger.d.ts +40 -0
  158. package/lib/service/logger/metricsLogger.js +150 -0
  159. package/lib/service/master.d.ts +2 -0
  160. package/lib/service/master.js +89 -0
  161. package/lib/service/metrics/requestMetricsMiddleware.d.ts +2 -0
  162. package/lib/service/metrics/requestMetricsMiddleware.js +46 -0
  163. package/lib/service/tracing/TracerSingleton.d.ts +7 -0
  164. package/lib/service/tracing/TracerSingleton.js +49 -0
  165. package/lib/service/tracing/metrics/MetricNames.d.ts +60 -0
  166. package/lib/service/tracing/metrics/MetricNames.js +45 -0
  167. package/lib/service/tracing/metrics/instruments.d.ts +9 -0
  168. package/lib/service/tracing/metrics/instruments.js +19 -0
  169. package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.d.ts +9 -0
  170. package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.js +26 -0
  171. package/lib/service/tracing/tracingMiddlewares.d.ts +5 -0
  172. package/lib/service/tracing/tracingMiddlewares.js +117 -0
  173. package/lib/service/worker/index.d.ts +11 -0
  174. package/lib/service/worker/index.js +197 -0
  175. package/lib/service/worker/listeners.d.ts +3 -0
  176. package/lib/{utils/unhandled.js → service/worker/listeners.js} +12 -16
  177. package/lib/service/{Service.d.ts → worker/runtime/Service.d.ts} +5 -5
  178. package/lib/service/{Service.js → worker/runtime/Service.js} +3 -1
  179. package/lib/service/worker/runtime/builtIn/handlers.d.ts +4 -0
  180. package/lib/service/worker/runtime/builtIn/handlers.js +34 -0
  181. package/lib/service/worker/runtime/builtIn/middlewares.d.ts +4 -0
  182. package/lib/service/worker/runtime/builtIn/middlewares.js +43 -0
  183. package/lib/service/worker/runtime/events/index.d.ts +4 -0
  184. package/lib/service/worker/runtime/events/index.js +48 -0
  185. package/lib/service/worker/runtime/events/middlewares/body.d.ts +3 -0
  186. package/lib/service/worker/runtime/events/middlewares/body.js +26 -0
  187. package/lib/service/worker/runtime/events/middlewares/context.d.ts +3 -0
  188. package/lib/service/worker/runtime/events/middlewares/context.js +23 -0
  189. package/lib/service/worker/runtime/events/router.d.ts +2 -0
  190. package/lib/service/worker/runtime/events/router.js +29 -0
  191. package/lib/service/worker/runtime/graphql/index.d.ts +6 -0
  192. package/lib/service/worker/runtime/graphql/index.js +29 -0
  193. package/lib/service/worker/runtime/graphql/middlewares/context.d.ts +2 -0
  194. package/lib/service/worker/runtime/graphql/middlewares/context.js +17 -0
  195. package/lib/service/worker/runtime/graphql/middlewares/error.js +97 -0
  196. package/lib/service/worker/runtime/graphql/middlewares/query.d.ts +3 -0
  197. package/lib/service/worker/runtime/graphql/middlewares/query.js +54 -0
  198. package/lib/service/worker/runtime/graphql/middlewares/response.js +39 -0
  199. package/lib/service/worker/runtime/graphql/middlewares/run.d.ts +2 -0
  200. package/lib/service/worker/runtime/graphql/middlewares/run.js +21 -0
  201. package/lib/service/worker/runtime/graphql/middlewares/updateSchema.d.ts +5 -0
  202. package/lib/service/worker/runtime/graphql/middlewares/updateSchema.js +30 -0
  203. package/lib/service/worker/runtime/graphql/middlewares/upload.d.ts +4 -0
  204. package/lib/service/{graphql → worker/runtime/graphql}/middlewares/upload.js +2 -1
  205. package/lib/service/worker/runtime/graphql/schema/index.d.ts +7 -0
  206. package/lib/service/worker/runtime/graphql/schema/index.js +33 -0
  207. package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.d.ts +6 -0
  208. package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.js +81 -0
  209. package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/Auth.d.ts +1 -0
  210. package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/Auth.js +17 -10
  211. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.d.ts +7 -0
  212. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.js +38 -0
  213. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.d.ts +11 -0
  214. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.js +62 -0
  215. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.d.ts +7 -0
  216. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.js +41 -0
  217. package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/Sanitize.d.ts +1 -0
  218. package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/Sanitize.js +7 -0
  219. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.d.ts +6 -0
  220. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.js +35 -0
  221. package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/SmartCacheDirective.d.ts +1 -0
  222. package/lib/service/{graphql → worker/runtime/graphql}/schema/schemaDirectives/SmartCacheDirective.js +9 -3
  223. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.d.ts +7 -0
  224. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.js +40 -0
  225. package/lib/service/{graphql/schema/schemaDirectives/Translatable.d.ts → worker/runtime/graphql/schema/schemaDirectives/TranslateTo.d.ts} +2 -1
  226. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.js +34 -0
  227. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.d.ts +22 -0
  228. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.js +37 -0
  229. package/lib/service/worker/runtime/graphql/schema/typeDefs/index.d.ts +8 -0
  230. package/lib/service/worker/runtime/graphql/schema/typeDefs/index.js +14 -0
  231. package/lib/service/{graphql → worker/runtime/graphql}/schema/typeDefs/ioUpload.js +1 -0
  232. package/lib/service/{graphql → worker/runtime/graphql}/schema/typeDefs/sanitizedString.js +8 -3
  233. package/lib/service/worker/runtime/graphql/typings.d.ts +31 -0
  234. package/lib/service/worker/runtime/graphql/utils/cacheControl.d.ts +2 -0
  235. package/lib/service/worker/runtime/graphql/utils/cacheControl.js +34 -0
  236. package/lib/service/worker/runtime/graphql/utils/error.d.ts +2 -0
  237. package/lib/service/worker/runtime/graphql/utils/error.js +78 -0
  238. package/lib/service/worker/runtime/graphql/utils/pathname.js +9 -0
  239. package/lib/service/worker/runtime/graphql/utils/translations.d.ts +14 -0
  240. package/lib/service/worker/runtime/graphql/utils/translations.js +42 -0
  241. package/lib/service/worker/runtime/http/index.d.ts +5 -0
  242. package/lib/service/worker/runtime/http/index.js +61 -0
  243. package/lib/service/worker/runtime/http/middlewares/authTokens.d.ts +3 -0
  244. package/lib/service/{http → worker/runtime/http}/middlewares/authTokens.js +1 -0
  245. package/lib/service/worker/runtime/http/middlewares/cancellationToken.d.ts +3 -0
  246. package/lib/service/{http → worker/runtime/http}/middlewares/cancellationToken.js +3 -1
  247. package/lib/service/worker/runtime/http/middlewares/clients.d.ts +4 -0
  248. package/lib/service/{http → worker/runtime/http}/middlewares/clients.js +1 -0
  249. package/lib/service/worker/runtime/http/middlewares/context.d.ts +4 -0
  250. package/lib/service/worker/runtime/http/middlewares/context.js +39 -0
  251. package/lib/service/worker/runtime/http/middlewares/error.d.ts +2 -0
  252. package/lib/service/{http → worker/runtime/http}/middlewares/error.js +29 -16
  253. package/lib/service/worker/runtime/http/middlewares/rateLimit.d.ts +6 -0
  254. package/lib/service/worker/runtime/http/middlewares/rateLimit.js +43 -0
  255. package/lib/service/{http → worker/runtime/http}/middlewares/requestStats.d.ts +3 -3
  256. package/lib/service/{http → worker/runtime/http}/middlewares/requestStats.js +1 -0
  257. package/lib/service/worker/runtime/http/middlewares/setCookie.d.ts +3 -0
  258. package/lib/service/{http → worker/runtime/http}/middlewares/setCookie.js +6 -5
  259. package/lib/service/worker/runtime/http/middlewares/settings.d.ts +9 -0
  260. package/lib/service/worker/runtime/http/middlewares/settings.js +49 -0
  261. package/lib/service/worker/runtime/http/middlewares/timings.d.ts +3 -0
  262. package/lib/service/{http → worker/runtime/http}/middlewares/timings.js +25 -11
  263. package/lib/service/worker/runtime/http/middlewares/vary.d.ts +3 -0
  264. package/lib/service/{http → worker/runtime/http}/middlewares/vary.js +4 -3
  265. package/lib/service/worker/runtime/http/router.d.ts +2 -0
  266. package/lib/service/worker/runtime/http/router.js +25 -0
  267. package/lib/service/worker/runtime/http/routes.d.ts +19 -0
  268. package/lib/service/worker/runtime/http/routes.js +16 -0
  269. package/lib/service/worker/runtime/method.d.ts +9 -0
  270. package/lib/service/{method.js → worker/runtime/method.js} +2 -1
  271. package/lib/service/worker/runtime/statusTrack.d.ts +14 -0
  272. package/lib/service/worker/runtime/statusTrack.js +43 -0
  273. package/lib/service/worker/runtime/typings.d.ts +173 -0
  274. package/lib/service/worker/runtime/utils/compose.d.ts +5 -0
  275. package/lib/service/worker/runtime/utils/compose.js +14 -0
  276. package/lib/service/worker/runtime/utils/context.d.ts +5 -0
  277. package/lib/service/worker/runtime/utils/context.js +42 -0
  278. package/lib/service/worker/runtime/utils/diff.d.ts +12 -0
  279. package/lib/service/worker/runtime/utils/diff.js +22 -0
  280. package/lib/service/worker/runtime/utils/recorder.d.ts +8 -0
  281. package/lib/service/worker/runtime/utils/recorder.js +38 -0
  282. package/lib/service/worker/runtime/utils/toArray.js +5 -0
  283. package/lib/service/worker/runtime/utils/tokenBucket.d.ts +2 -0
  284. package/lib/service/worker/runtime/utils/tokenBucket.js +17 -0
  285. package/lib/tracing/LogEvents.d.ts +31 -0
  286. package/lib/{service/graphql/utils/array.js → tracing/LogEvents.js} +1 -1
  287. package/lib/tracing/LogFields.d.ts +66 -0
  288. package/lib/tracing/LogFields.js +3 -0
  289. package/lib/tracing/Tags.d.ts +81 -0
  290. package/lib/tracing/Tags.js +8 -0
  291. package/lib/tracing/UserLandTracer.d.ts +27 -0
  292. package/lib/tracing/UserLandTracer.js +58 -0
  293. package/lib/tracing/errorReporting/ErrorReport.d.ts +31 -0
  294. package/lib/tracing/errorReporting/ErrorReport.js +71 -0
  295. package/lib/tracing/index.d.ts +9 -0
  296. package/lib/tracing/index.js +20 -0
  297. package/lib/tracing/spanReference/SpanReferenceTypes.d.ts +4 -0
  298. package/lib/tracing/spanReference/SpanReferenceTypes.js +8 -0
  299. package/lib/tracing/spanReference/createSpanReference.d.ts +3 -0
  300. package/lib/tracing/spanReference/createSpanReference.js +9 -0
  301. package/lib/tracing/utils.d.ts +13 -0
  302. package/lib/tracing/utils.js +42 -0
  303. package/lib/utils/MineWinsConflictsResolver.d.ts +7 -5
  304. package/lib/utils/MineWinsConflictsResolver.js +40 -22
  305. package/lib/utils/app.d.ts +3 -1
  306. package/lib/utils/app.js +40 -21
  307. package/lib/utils/appsStaleIfError.d.ts +2 -1
  308. package/lib/utils/appsStaleIfError.js +33 -12
  309. package/lib/utils/billingOptions.d.ts +36 -3
  310. package/lib/utils/billingOptions.js +9 -3
  311. package/lib/utils/binding.d.ts +3 -3
  312. package/lib/utils/binding.js +5 -2
  313. package/lib/utils/cancel.d.ts +2 -2
  314. package/lib/utils/cancel.js +3 -1
  315. package/lib/utils/conflicts.mock.d.ts +17 -0
  316. package/lib/utils/conflicts.mock.js +28 -0
  317. package/lib/utils/domain.js +2 -1
  318. package/lib/utils/error.js +6 -4
  319. package/lib/utils/index.js +23 -12
  320. package/lib/utils/json.js +1 -0
  321. package/lib/utils/log.d.ts +1 -3
  322. package/lib/utils/log.js +6 -4
  323. package/lib/utils/message.js +11 -4
  324. package/lib/utils/renameBy.js +3 -1
  325. package/lib/utils/retry.js +10 -7
  326. package/lib/utils/status.js +3 -1
  327. package/lib/utils/tenant.d.ts +3 -3
  328. package/lib/utils/tenant.js +5 -2
  329. package/lib/utils/throwOnGraphQLErrors.js +1 -0
  330. package/lib/utils/time.d.ts +7 -7
  331. package/lib/utils/time.js +29 -12
  332. package/package.json +3 -3
  333. package/lib/HttpClient/IOClient.d.ts +0 -13
  334. package/lib/HttpClient/IOClient.js +0 -14
  335. package/lib/HttpClient/factories/index.d.ts +0 -8
  336. package/lib/HttpClient/factories/index.js +0 -31
  337. package/lib/HttpClient/middlewares/request.d.ts +0 -10
  338. package/lib/HttpClient/middlewares/request.js +0 -87
  339. package/lib/IODataSource.d.ts +0 -27
  340. package/lib/IODataSource.js +0 -46
  341. package/lib/clients/Apps.d.ts +0 -84
  342. package/lib/clients/Apps.js +0 -326
  343. package/lib/clients/Assets.d.ts +0 -21
  344. package/lib/clients/Assets.js +0 -110
  345. package/lib/clients/Billing.d.ts +0 -11
  346. package/lib/clients/BillingMetrics.d.ts +0 -12
  347. package/lib/clients/BillingMetrics.js +0 -10
  348. package/lib/clients/Events.d.ts +0 -6
  349. package/lib/clients/Events.js +0 -19
  350. package/lib/clients/Housekeeper.d.ts +0 -11
  351. package/lib/clients/Housekeeper.js +0 -24
  352. package/lib/clients/ID.d.ts +0 -22
  353. package/lib/clients/ID.js +0 -48
  354. package/lib/clients/LicenseManager.d.ts +0 -6
  355. package/lib/clients/LicenseManager.js +0 -43
  356. package/lib/clients/Logger.d.ts +0 -27
  357. package/lib/clients/Logger.js +0 -32
  358. package/lib/clients/Messages.d.ts +0 -18
  359. package/lib/clients/Messages.js +0 -20
  360. package/lib/clients/MessagesGraphQL.d.ts +0 -63
  361. package/lib/clients/MessagesGraphQL.js +0 -50
  362. package/lib/clients/Metadata.d.ts +0 -25
  363. package/lib/clients/Metadata.js +0 -53
  364. package/lib/clients/Registry.d.ts +0 -61
  365. package/lib/clients/Registry.js +0 -147
  366. package/lib/clients/Router.d.ts +0 -33
  367. package/lib/clients/Router.js +0 -50
  368. package/lib/clients/Segment.js +0 -69
  369. package/lib/clients/Settings.js +0 -44
  370. package/lib/clients/Sphinx.d.ts +0 -12
  371. package/lib/clients/Sphinx.js +0 -19
  372. package/lib/clients/Tenant.js +0 -13
  373. package/lib/clients/VBase.d.ts +0 -57
  374. package/lib/clients/VBase.js +0 -116
  375. package/lib/clients/Workspaces.d.ts +0 -17
  376. package/lib/clients/Workspaces.js +0 -38
  377. package/lib/service/Runtime.d.ts +0 -18
  378. package/lib/service/Runtime.js +0 -57
  379. package/lib/service/events/index.d.ts +0 -3
  380. package/lib/service/events/index.js +0 -21
  381. package/lib/service/graphql/index.d.ts +0 -7
  382. package/lib/service/graphql/index.js +0 -33
  383. package/lib/service/graphql/middlewares/error.js +0 -107
  384. package/lib/service/graphql/middlewares/formatters.d.ts +0 -2
  385. package/lib/service/graphql/middlewares/formatters.js +0 -64
  386. package/lib/service/graphql/middlewares/query.d.ts +0 -2
  387. package/lib/service/graphql/middlewares/query.js +0 -32
  388. package/lib/service/graphql/middlewares/response.js +0 -36
  389. package/lib/service/graphql/middlewares/run.d.ts +0 -4
  390. package/lib/service/graphql/middlewares/run.js +0 -55
  391. package/lib/service/graphql/middlewares/schema.d.ts +0 -2
  392. package/lib/service/graphql/middlewares/schema.js +0 -8
  393. package/lib/service/graphql/middlewares/timings.d.ts +0 -2
  394. package/lib/service/graphql/middlewares/timings.js +0 -10
  395. package/lib/service/graphql/middlewares/upload.d.ts +0 -7
  396. package/lib/service/graphql/schema/index.d.ts +0 -3
  397. package/lib/service/graphql/schema/index.js +0 -66
  398. package/lib/service/graphql/schema/messagesLoader.d.ts +0 -4
  399. package/lib/service/graphql/schema/messagesLoader.js +0 -41
  400. package/lib/service/graphql/schema/messagesLoaderV2.d.ts +0 -5
  401. package/lib/service/graphql/schema/messagesLoaderV2.js +0 -44
  402. package/lib/service/graphql/schema/schemaDirectives/Translatable.js +0 -54
  403. package/lib/service/graphql/schema/schemaDirectives/TranslatableV2.d.ts +0 -13
  404. package/lib/service/graphql/schema/schemaDirectives/TranslatableV2.js +0 -67
  405. package/lib/service/graphql/schema/schemaDirectives/index.d.ts +0 -13
  406. package/lib/service/graphql/schema/schemaDirectives/index.js +0 -17
  407. package/lib/service/graphql/schema/typeDefs/index.d.ts +0 -16
  408. package/lib/service/graphql/schema/typeDefs/index.js +0 -21
  409. package/lib/service/graphql/schema/typeDefs/ioMessage.d.ts +0 -8
  410. package/lib/service/graphql/schema/typeDefs/ioMessage.js +0 -33
  411. package/lib/service/graphql/typings.d.ts +0 -21
  412. package/lib/service/graphql/utils/cacheControl.d.ts +0 -6
  413. package/lib/service/graphql/utils/cacheControl.js +0 -38
  414. package/lib/service/graphql/utils/maxAgeEnum.d.ts +0 -6
  415. package/lib/service/graphql/utils/maxAgeEnum.js +0 -17
  416. package/lib/service/graphql/utils/pathname.js +0 -7
  417. package/lib/service/http/index.d.ts +0 -3
  418. package/lib/service/http/index.js +0 -18
  419. package/lib/service/http/middlewares/authTokens.d.ts +0 -3
  420. package/lib/service/http/middlewares/cancellationToken.d.ts +0 -3
  421. package/lib/service/http/middlewares/clients.d.ts +0 -4
  422. package/lib/service/http/middlewares/error.d.ts +0 -3
  423. package/lib/service/http/middlewares/setCookie.d.ts +0 -3
  424. package/lib/service/http/middlewares/timings.d.ts +0 -3
  425. package/lib/service/http/middlewares/vary.d.ts +0 -3
  426. package/lib/service/method.d.ts +0 -9
  427. package/lib/service/typings.d.ts +0 -139
  428. package/lib/service/utils/compose.d.ts +0 -4
  429. package/lib/service/utils/compose.js +0 -11
  430. package/lib/utils/MineWinsConflictsResolver.test.d.ts +0 -1
  431. package/lib/utils/MineWinsConflictsResolver.test.js +0 -134
  432. package/lib/utils/unhandled.d.ts +0 -1
  433. /package/lib/service/{graphql → worker/runtime/graphql}/middlewares/error.d.ts +0 -0
  434. /package/lib/service/{graphql → worker/runtime/graphql}/middlewares/response.d.ts +0 -0
  435. /package/lib/service/{graphql → worker/runtime/graphql}/schema/typeDefs/ioUpload.d.ts +0 -0
  436. /package/lib/service/{graphql → worker/runtime/graphql}/schema/typeDefs/sanitizedString.d.ts +0 -0
  437. /package/lib/service/{graphql → worker/runtime/graphql}/typings.js +0 -0
  438. /package/lib/service/{graphql → worker/runtime/graphql}/utils/pathname.d.ts +0 -0
  439. /package/lib/service/{typings.js → worker/runtime/typings.js} +0 -0
  440. /package/lib/service/{graphql/utils/array.d.ts → worker/runtime/utils/toArray.d.ts} +0 -0
@@ -0,0 +1,511 @@
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.Apps = void 0;
7
+ const archiver_1 = __importDefault(require("archiver"));
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 InfraClient_1 = require("./InfraClient");
14
+ const createRoutes = ({ account, workspace }) => {
15
+ const routes = {
16
+ Acknowledge: (app, service) => `${routes.App(app)}/acknowledge/${service}`,
17
+ App: (app) => `${routes.Apps()}/${app}`,
18
+ AppBundle: (locator, path) => `${routes.AppOrRegistry(locator)}/bundle/${path}`,
19
+ AppOrRegistry: ({ name, version, build }) => build
20
+ ? `${routes.Apps()}/${name}@${version}+${build}`
21
+ : `${routes.Registry()}/${name}/${version}`,
22
+ Apps: () => `${routes.Workspace}/apps`,
23
+ Dependencies: () => `${routes.Workspace}/dependencies`,
24
+ File: (locator, path) => `${routes.Files(locator)}/${path}`,
25
+ FileFromApps: (app, path) => `${routes.Workspace}/apps/${app}/files/${path}`,
26
+ Files: (locator) => `${routes.AppOrRegistry(locator)}/files`,
27
+ Link: (app) => `${routes.Workspace}/v2/links/${app}`,
28
+ Links: () => `${routes.Workspace}/links`,
29
+ Master: `/${account}/master`,
30
+ Meta: () => `${routes.Workspace}/v2/apps`,
31
+ Registry: () => `${routes.Master}/registry`,
32
+ ResolveDependencies: () => `${routes.Workspace}/dependencies/_resolve`,
33
+ ResolveDependenciesWithManifest: () => `${routes.Workspace}/v2/apps/_resolve`,
34
+ Settings: (app) => `${routes.App(app)}/settings`,
35
+ Unlink: (app) => `${routes.Links()}/${app}`,
36
+ Workspace: `/${account}/${workspace}`,
37
+ };
38
+ return routes;
39
+ };
40
+ const getVendorAndName = ({ id }) => (0, utils_1.removeVersionFromAppId)(id);
41
+ const notFound = (e) => {
42
+ if (e.response && e.response.status === 404) {
43
+ return {};
44
+ }
45
+ throw e;
46
+ };
47
+ const zipObj = (keys, values) => {
48
+ let idx = 0;
49
+ const len = Math.min(keys.length, values.length);
50
+ const out = {};
51
+ while (idx < len) {
52
+ out[keys[idx]] = values[idx];
53
+ idx += 1;
54
+ }
55
+ return out;
56
+ };
57
+ // 🚨🚨🚨
58
+ // In order to make changes in here, please also change the colossus App so we
59
+ // share the same cache key and do NOT call Apps unecessarily
60
+ const workspaceFields = [
61
+ '_activationDate',
62
+ '_buildFeatures',
63
+ '_isRoot',
64
+ '_resolvedDependencies',
65
+ 'credentialType',
66
+ 'link',
67
+ 'name',
68
+ 'registry',
69
+ 'settingsSchema',
70
+ 'vendor',
71
+ 'version',
72
+ ].join(',');
73
+ class Apps extends InfraClient_1.InfraClient {
74
+ get routes() {
75
+ return this._routes;
76
+ }
77
+ constructor(context, options) {
78
+ super('apps@0.x', context, options, true);
79
+ this.installApp = (descriptor, tracingConfig) => {
80
+ if (descriptor.startsWith('infra:service-')) {
81
+ return this.installRuntime(descriptor, tracingConfig);
82
+ }
83
+ const metric = 'apps-install';
84
+ return this.http.post(this.routes.Apps(), { id: descriptor }, {
85
+ metric,
86
+ tracing: {
87
+ requestSpanNameSuffix: metric,
88
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
89
+ },
90
+ });
91
+ };
92
+ this.uninstallApp = (app, tracingConfig) => {
93
+ const metric = 'apps-uninstall';
94
+ return this.http.delete(this.routes.App(app), {
95
+ metric,
96
+ tracing: {
97
+ requestSpanNameSuffix: metric,
98
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
99
+ },
100
+ });
101
+ };
102
+ this.acknowledgeApp = (app, service, tracingConfig) => {
103
+ const metric = 'apps-ack';
104
+ return this.http.put(this.routes.Acknowledge(app, service), null, {
105
+ metric,
106
+ tracing: {
107
+ requestSpanNameSuffix: metric,
108
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
109
+ },
110
+ });
111
+ };
112
+ this.link = async (app, files, { zlib } = {}, tracingConfig) => {
113
+ if (!(files[0] && files[0].path)) {
114
+ throw new Error('Argument files must be an array of {path, content}, where content can be a String, a Buffer or a ReadableStream.');
115
+ }
116
+ const emptyChanges = files.filter(file => !file.content);
117
+ if (emptyChanges.length > 0) {
118
+ throw new Error(`Missing content for paths: ${emptyChanges.map(e => e.path).join('; ')}`);
119
+ }
120
+ const indexOfManifest = files.findIndex(({ path }) => path === 'manifest.json');
121
+ if (indexOfManifest === -1) {
122
+ throw new Error('No manifest.json file found in files.');
123
+ }
124
+ const zip = (0, archiver_1.default)('zip', { zlib });
125
+ // Throw stream errors so they reject the promise chain.
126
+ zip.on('error', (e) => {
127
+ throw e;
128
+ });
129
+ const metric = 'apps-link';
130
+ const request = this.http.put(this.routes.Link(app), zip, {
131
+ headers: { 'Content-Type': 'application/zip' },
132
+ metric,
133
+ tracing: {
134
+ requestSpanNameSuffix: metric,
135
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
136
+ },
137
+ });
138
+ files.forEach(({ content, path }) => zip.append(content, { name: path }));
139
+ const finalize = zip.finalize();
140
+ try {
141
+ const [response] = await Promise.all([request, finalize]);
142
+ response.bundleSize = zip.pointer();
143
+ return response;
144
+ }
145
+ catch (e) {
146
+ // Typing cast for compatibility with error handling in TS versions > 4.0
147
+ // Source: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#unknown-on-catch-clause-bindings
148
+ e.bundleSize = zip.pointer();
149
+ throw e;
150
+ }
151
+ };
152
+ this.patch = async (app, changes, { zlib } = {}, tracingConfig) => {
153
+ if (!(changes[0] && changes[0].path)) {
154
+ throw new Error('Argument changes must be an array of {path, content}, where content can be a String, a Buffer or a ReadableStream.');
155
+ }
156
+ const files = changes.filter(change => !!change.content);
157
+ const deletedFiles = changes
158
+ .filter(change => !change.content)
159
+ .map(change => change.path)
160
+ .join(':');
161
+ const zip = (0, archiver_1.default)('zip', { zlib });
162
+ // Throw stream errors so they reject the promise chain.
163
+ zip.on('error', (e) => {
164
+ throw e;
165
+ });
166
+ const metric = 'apps-patch';
167
+ const request = this.http.patch(this.routes.Link(app), zip, {
168
+ headers: { 'Content-Type': 'application/zip' },
169
+ metric,
170
+ params: { deletedFiles },
171
+ tracing: {
172
+ requestSpanNameSuffix: metric,
173
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
174
+ },
175
+ });
176
+ files.forEach(({ content, path }) => zip.append(content, { name: path }));
177
+ const finalize = zip.finalize();
178
+ const [response] = await Promise.all([request, finalize]);
179
+ return response;
180
+ };
181
+ this.unlink = (app, tracingConfig) => {
182
+ return this.http.delete(this.routes.Unlink(app), {
183
+ tracing: {
184
+ requestSpanNameSuffix: 'apps-unlink',
185
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
186
+ },
187
+ });
188
+ };
189
+ this.unlinkAll = (tracingConfig) => {
190
+ return this.http.delete(this.routes.Links(), {
191
+ tracing: {
192
+ requestSpanNameSuffix: 'apps-unlink-all',
193
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
194
+ },
195
+ });
196
+ };
197
+ this.saveAppSettings = (app, settings, tracingConfig) => {
198
+ const headers = { 'Content-Type': 'application/json' };
199
+ const metric = 'apps-save';
200
+ return this.http.put(this.routes.Settings(app), settings, {
201
+ headers,
202
+ metric,
203
+ tracing: {
204
+ requestSpanNameSuffix: metric,
205
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
206
+ },
207
+ });
208
+ };
209
+ this.listApps = ({ oldVersion, since, service } = {}, tracingConfig) => {
210
+ const params = {
211
+ oldVersion,
212
+ service,
213
+ since,
214
+ };
215
+ const metric = 'apps-list';
216
+ const inflightKey = HttpClient_1.inflightUrlWithQuery;
217
+ return this.http.get(this.routes.Apps(), {
218
+ inflightKey,
219
+ metric,
220
+ params,
221
+ tracing: {
222
+ requestSpanNameSuffix: metric,
223
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
224
+ },
225
+ });
226
+ };
227
+ this.listAppFiles = (app, { prefix, nextMarker } = {}, tracingConfig) => {
228
+ const locator = (0, utils_1.parseAppId)(app);
229
+ const linked = !!locator.build;
230
+ const params = {
231
+ marker: nextMarker,
232
+ prefix,
233
+ };
234
+ const metric = linked ? 'apps-list-files' : 'registry-list-files';
235
+ const inflightKey = HttpClient_1.inflightUrlWithQuery;
236
+ return this.http.get(this.routes.Files(locator), {
237
+ inflightKey,
238
+ metric,
239
+ params,
240
+ tracing: {
241
+ requestSpanNameSuffix: metric,
242
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
243
+ },
244
+ });
245
+ };
246
+ this.listLinks = (tracingConfig) => {
247
+ const inflightKey = HttpClient_1.inflightURL;
248
+ const metric = 'apps-list-links';
249
+ return this.http.get(this.routes.Links(), {
250
+ inflightKey,
251
+ metric,
252
+ tracing: {
253
+ requestSpanNameSuffix: metric,
254
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
255
+ },
256
+ });
257
+ };
258
+ this.getAppFile = (app, path, staleIfError, tracingConfig) => {
259
+ const { logger } = this.context;
260
+ const locator = (0, utils_1.parseAppId)(app);
261
+ const linked = !!locator.build;
262
+ const inflightKey = HttpClient_1.inflightURL;
263
+ if (staleIfError && this.memoryCache) {
264
+ (0, appsStaleIfError_1.saveVersion)(app, this.memoryCache);
265
+ }
266
+ const metric = linked ? 'apps-get-file' : 'registry-get-file';
267
+ try {
268
+ return this.http.getBuffer(this.routes.File(locator, path), {
269
+ cacheable: linked ? HttpClient_1.CacheType.Memory : HttpClient_1.CacheType.Disk,
270
+ inflightKey,
271
+ metric,
272
+ tracing: {
273
+ requestSpanNameSuffix: metric,
274
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
275
+ },
276
+ });
277
+ }
278
+ catch (error) {
279
+ logger.error({ error, message: 'getAppFile failed', app, path });
280
+ if (staleIfError && this.memoryCache) {
281
+ return (0, appsStaleIfError_1.getFallbackFile)(app, path, this.memoryCache, this);
282
+ }
283
+ throw error;
284
+ }
285
+ };
286
+ this.getAppJSON = (app, path, nullIfNotFound, tracingConfig) => {
287
+ const locator = (0, utils_1.parseAppId)(app);
288
+ const linked = !!locator.build;
289
+ const inflightKey = HttpClient_1.inflightURL;
290
+ const metric = linked ? 'apps-get-json' : 'registry-get-json';
291
+ return this.http.get(this.routes.File(locator, path), {
292
+ cacheable: linked ? HttpClient_1.CacheType.Memory : HttpClient_1.CacheType.Any,
293
+ inflightKey,
294
+ metric,
295
+ nullIfNotFound,
296
+ tracing: {
297
+ requestSpanNameSuffix: metric,
298
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
299
+ },
300
+ });
301
+ };
302
+ this.getFileFromApps = (app, path, nullIfNotFound, tracingConfig) => {
303
+ const inflightKey = HttpClient_1.inflightURL;
304
+ const metric = 'get-file-from-apps';
305
+ return this.http.get(this.routes.FileFromApps(app, path), {
306
+ cacheable: HttpClient_1.CacheType.Memory,
307
+ inflightKey,
308
+ metric,
309
+ nullIfNotFound,
310
+ tracing: {
311
+ requestSpanNameSuffix: metric,
312
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
313
+ },
314
+ });
315
+ };
316
+ this.getAppFileStream = (app, path, tracingConfig) => {
317
+ const locator = (0, utils_1.parseAppId)(app);
318
+ const metric = locator.build ? 'apps-get-file-s' : 'registry-get-file-s';
319
+ return this.http.getStream(this.routes.File(locator, path), {
320
+ metric,
321
+ tracing: {
322
+ requestSpanNameSuffix: metric,
323
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
324
+ },
325
+ });
326
+ };
327
+ this.getApp = (app, tracingConfig) => {
328
+ const metric = 'apps-get-app';
329
+ const inflightKey = HttpClient_1.inflightURL;
330
+ return this.http.get(this.routes.App(app), {
331
+ inflightKey,
332
+ metric,
333
+ tracing: {
334
+ requestSpanNameSuffix: metric,
335
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
336
+ },
337
+ });
338
+ };
339
+ this.getAppSettings = (app, tracingConfig) => {
340
+ const inflightKey = HttpClient_1.inflightURL;
341
+ const metric = 'apps-get-settings';
342
+ return this.http.get(this.routes.Settings(app), {
343
+ inflightKey,
344
+ metric,
345
+ tracing: {
346
+ requestSpanNameSuffix: metric,
347
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
348
+ },
349
+ });
350
+ };
351
+ this.getAllAppsSettings = (listAppsOptions = {}, tracingConfig) => {
352
+ return this.listApps(listAppsOptions, tracingConfig).then(({ data: installedApps }) => {
353
+ const names = installedApps.map(getVendorAndName);
354
+ const settingsPromises = names.map(vendorAndName => this.getAppSettings(vendorAndName, tracingConfig).catch(notFound));
355
+ return Promise.all(settingsPromises).then((settings) => {
356
+ return zipObj(names, settings);
357
+ });
358
+ });
359
+ };
360
+ this.getAppBundle = (app, bundlePath, generatePackageJson, tracingConfig) => {
361
+ const locator = (0, utils_1.parseAppId)(app);
362
+ const params = generatePackageJson && { _packageJSONEngine: 'npm', _packageJSONFilter: 'vtex.render-builder@x' };
363
+ const metric = locator.build ? 'apps-get-bundle' : 'registry-get-bundle';
364
+ return this.http.getStream(this.routes.AppBundle(locator, bundlePath), {
365
+ headers: {
366
+ Accept: 'application/x-gzip',
367
+ 'Accept-Encoding': 'gzip',
368
+ },
369
+ metric,
370
+ params,
371
+ tracing: {
372
+ requestSpanNameSuffix: metric,
373
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
374
+ },
375
+ });
376
+ };
377
+ this.unpackAppBundle = (app, bundlePath, unpackPath, generatePackageJson, tracingConfig) => {
378
+ return this.getAppBundle(app, bundlePath, generatePackageJson, tracingConfig)
379
+ .then(stream => stream
380
+ .pipe((0, zlib_1.createGunzip)())
381
+ .pipe((0, tar_fs_1.extract)(unpackPath)));
382
+ };
383
+ this.getAppsMetaInfos = async (filter, staleWhileRevalidate = true, tracingConfig) => {
384
+ var _a;
385
+ const { account, production, recorder, workspace, logger } = this.context;
386
+ const metric = 'get-apps-meta';
387
+ const inflightKey = HttpClient_1.inflightURL;
388
+ const key = (0, appsStaleIfError_1.getMetaInfoKey)(account, workspace);
389
+ const cachedResponse = production && staleWhileRevalidate
390
+ ? await ((_a = this.diskCache) === null || _a === void 0 ? void 0 : _a.get(key))
391
+ : undefined;
392
+ if (cachedResponse && recorder) {
393
+ recorder.record(cachedResponse.headers);
394
+ }
395
+ const metaInfoPromise = this.http
396
+ .getRaw(this.routes.Meta(), {
397
+ ignoreRecorder: Boolean(cachedResponse),
398
+ inflightKey,
399
+ metric,
400
+ params: { fields: workspaceFields },
401
+ tracing: {
402
+ requestSpanNameSuffix: metric,
403
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
404
+ },
405
+ })
406
+ .then(response => {
407
+ const { data, headers: responseHeaders } = response;
408
+ if (this.diskCache && production) {
409
+ this.diskCache.set(key, {
410
+ appsMetaInfo: data.apps || [],
411
+ headers: responseHeaders,
412
+ });
413
+ }
414
+ return response;
415
+ });
416
+ let appsMetaInfo;
417
+ if (cachedResponse) {
418
+ appsMetaInfo = cachedResponse.appsMetaInfo;
419
+ metaInfoPromise.catch(error => {
420
+ logger.warn({ message: 'Unable to update stale cache', error });
421
+ });
422
+ }
423
+ else {
424
+ appsMetaInfo = await metaInfoPromise.then(response => response.data.apps);
425
+ }
426
+ if (filter) {
427
+ return appsMetaInfo.filter(appMeta => { var _a; return (_a = appMeta === null || appMeta === void 0 ? void 0 : appMeta._resolvedDependencies) === null || _a === void 0 ? void 0 : _a.filter; });
428
+ }
429
+ return appsMetaInfo;
430
+ };
431
+ this.getDependencies = (filter = '', tracingConfig) => {
432
+ const params = { filter };
433
+ const metric = 'apps-get-deps';
434
+ const inflightKey = HttpClient_1.inflightUrlWithQuery;
435
+ return this.http.get(this.routes.Dependencies(), {
436
+ inflightKey,
437
+ metric,
438
+ params,
439
+ tracing: {
440
+ requestSpanNameSuffix: metric,
441
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
442
+ },
443
+ });
444
+ };
445
+ this.updateDependencies = (tracingConfig) => {
446
+ const metric = 'apps-update-deps';
447
+ return this.http.put(this.routes.Dependencies(), null, {
448
+ metric,
449
+ tracing: {
450
+ requestSpanNameSuffix: metric,
451
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
452
+ },
453
+ });
454
+ };
455
+ this.updateDependency = (name, version, registry, tracingConfig) => {
456
+ const metric = 'apps-update-dep';
457
+ return this.http.patch(this.routes.Apps(), [{ name, version, registry }], {
458
+ metric,
459
+ tracing: {
460
+ requestSpanNameSuffix: metric,
461
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
462
+ },
463
+ });
464
+ };
465
+ this.resolveDependencies = (apps, registries, filter = '', tracingConfig) => {
466
+ const params = { apps, registries, filter };
467
+ const metric = 'apps-resolve-deps';
468
+ const inflightKey = HttpClient_1.inflightUrlWithQuery;
469
+ return this.http.get(this.routes.ResolveDependencies(), {
470
+ inflightKey,
471
+ metric,
472
+ params,
473
+ tracing: {
474
+ requestSpanNameSuffix: metric,
475
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
476
+ },
477
+ });
478
+ };
479
+ this.resolveDependenciesWithManifest = (manifest, filter = '', tracingConfig) => {
480
+ const params = { filter };
481
+ const metric = 'apps-resolve-deps-m';
482
+ return this.http.post(this.routes.ResolveDependenciesWithManifest(), manifest, {
483
+ metric,
484
+ params,
485
+ tracing: {
486
+ requestSpanNameSuffix: metric,
487
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
488
+ },
489
+ });
490
+ };
491
+ this.installRuntime = (descriptor, tracingConfig) => {
492
+ const { account, workspace } = this.context;
493
+ const [name, version] = descriptor.split('@');
494
+ return this.http.patch(`http://apps.aws-us-east-1.vtex.io/${account}/${workspace}/apps`, [
495
+ {
496
+ name,
497
+ version,
498
+ },
499
+ ], {
500
+ tracing: {
501
+ requestSpanNameSuffix: 'apps-install-runtime',
502
+ ...tracingConfig === null || tracingConfig === void 0 ? void 0 : tracingConfig.tracing,
503
+ },
504
+ });
505
+ };
506
+ this.diskCache = options && options.diskCache;
507
+ this.memoryCache = options && options.memoryCache;
508
+ this._routes = createRoutes(context);
509
+ }
510
+ }
511
+ exports.Apps = Apps;
@@ -0,0 +1,35 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Readable } from 'stream';
4
+ import { AppMetaInfo } from '../..';
5
+ import { InstanceOptions, RequestTracingConfig } from '../../HttpClient';
6
+ import { IOContext } from '../../service/worker/runtime/typings';
7
+ import { InfraClient } from './InfraClient';
8
+ export interface AssetsParams {
9
+ files?: string[];
10
+ pick?: string[];
11
+ }
12
+ export declare class Assets extends InfraClient {
13
+ private routes;
14
+ constructor(context: IOContext, options?: InstanceOptions);
15
+ getSettings(dependencies: AppMetaInfo[], appAtMajor: string, params?: AssetsParams, tracingConfig?: RequestTracingConfig): Promise<Record<string, any>[]>;
16
+ getBuildJSONForApp(app: AppMetaInfo, appVendorName: string, pick?: string | string[], tracingConfig?: RequestTracingConfig): Promise<Record<string, any>>;
17
+ getSettingsFromFilesForApp(app: AppMetaInfo, files?: string | string[], tracingConfig?: RequestTracingConfig): Promise<Record<string, any>>;
18
+ getJSON<T extends object | null>(appId: string, file: string, nullIfNotFound?: boolean, tracingConfig?: RequestTracingConfig): Promise<T>;
19
+ getFile(appId: string, file: string, nullIfNotFound?: boolean, tracingConfig?: RequestTracingConfig): Promise<{
20
+ data: Buffer;
21
+ headers: any;
22
+ }>;
23
+ getFilteredDependencies(apps: string | string[], dependencies: AppMetaInfo[]): AppMetaInfo[];
24
+ getAppBundleByVendor: (app: string, bundlePath: string, generatePackageJson: boolean, tracingConfig?: RequestTracingConfig) => Promise<Readable>;
25
+ protected getAppJSONByAccount: <T extends object | null>(app: string, path: string, nullIfNotFound?: boolean, tracingConfig?: RequestTracingConfig) => Promise<T>;
26
+ protected getAppJSONByVendor: <T extends object | null>(app: string, path: string, nullIfNotFound?: boolean, tracingConfig?: RequestTracingConfig) => Promise<T>;
27
+ protected getAppFileByAccount: (app: string, path: string, nullIfNotFound?: boolean, tracingConfig?: RequestTracingConfig) => Promise<{
28
+ data: Buffer;
29
+ headers: any;
30
+ }>;
31
+ protected getAppFileByVendor: (app: string, path: string, nullIfNotFound?: boolean, tracingConfig?: RequestTracingConfig) => Promise<{
32
+ data: Buffer;
33
+ headers: any;
34
+ }>;
35
+ }