@vtex/api 6.45.4

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 (360) hide show
  1. package/CHANGELOG.md +1685 -0
  2. package/README.md +65 -0
  3. package/gen/manifest.schema +189 -0
  4. package/lib/HttpClient/GraphQLClient.d.ts +28 -0
  5. package/lib/HttpClient/GraphQLClient.js +30 -0
  6. package/lib/HttpClient/HttpClient.d.ts +29 -0
  7. package/lib/HttpClient/HttpClient.js +130 -0
  8. package/lib/HttpClient/agents.d.ts +3 -0
  9. package/lib/HttpClient/agents.js +24 -0
  10. package/lib/HttpClient/index.d.ts +6 -0
  11. package/lib/HttpClient/index.js +14 -0
  12. package/lib/HttpClient/middlewares/cache.d.ts +35 -0
  13. package/lib/HttpClient/middlewares/cache.js +173 -0
  14. package/lib/HttpClient/middlewares/cancellationToken.d.ts +3 -0
  15. package/lib/HttpClient/middlewares/cancellationToken.js +72 -0
  16. package/lib/HttpClient/middlewares/inflight.d.ts +5 -0
  17. package/lib/HttpClient/middlewares/inflight.js +50 -0
  18. package/lib/HttpClient/middlewares/memoization.d.ts +7 -0
  19. package/lib/HttpClient/middlewares/memoization.js +40 -0
  20. package/lib/HttpClient/middlewares/metrics.d.ts +9 -0
  21. package/lib/HttpClient/middlewares/metrics.js +110 -0
  22. package/lib/HttpClient/middlewares/notFound.d.ts +7 -0
  23. package/lib/HttpClient/middlewares/notFound.js +20 -0
  24. package/lib/HttpClient/middlewares/recorder.d.ts +3 -0
  25. package/lib/HttpClient/middlewares/recorder.js +21 -0
  26. package/lib/HttpClient/middlewares/request/HttpAgentSingleton.d.ts +14 -0
  27. package/lib/HttpClient/middlewares/request/HttpAgentSingleton.js +37 -0
  28. package/lib/HttpClient/middlewares/request/index.d.ts +18 -0
  29. package/lib/HttpClient/middlewares/request/index.js +83 -0
  30. package/lib/HttpClient/middlewares/request/setupAxios/index.d.ts +1 -0
  31. package/lib/HttpClient/middlewares/request/setupAxios/index.js +20 -0
  32. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.d.ts +2 -0
  33. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/exponentialBackoff.js +48 -0
  34. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.d.ts +2 -0
  35. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/index.js +7 -0
  36. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.d.ts +8 -0
  37. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/index.js +51 -0
  38. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.d.ts +4 -0
  39. package/lib/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.js +29 -0
  40. package/lib/HttpClient/middlewares/tracing.d.ts +15 -0
  41. package/lib/HttpClient/middlewares/tracing.js +54 -0
  42. package/lib/HttpClient/typings.d.ts +123 -0
  43. package/lib/HttpClient/typings.js +11 -0
  44. package/lib/caches/CacheLayer.d.ts +7 -0
  45. package/lib/caches/CacheLayer.js +2 -0
  46. package/lib/caches/DiskCache.d.ts +17 -0
  47. package/lib/caches/DiskCache.js +70 -0
  48. package/lib/caches/LRUCache.d.ts +16 -0
  49. package/lib/caches/LRUCache.js +48 -0
  50. package/lib/caches/LRUDiskCache.d.ts +21 -0
  51. package/lib/caches/LRUDiskCache.js +132 -0
  52. package/lib/caches/MultilayeredCache.d.ts +14 -0
  53. package/lib/caches/MultilayeredCache.js +68 -0
  54. package/lib/caches/index.d.ts +6 -0
  55. package/lib/caches/index.js +9 -0
  56. package/lib/caches/typings.d.ts +48 -0
  57. package/lib/caches/typings.js +2 -0
  58. package/lib/clients/IOClient.d.ts +13 -0
  59. package/lib/clients/IOClient.js +19 -0
  60. package/lib/clients/IOClients.d.ts +37 -0
  61. package/lib/clients/IOClients.js +89 -0
  62. package/lib/clients/IOGraphQLClient.d.ts +13 -0
  63. package/lib/clients/IOGraphQLClient.js +16 -0
  64. package/lib/clients/apps/AppClient.d.ts +9 -0
  65. package/lib/clients/apps/AppClient.js +34 -0
  66. package/lib/clients/apps/AppGraphQLClient.d.ts +9 -0
  67. package/lib/clients/apps/AppGraphQLClient.js +34 -0
  68. package/lib/clients/apps/Billing.d.ts +12 -0
  69. package/lib/clients/apps/Billing.js +21 -0
  70. package/lib/clients/apps/Builder.d.ts +45 -0
  71. package/lib/clients/apps/Builder.js +114 -0
  72. package/lib/clients/apps/MessagesGraphQL.d.ts +61 -0
  73. package/lib/clients/apps/MessagesGraphQL.js +121 -0
  74. package/lib/clients/apps/Settings.d.ts +14 -0
  75. package/lib/clients/apps/Settings.js +38 -0
  76. package/lib/clients/apps/catalogGraphQL/brand.d.ts +13 -0
  77. package/lib/clients/apps/catalogGraphQL/brand.js +18 -0
  78. package/lib/clients/apps/catalogGraphQL/category.d.ts +11 -0
  79. package/lib/clients/apps/catalogGraphQL/category.js +16 -0
  80. package/lib/clients/apps/catalogGraphQL/index.d.ts +22 -0
  81. package/lib/clients/apps/catalogGraphQL/index.js +88 -0
  82. package/lib/clients/apps/catalogGraphQL/product.d.ts +25 -0
  83. package/lib/clients/apps/catalogGraphQL/product.js +30 -0
  84. package/lib/clients/apps/catalogGraphQL/sku.d.ts +26 -0
  85. package/lib/clients/apps/catalogGraphQL/sku.js +30 -0
  86. package/lib/clients/apps/index.d.ts +7 -0
  87. package/lib/clients/apps/index.js +12 -0
  88. package/lib/clients/external/ExternalClient.d.ts +9 -0
  89. package/lib/clients/external/ExternalClient.js +21 -0
  90. package/lib/clients/external/ID.d.ts +23 -0
  91. package/lib/clients/external/ID.js +60 -0
  92. package/lib/clients/external/Masterdata.d.ts +93 -0
  93. package/lib/clients/external/Masterdata.js +223 -0
  94. package/lib/clients/external/PaymentProvider.d.ts +31 -0
  95. package/lib/clients/external/PaymentProvider.js +42 -0
  96. package/lib/clients/external/index.d.ts +4 -0
  97. package/lib/clients/external/index.js +9 -0
  98. package/lib/clients/index.d.ts +9 -0
  99. package/lib/clients/index.js +17 -0
  100. package/lib/clients/infra/Apps.d.ts +88 -0
  101. package/lib/clients/infra/Apps.js +508 -0
  102. package/lib/clients/infra/Assets.d.ts +34 -0
  103. package/lib/clients/infra/Assets.js +165 -0
  104. package/lib/clients/infra/BillingMetrics.d.ts +13 -0
  105. package/lib/clients/infra/BillingMetrics.js +15 -0
  106. package/lib/clients/infra/Events.d.ts +12 -0
  107. package/lib/clients/infra/Events.js +33 -0
  108. package/lib/clients/infra/Housekeeper.d.ts +10 -0
  109. package/lib/clients/infra/Housekeeper.js +30 -0
  110. package/lib/clients/infra/InfraClient.d.ts +9 -0
  111. package/lib/clients/infra/InfraClient.js +34 -0
  112. package/lib/clients/infra/Metadata.d.ts +26 -0
  113. package/lib/clients/infra/Metadata.js +83 -0
  114. package/lib/clients/infra/Registry.d.ts +59 -0
  115. package/lib/clients/infra/Registry.js +207 -0
  116. package/lib/clients/infra/Router.d.ts +34 -0
  117. package/lib/clients/infra/Router.js +81 -0
  118. package/lib/clients/infra/Sphinx.d.ts +13 -0
  119. package/lib/clients/infra/Sphinx.js +29 -0
  120. package/lib/clients/infra/VBase.d.ts +60 -0
  121. package/lib/clients/infra/VBase.js +171 -0
  122. package/lib/clients/infra/Workspaces.d.ts +18 -0
  123. package/lib/clients/infra/Workspaces.js +65 -0
  124. package/lib/clients/infra/index.d.ts +12 -0
  125. package/lib/clients/infra/index.js +17 -0
  126. package/lib/clients/janus/JanusClient.d.ts +21 -0
  127. package/lib/clients/janus/JanusClient.js +30 -0
  128. package/lib/clients/janus/LicenseManager.d.ts +7 -0
  129. package/lib/clients/janus/LicenseManager.js +58 -0
  130. package/lib/clients/janus/Segment.d.ts +36 -0
  131. package/lib/clients/janus/Segment.js +79 -0
  132. package/lib/clients/janus/Session.d.ts +15 -0
  133. package/lib/clients/janus/Session.js +75 -0
  134. package/lib/clients/janus/Tenant.d.ts +29 -0
  135. package/lib/clients/janus/Tenant.js +28 -0
  136. package/lib/clients/janus/index.d.ts +5 -0
  137. package/lib/clients/janus/index.js +10 -0
  138. package/lib/constants.d.ts +59 -0
  139. package/lib/constants.js +65 -0
  140. package/lib/errors/AuthenticationError.d.ts +18 -0
  141. package/lib/errors/AuthenticationError.js +24 -0
  142. package/lib/errors/ForbiddenError.d.ts +18 -0
  143. package/lib/errors/ForbiddenError.js +24 -0
  144. package/lib/errors/NotFoundError.d.ts +18 -0
  145. package/lib/errors/NotFoundError.js +24 -0
  146. package/lib/errors/RequestCancelledError.d.ts +6 -0
  147. package/lib/errors/RequestCancelledError.js +11 -0
  148. package/lib/errors/ResolverError.d.ts +29 -0
  149. package/lib/errors/ResolverError.js +35 -0
  150. package/lib/errors/ResolverWarning.d.ts +21 -0
  151. package/lib/errors/ResolverWarning.js +28 -0
  152. package/lib/errors/TooManyRequestsError.d.ts +4 -0
  153. package/lib/errors/TooManyRequestsError.js +9 -0
  154. package/lib/errors/UserInputError.d.ts +18 -0
  155. package/lib/errors/UserInputError.js +24 -0
  156. package/lib/errors/customGraphQLError.d.ts +4 -0
  157. package/lib/errors/customGraphQLError.js +9 -0
  158. package/lib/errors/index.d.ts +8 -0
  159. package/lib/errors/index.js +13 -0
  160. package/lib/index.d.ts +17 -0
  161. package/lib/index.js +21 -0
  162. package/lib/metrics/MetricsAccumulator.d.ts +35 -0
  163. package/lib/metrics/MetricsAccumulator.js +125 -0
  164. package/lib/responses.d.ts +79 -0
  165. package/lib/responses.js +2 -0
  166. package/lib/service/index.d.ts +2 -0
  167. package/lib/service/index.js +30 -0
  168. package/lib/service/loaders.d.ts +8 -0
  169. package/lib/service/loaders.js +54 -0
  170. package/lib/service/logger/console.d.ts +10 -0
  171. package/lib/service/logger/console.js +36 -0
  172. package/lib/service/logger/index.d.ts +2 -0
  173. package/lib/service/logger/index.js +7 -0
  174. package/lib/service/logger/logger.d.ts +35 -0
  175. package/lib/service/logger/logger.js +73 -0
  176. package/lib/service/logger/metricsLogger.d.ts +40 -0
  177. package/lib/service/logger/metricsLogger.js +149 -0
  178. package/lib/service/master.d.ts +2 -0
  179. package/lib/service/master.js +91 -0
  180. package/lib/service/tracing/TracerSingleton.d.ts +7 -0
  181. package/lib/service/tracing/TracerSingleton.js +54 -0
  182. package/lib/service/tracing/metrics/MetricNames.d.ts +60 -0
  183. package/lib/service/tracing/metrics/MetricNames.js +44 -0
  184. package/lib/service/tracing/metrics/instruments.d.ts +9 -0
  185. package/lib/service/tracing/metrics/instruments.js +11 -0
  186. package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.d.ts +9 -0
  187. package/lib/service/tracing/metrics/measurers/EventLoopLagMeasurer.js +25 -0
  188. package/lib/service/tracing/tracingMiddlewares.d.ts +5 -0
  189. package/lib/service/tracing/tracingMiddlewares.js +119 -0
  190. package/lib/service/worker/index.d.ts +11 -0
  191. package/lib/service/worker/index.js +193 -0
  192. package/lib/service/worker/listeners.d.ts +3 -0
  193. package/lib/service/worker/listeners.js +43 -0
  194. package/lib/service/worker/runtime/Service.d.ts +17 -0
  195. package/lib/service/worker/runtime/Service.js +23 -0
  196. package/lib/service/worker/runtime/builtIn/handlers.d.ts +4 -0
  197. package/lib/service/worker/runtime/builtIn/handlers.js +27 -0
  198. package/lib/service/worker/runtime/builtIn/middlewares.d.ts +4 -0
  199. package/lib/service/worker/runtime/builtIn/middlewares.js +40 -0
  200. package/lib/service/worker/runtime/events/index.d.ts +4 -0
  201. package/lib/service/worker/runtime/events/index.js +46 -0
  202. package/lib/service/worker/runtime/events/middlewares/body.d.ts +3 -0
  203. package/lib/service/worker/runtime/events/middlewares/body.js +22 -0
  204. package/lib/service/worker/runtime/events/middlewares/context.d.ts +3 -0
  205. package/lib/service/worker/runtime/events/middlewares/context.js +22 -0
  206. package/lib/service/worker/runtime/events/router.d.ts +2 -0
  207. package/lib/service/worker/runtime/events/router.js +27 -0
  208. package/lib/service/worker/runtime/graphql/index.d.ts +6 -0
  209. package/lib/service/worker/runtime/graphql/index.js +27 -0
  210. package/lib/service/worker/runtime/graphql/middlewares/context.d.ts +2 -0
  211. package/lib/service/worker/runtime/graphql/middlewares/context.js +16 -0
  212. package/lib/service/worker/runtime/graphql/middlewares/error.d.ts +2 -0
  213. package/lib/service/worker/runtime/graphql/middlewares/error.js +93 -0
  214. package/lib/service/worker/runtime/graphql/middlewares/query.d.ts +2 -0
  215. package/lib/service/worker/runtime/graphql/middlewares/query.js +52 -0
  216. package/lib/service/worker/runtime/graphql/middlewares/response.d.ts +2 -0
  217. package/lib/service/worker/runtime/graphql/middlewares/response.js +38 -0
  218. package/lib/service/worker/runtime/graphql/middlewares/run.d.ts +2 -0
  219. package/lib/service/worker/runtime/graphql/middlewares/run.js +19 -0
  220. package/lib/service/worker/runtime/graphql/middlewares/updateSchema.d.ts +4 -0
  221. package/lib/service/worker/runtime/graphql/middlewares/updateSchema.js +28 -0
  222. package/lib/service/worker/runtime/graphql/middlewares/upload.d.ts +4 -0
  223. package/lib/service/worker/runtime/graphql/middlewares/upload.js +12 -0
  224. package/lib/service/worker/runtime/graphql/schema/index.d.ts +7 -0
  225. package/lib/service/worker/runtime/graphql/schema/index.js +31 -0
  226. package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.d.ts +6 -0
  227. package/lib/service/worker/runtime/graphql/schema/messagesLoaderV2.js +79 -0
  228. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Auth.d.ts +6 -0
  229. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Auth.js +73 -0
  230. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.d.ts +7 -0
  231. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/CacheControl.js +37 -0
  232. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.d.ts +11 -0
  233. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Deprecated.js +61 -0
  234. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.d.ts +7 -0
  235. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Metric.js +40 -0
  236. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Sanitize.d.ts +9 -0
  237. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Sanitize.js +35 -0
  238. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.d.ts +6 -0
  239. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/Settings.js +34 -0
  240. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/SmartCacheDirective.d.ts +6 -0
  241. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/SmartCacheDirective.js +29 -0
  242. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.d.ts +7 -0
  243. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.js +39 -0
  244. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.d.ts +7 -0
  245. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslateTo.js +33 -0
  246. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.d.ts +22 -0
  247. package/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.js +36 -0
  248. package/lib/service/worker/runtime/graphql/schema/typeDefs/index.d.ts +7 -0
  249. package/lib/service/worker/runtime/graphql/schema/typeDefs/index.js +12 -0
  250. package/lib/service/worker/runtime/graphql/schema/typeDefs/ioUpload.d.ts +3 -0
  251. package/lib/service/worker/runtime/graphql/schema/typeDefs/ioUpload.js +16 -0
  252. package/lib/service/worker/runtime/graphql/schema/typeDefs/sanitizedString.d.ts +10 -0
  253. package/lib/service/worker/runtime/graphql/schema/typeDefs/sanitizedString.js +39 -0
  254. package/lib/service/worker/runtime/graphql/typings.d.ts +31 -0
  255. package/lib/service/worker/runtime/graphql/typings.js +2 -0
  256. package/lib/service/worker/runtime/graphql/utils/cacheControl.d.ts +1 -0
  257. package/lib/service/worker/runtime/graphql/utils/cacheControl.js +32 -0
  258. package/lib/service/worker/runtime/graphql/utils/error.d.ts +1 -0
  259. package/lib/service/worker/runtime/graphql/utils/error.js +76 -0
  260. package/lib/service/worker/runtime/graphql/utils/pathname.d.ts +1 -0
  261. package/lib/service/worker/runtime/graphql/utils/pathname.js +7 -0
  262. package/lib/service/worker/runtime/graphql/utils/translations.d.ts +14 -0
  263. package/lib/service/worker/runtime/graphql/utils/translations.js +38 -0
  264. package/lib/service/worker/runtime/http/index.d.ts +5 -0
  265. package/lib/service/worker/runtime/http/index.js +58 -0
  266. package/lib/service/worker/runtime/http/middlewares/authTokens.d.ts +3 -0
  267. package/lib/service/worker/runtime/http/middlewares/authTokens.js +12 -0
  268. package/lib/service/worker/runtime/http/middlewares/cancellationToken.d.ts +3 -0
  269. package/lib/service/worker/runtime/http/middlewares/cancellationToken.js +18 -0
  270. package/lib/service/worker/runtime/http/middlewares/clients.d.ts +4 -0
  271. package/lib/service/worker/runtime/http/middlewares/clients.js +12 -0
  272. package/lib/service/worker/runtime/http/middlewares/context.d.ts +4 -0
  273. package/lib/service/worker/runtime/http/middlewares/context.js +36 -0
  274. package/lib/service/worker/runtime/http/middlewares/error.d.ts +2 -0
  275. package/lib/service/worker/runtime/http/middlewares/error.js +84 -0
  276. package/lib/service/worker/runtime/http/middlewares/rateLimit.d.ts +6 -0
  277. package/lib/service/worker/runtime/http/middlewares/rateLimit.js +42 -0
  278. package/lib/service/worker/runtime/http/middlewares/requestStats.d.ts +17 -0
  279. package/lib/service/worker/runtime/http/middlewares/requestStats.js +40 -0
  280. package/lib/service/worker/runtime/http/middlewares/setCookie.d.ts +3 -0
  281. package/lib/service/worker/runtime/http/middlewares/setCookie.js +52 -0
  282. package/lib/service/worker/runtime/http/middlewares/settings.d.ts +9 -0
  283. package/lib/service/worker/runtime/http/middlewares/settings.js +43 -0
  284. package/lib/service/worker/runtime/http/middlewares/timings.d.ts +3 -0
  285. package/lib/service/worker/runtime/http/middlewares/timings.js +45 -0
  286. package/lib/service/worker/runtime/http/middlewares/vary.d.ts +3 -0
  287. package/lib/service/worker/runtime/http/middlewares/vary.js +52 -0
  288. package/lib/service/worker/runtime/http/router.d.ts +2 -0
  289. package/lib/service/worker/runtime/http/router.js +23 -0
  290. package/lib/service/worker/runtime/http/routes.d.ts +19 -0
  291. package/lib/service/worker/runtime/http/routes.js +12 -0
  292. package/lib/service/worker/runtime/method.d.ts +9 -0
  293. package/lib/service/worker/runtime/method.js +23 -0
  294. package/lib/service/worker/runtime/statusTrack.d.ts +14 -0
  295. package/lib/service/worker/runtime/statusTrack.js +37 -0
  296. package/lib/service/worker/runtime/typings.d.ts +172 -0
  297. package/lib/service/worker/runtime/typings.js +2 -0
  298. package/lib/service/worker/runtime/utils/compose.d.ts +5 -0
  299. package/lib/service/worker/runtime/utils/compose.js +11 -0
  300. package/lib/service/worker/runtime/utils/context.d.ts +2 -0
  301. package/lib/service/worker/runtime/utils/context.js +40 -0
  302. package/lib/service/worker/runtime/utils/diff.d.ts +12 -0
  303. package/lib/service/worker/runtime/utils/diff.js +21 -0
  304. package/lib/service/worker/runtime/utils/recorder.d.ts +8 -0
  305. package/lib/service/worker/runtime/utils/recorder.js +37 -0
  306. package/lib/service/worker/runtime/utils/toArray.d.ts +1 -0
  307. package/lib/service/worker/runtime/utils/toArray.js +3 -0
  308. package/lib/service/worker/runtime/utils/tokenBucket.d.ts +2 -0
  309. package/lib/service/worker/runtime/utils/tokenBucket.js +16 -0
  310. package/lib/tracing/LogEvents.d.ts +31 -0
  311. package/lib/tracing/LogEvents.js +3 -0
  312. package/lib/tracing/LogFields.d.ts +61 -0
  313. package/lib/tracing/LogFields.js +3 -0
  314. package/lib/tracing/Tags.d.ts +79 -0
  315. package/lib/tracing/Tags.js +7 -0
  316. package/lib/tracing/UserLandTracer.d.ts +27 -0
  317. package/lib/tracing/UserLandTracer.js +55 -0
  318. package/lib/tracing/errorReporting/ErrorReport.d.ts +31 -0
  319. package/lib/tracing/errorReporting/ErrorReport.js +61 -0
  320. package/lib/tracing/index.d.ts +9 -0
  321. package/lib/tracing/index.js +19 -0
  322. package/lib/tracing/spanReference/SpanReferenceTypes.d.ts +4 -0
  323. package/lib/tracing/spanReference/SpanReferenceTypes.js +7 -0
  324. package/lib/tracing/spanReference/createSpanReference.d.ts +3 -0
  325. package/lib/tracing/spanReference/createSpanReference.js +8 -0
  326. package/lib/tracing/utils.d.ts +13 -0
  327. package/lib/tracing/utils.js +40 -0
  328. package/lib/utils/MineWinsConflictsResolver.d.ts +28 -0
  329. package/lib/utils/MineWinsConflictsResolver.js +130 -0
  330. package/lib/utils/app.d.ts +23 -0
  331. package/lib/utils/app.js +48 -0
  332. package/lib/utils/appsStaleIfError.d.ts +11 -0
  333. package/lib/utils/appsStaleIfError.js +63 -0
  334. package/lib/utils/billingOptions.d.ts +36 -0
  335. package/lib/utils/billingOptions.js +9 -0
  336. package/lib/utils/binding.d.ts +13 -0
  337. package/lib/utils/binding.js +38 -0
  338. package/lib/utils/cancel.d.ts +3 -0
  339. package/lib/utils/cancel.js +12 -0
  340. package/lib/utils/domain.d.ts +1 -0
  341. package/lib/utils/domain.js +5 -0
  342. package/lib/utils/error.d.ts +8 -0
  343. package/lib/utils/error.js +94 -0
  344. package/lib/utils/index.d.ts +9 -0
  345. package/lib/utils/index.js +14 -0
  346. package/lib/utils/message.d.ts +25 -0
  347. package/lib/utils/message.js +23 -0
  348. package/lib/utils/renameBy.d.ts +1 -0
  349. package/lib/utils/renameBy.js +4 -0
  350. package/lib/utils/retry.d.ts +4 -0
  351. package/lib/utils/retry.js +32 -0
  352. package/lib/utils/status.d.ts +1 -0
  353. package/lib/utils/status.js +11 -0
  354. package/lib/utils/tenant.d.ts +5 -0
  355. package/lib/utils/tenant.js +6 -0
  356. package/lib/utils/throwOnGraphQLErrors.d.ts +2 -0
  357. package/lib/utils/throwOnGraphQLErrors.js +15 -0
  358. package/lib/utils/time.d.ts +31 -0
  359. package/lib/utils/time.js +118 -0
  360. package/package.json +127 -0
package/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # VTEX IO API Client for Node
2
+
3
+ This library enables developers to quickly integrate with the VTEX IO APIs and create full fledged node services using VTEX IO.
4
+
5
+ [![Build Status](https://travis-ci.org/vtex/node-vtex-api.svg?branch=master)](https://travis-ci.org/vtex/node-vtex-api)
6
+
7
+ ## Getting started
8
+
9
+ For a complete example on using `@vtex/api`, check out this app: https://github.com/vtex-apps/service-example
10
+
11
+ The most basic usage is to export a new `Service()` with your route handlers:
12
+
13
+ ```javascript
14
+ // Import global types
15
+ import './globals'
16
+
17
+ import { Service } from '@vtex/api'
18
+
19
+ import { clients } from './clients'
20
+ import example from './handlers/example'
21
+
22
+ // Export a service that defines route handlers and client options.
23
+ export default new Service({
24
+ clients,
25
+ routes: {
26
+ example,
27
+ },
28
+ })
29
+ ```
30
+
31
+ This allows you to define middlewares that receive a `Context` param which contains all IO Clients in the `clients` property:
32
+
33
+ ```javascript
34
+ export const example = async (ctx: Context, next: () => Promise<void>) => {
35
+ const {state: {code}, clients: {apps}} = ctx
36
+ console.log('Received code:', code)
37
+
38
+ const apps = await apps.listApps()
39
+
40
+ ctx.status = 200
41
+ ctx.body = apps
42
+ ctx.set('Cache-Control', 'private')
43
+
44
+ await next()
45
+ }
46
+ ```
47
+
48
+ `ctx.clients.apps` is an instance of `Apps`.
49
+
50
+ ## Development
51
+
52
+ - Install the dependencies: `yarn`
53
+ - Watch for changes: `yarn watch`
54
+
55
+ ### Development with IO clients
56
+
57
+ - Install the dependencies: `yarn`
58
+ - [Link](https://classic.yarnpkg.com/en/docs/cli/link/) this package: `yarn link`
59
+ - Watch for changes: `yarn watch`
60
+ - Move to the app that depends on the changes made on this package: `cd ../<your-app>/node`
61
+ - Link this package to your app's node_modules: `yarn link @vtex/api`
62
+
63
+ Now, when you get a workspace up and running for your app with `vtex link`, you'll have this package linked as well.
64
+
65
+ > When done developing, don't forget to unlink it from `<your-app>/node`: `yarn unlink @vtex/api`
@@ -0,0 +1,189 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "definitions": {
4
+ "BILLING_TYPE": {
5
+ "enum": [
6
+ "billable",
7
+ "free",
8
+ "sponsored"
9
+ ],
10
+ "type": "string"
11
+ },
12
+ "BillingOptions": {
13
+ "properties": {
14
+ "availableCountries": {
15
+ "items": {
16
+ "type": "string"
17
+ },
18
+ "type": "array"
19
+ },
20
+ "plans": {
21
+ "items": {
22
+ "$ref": "#/definitions/Plan"
23
+ },
24
+ "type": "array"
25
+ },
26
+ "support": {
27
+ "$ref": "#/definitions/Support"
28
+ },
29
+ "type": {
30
+ "$ref": "#/definitions/BILLING_TYPE"
31
+ }
32
+ },
33
+ "type": "object"
34
+ },
35
+ "Plan": {
36
+ "properties": {
37
+ "currency": {
38
+ "type": "string"
39
+ },
40
+ "id": {
41
+ "type": "string"
42
+ },
43
+ "price": {
44
+ "$ref": "#/definitions/Price"
45
+ }
46
+ },
47
+ "type": "object"
48
+ },
49
+ "Policy": {
50
+ "properties": {
51
+ "attrs": {
52
+ "additionalProperties": {
53
+ "type": "string"
54
+ },
55
+ "type": "object"
56
+ },
57
+ "name": {
58
+ "type": "string"
59
+ }
60
+ },
61
+ "type": "object"
62
+ },
63
+ "Price": {
64
+ "properties": {
65
+ "metrics": {
66
+ "items": {
67
+ "$ref": "#/definitions/PriceMetric"
68
+ },
69
+ "type": "array"
70
+ },
71
+ "subscription": {
72
+ "type": "number"
73
+ }
74
+ },
75
+ "type": "object"
76
+ },
77
+ "PriceMetric": {
78
+ "properties": {
79
+ "customUrl": {
80
+ "type": "string"
81
+ },
82
+ "id": {
83
+ "type": "string"
84
+ },
85
+ "ranges": {
86
+ "items": {
87
+ "$ref": "#/definitions/Range"
88
+ },
89
+ "type": "array"
90
+ }
91
+ },
92
+ "type": "object"
93
+ },
94
+ "Range": {
95
+ "properties": {
96
+ "exclusiveFrom": {
97
+ "type": "number"
98
+ },
99
+ "inclusiveTo": {
100
+ "type": "number"
101
+ },
102
+ "multiplier": {
103
+ "type": "number"
104
+ }
105
+ },
106
+ "type": "object"
107
+ },
108
+ "Support": {
109
+ "properties": {
110
+ "email": {
111
+ "type": "string"
112
+ },
113
+ "phone": {
114
+ "type": "string"
115
+ },
116
+ "url": {
117
+ "type": "string"
118
+ }
119
+ },
120
+ "type": "object"
121
+ }
122
+ },
123
+ "properties": {
124
+ "billingOptions": {
125
+ "$ref": "#/definitions/BillingOptions"
126
+ },
127
+ "builders": {
128
+ "additionalProperties": {
129
+ "type": "string"
130
+ },
131
+ "type": "object"
132
+ },
133
+ "categories": {
134
+ "items": {
135
+ "type": "string"
136
+ },
137
+ "type": "array"
138
+ },
139
+ "credentialType": {
140
+ "type": "string"
141
+ },
142
+ "dependencies": {
143
+ "additionalProperties": {
144
+ "type": "string"
145
+ },
146
+ "type": "object"
147
+ },
148
+ "description": {
149
+ "type": "string"
150
+ },
151
+ "mustUpdateAt": {
152
+ "type": "string"
153
+ },
154
+ "name": {
155
+ "type": "string"
156
+ },
157
+ "peerDependencies": {
158
+ "additionalProperties": {
159
+ "type": "string"
160
+ },
161
+ "type": "object"
162
+ },
163
+ "policies": {
164
+ "items": {
165
+ "$ref": "#/definitions/Policy"
166
+ },
167
+ "type": "array"
168
+ },
169
+ "registries": {
170
+ "items": {
171
+ "type": "string"
172
+ },
173
+ "type": "array"
174
+ },
175
+ "settingsSchema": {
176
+ },
177
+ "title": {
178
+ "type": "string"
179
+ },
180
+ "vendor": {
181
+ "type": "string"
182
+ },
183
+ "version": {
184
+ "type": "string"
185
+ }
186
+ },
187
+ "type": "object"
188
+ }
189
+
@@ -0,0 +1,28 @@
1
+ import { GraphQLError } from 'graphql';
2
+ import { HttpClient } from './HttpClient';
3
+ import { RequestConfig } from './typings';
4
+ interface QueryOptions<Variables extends object> {
5
+ query: string;
6
+ variables: Variables;
7
+ inflight?: boolean;
8
+ throwOnError?: boolean;
9
+ extensions?: Record<string, any>;
10
+ }
11
+ interface MutateOptions<Variables extends object> {
12
+ mutate: string;
13
+ variables: Variables;
14
+ throwOnError?: boolean;
15
+ }
16
+ export declare type Serializable = object | boolean | string | number;
17
+ export interface GraphQLResponse<T extends Serializable> {
18
+ data?: T;
19
+ errors?: GraphQLError[];
20
+ extensions?: Record<string, any>;
21
+ }
22
+ export declare class GraphQLClient {
23
+ private http;
24
+ constructor(http: HttpClient);
25
+ query: <Data extends Serializable, Variables extends object>({ query, variables, inflight, extensions, throwOnError }: QueryOptions<Variables>, config?: RequestConfig) => Promise<GraphQLResponse<Data>>;
26
+ mutate: <Data extends Serializable, Variables extends object>({ mutate, variables, throwOnError }: MutateOptions<Variables>, config?: RequestConfig) => Promise<GraphQLResponse<Data>>;
27
+ }
28
+ export {};
@@ -0,0 +1,30 @@
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 customGraphQLError_1 = __importDefault(require("../errors/customGraphQLError"));
7
+ const inflight_1 = require("./middlewares/inflight");
8
+ const throwOnGraphQLErrors = (message, response) => {
9
+ if (response && response.errors && response.errors.length > 0) {
10
+ throw new customGraphQLError_1.default(message, response.errors);
11
+ }
12
+ return response;
13
+ };
14
+ class GraphQLClient {
15
+ constructor(http) {
16
+ this.http = http;
17
+ this.query = ({ query, variables, inflight, extensions, throwOnError }, config = {}) => this.http.getWithBody(config.url || '', { query, variables, extensions }, {
18
+ inflightKey: inflight !== false ? inflight_1.inflightUrlWithQuery : undefined,
19
+ ...config,
20
+ })
21
+ .then(graphqlResponse => throwOnError === false
22
+ ? graphqlResponse
23
+ : throwOnGraphQLErrors(this.http.name, graphqlResponse));
24
+ this.mutate = ({ mutate, variables, throwOnError }, config = {}) => this.http.post(config.url || '', { query: mutate, variables }, config)
25
+ .then(graphqlResponse => throwOnError === false
26
+ ? graphqlResponse
27
+ : throwOnGraphQLErrors(this.http.name, graphqlResponse));
28
+ }
29
+ }
30
+ exports.GraphQLClient = GraphQLClient;
@@ -0,0 +1,29 @@
1
+ /// <reference types="node" />
2
+ import { AxiosResponse } from 'axios';
3
+ import { IncomingMessage } from 'http';
4
+ import { IOContext } from '../service/worker/runtime/typings';
5
+ import { InstanceOptions, IOResponse, RequestConfig } from './typings';
6
+ declare type ClientOptions = IOContext & Partial<InstanceOptions>;
7
+ export declare class HttpClient {
8
+ name: string;
9
+ private runMiddlewares;
10
+ constructor(opts: ClientOptions);
11
+ get: <T = any>(url: string, config?: RequestConfig) => Promise<T>;
12
+ getRaw: <T = any>(url: string, config?: RequestConfig) => Promise<IOResponse<T>>;
13
+ getWithBody: <T = any>(url: string, data?: any, config?: RequestConfig) => Promise<T>;
14
+ getBuffer: (url: string, config?: RequestConfig) => Promise<{
15
+ data: Buffer;
16
+ headers: any;
17
+ }>;
18
+ getStream: (url: string, config?: RequestConfig) => Promise<IncomingMessage>;
19
+ put: <T = void>(url: string, data?: any, config?: RequestConfig) => Promise<T>;
20
+ putRaw: <T = void>(url: string, data?: any, config?: RequestConfig) => Promise<IOResponse<T>>;
21
+ post: <T = void>(url: string, data?: any, config?: RequestConfig) => Promise<T>;
22
+ postRaw: <T = void>(url: string, data?: any, config?: RequestConfig) => Promise<IOResponse<T>>;
23
+ patch: <T = void>(url: string, data?: any, config?: RequestConfig) => Promise<T>;
24
+ head: (url: string, config?: RequestConfig) => Promise<IOResponse<void>>;
25
+ delete: <T = void>(url: string, config?: RequestConfig | undefined) => Promise<IOResponse<T>>;
26
+ protected request: (config: RequestConfig) => Promise<AxiosResponse<any>>;
27
+ private getConfig;
28
+ }
29
+ export {};
@@ -0,0 +1,130 @@
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 crypto_1 = require("crypto");
7
+ const koa_compose_1 = __importDefault(require("koa-compose"));
8
+ const p_limit_1 = __importDefault(require("p-limit"));
9
+ const constants_1 = require("../constants");
10
+ const binding_1 = require("../utils/binding");
11
+ const tenant_1 = require("../utils/tenant");
12
+ const cache_1 = require("./middlewares/cache");
13
+ const cancellationToken_1 = require("./middlewares/cancellationToken");
14
+ const inflight_1 = require("./middlewares/inflight");
15
+ const memoization_1 = require("./middlewares/memoization");
16
+ const metrics_1 = require("./middlewares/metrics");
17
+ const notFound_1 = require("./middlewares/notFound");
18
+ const recorder_1 = require("./middlewares/recorder");
19
+ const request_1 = require("./middlewares/request");
20
+ const tracing_1 = require("./middlewares/tracing");
21
+ const DEFAULT_TIMEOUT_MS = 1000;
22
+ const noTransforms = [(data) => data];
23
+ class HttpClient {
24
+ constructor(opts) {
25
+ this.get = (url, config = {}) => {
26
+ const cacheableConfig = this.getConfig(url, config);
27
+ return this.request(cacheableConfig).then(response => response.data);
28
+ };
29
+ this.getRaw = (url, config = {}) => {
30
+ const cacheableConfig = this.getConfig(url, config);
31
+ return this.request(cacheableConfig);
32
+ };
33
+ this.getWithBody = (url, data, config = {}) => {
34
+ const bodyHash = crypto_1.createHash('md5').update(JSON.stringify(data)).digest('hex');
35
+ const cacheableConfig = this.getConfig(url, {
36
+ ...config,
37
+ data,
38
+ params: {
39
+ ...config.params,
40
+ [constants_1.BODY_HASH]: bodyHash,
41
+ },
42
+ });
43
+ return this.request(cacheableConfig).then(response => response.data);
44
+ };
45
+ this.getBuffer = (url, config = {}) => {
46
+ const bufferConfig = { cacheable: cache_1.CacheType.Disk, ...config, url, responseType: 'arraybuffer', transformResponse: noTransforms };
47
+ return this.request(bufferConfig);
48
+ };
49
+ this.getStream = (url, config = {}) => {
50
+ const streamConfig = { ...config, url, responseType: 'stream', transformResponse: noTransforms };
51
+ return this.request(streamConfig).then(response => response.data);
52
+ };
53
+ this.put = (url, data, config = {}) => {
54
+ const putConfig = { ...config, url, data, method: 'put' };
55
+ return this.request(putConfig).then(response => response.data);
56
+ };
57
+ this.putRaw = (url, data, config = {}) => {
58
+ const putConfig = { ...config, url, data, method: 'put' };
59
+ return this.request(putConfig);
60
+ };
61
+ this.post = (url, data, config = {}) => {
62
+ const postConfig = { ...config, url, data, method: 'post' };
63
+ return this.request(postConfig).then(response => response.data);
64
+ };
65
+ this.postRaw = (url, data, config = {}) => {
66
+ const postConfig = { ...config, url, data, method: 'post' };
67
+ return this.request(postConfig);
68
+ };
69
+ this.patch = (url, data, config = {}) => {
70
+ const patchConfig = { ...config, url, data, method: 'patch' };
71
+ return this.request(patchConfig).then(response => response.data);
72
+ };
73
+ this.head = (url, config = {}) => {
74
+ const headConfig = { ...config, url, method: 'head' };
75
+ return this.request(headConfig);
76
+ };
77
+ this.delete = (url, config) => {
78
+ const deleteConfig = { ...config, url, method: 'delete' };
79
+ return this.request(deleteConfig);
80
+ };
81
+ this.request = async (config) => {
82
+ const context = { config };
83
+ await this.runMiddlewares(context);
84
+ return context.response;
85
+ };
86
+ this.getConfig = (url, config = {}) => ({
87
+ cacheable: cache_1.CacheType.Memory,
88
+ memoizable: true,
89
+ ...config,
90
+ url,
91
+ });
92
+ const { baseURL, authToken, authType, memoryCache, diskCache, locale, name, metrics, product, serverTiming, recorder, userAgent, timeout = DEFAULT_TIMEOUT_MS, segmentToken, sessionToken, retries, concurrency, headers: defaultHeaders, host, params, operationId, tenant, binding, verbose, cancellation, exponentialTimeoutCoefficient, initialBackoffDelay, exponentialBackoffCoefficient, httpsAgent, tracer, logger, } = opts;
93
+ this.name = name || baseURL || 'unknown';
94
+ const limit = concurrency && concurrency > 0 && p_limit_1.default(concurrency) || undefined;
95
+ const headers = {
96
+ ...defaultHeaders,
97
+ 'Accept-Encoding': 'gzip',
98
+ 'User-Agent': userAgent,
99
+ ...host ? { [constants_1.FORWARDED_HOST_HEADER]: host } : null,
100
+ ...tenant ? { [constants_1.TENANT_HEADER]: tenant_1.formatTenantHeaderValue(tenant) } : null,
101
+ ...binding ? { [constants_1.BINDING_HEADER]: binding_1.formatBindingHeaderValue(binding) } : null,
102
+ ...locale ? { [constants_1.LOCALE_HEADER]: locale } : null,
103
+ ...operationId ? { 'x-vtex-operation-id': operationId } : null,
104
+ ...product ? { [constants_1.PRODUCT_HEADER]: product } : null,
105
+ ...segmentToken ? { [constants_1.SEGMENT_HEADER]: segmentToken } : null,
106
+ ...sessionToken ? { [constants_1.SESSION_HEADER]: sessionToken } : null,
107
+ };
108
+ if (authType && authToken) {
109
+ headers['Authorization'] = `${authType} ${authToken}`; // tslint:disable-line
110
+ }
111
+ const memoizedCache = new Map();
112
+ this.runMiddlewares = koa_compose_1.default([
113
+ tracing_1.createHttpClientTracingMiddleware({ tracer, logger, clientName: this.name, hasDiskCacheMiddleware: !!diskCache, hasMemoryCacheMiddleware: !!memoryCache }),
114
+ ...(opts.middlewares || []),
115
+ request_1.defaultsMiddleware({ baseURL, rawHeaders: headers, params, timeout, retries, verbose, exponentialTimeoutCoefficient, initialBackoffDelay, exponentialBackoffCoefficient, httpsAgent }),
116
+ metrics_1.metricsMiddleware({ metrics, serverTiming, name }),
117
+ memoization_1.memoizationMiddleware({ memoizedCache }),
118
+ ...recorder ? [recorder_1.recorderMiddleware(recorder)] : [],
119
+ cancellationToken_1.cancellationToken(cancellation),
120
+ inflight_1.singleFlightMiddleware,
121
+ notFound_1.acceptNotFoundMiddleware,
122
+ ...memoryCache ? [cache_1.cacheMiddleware({ type: cache_1.CacheType.Memory, storage: memoryCache })] : [],
123
+ ...diskCache ? [cache_1.cacheMiddleware({ type: cache_1.CacheType.Disk, storage: diskCache })] : [],
124
+ notFound_1.notFoundFallbackMiddleware,
125
+ request_1.routerCacheMiddleware,
126
+ request_1.requestMiddleware(limit),
127
+ ]);
128
+ }
129
+ }
130
+ exports.HttpClient = HttpClient;