@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
@@ -0,0 +1,7 @@
1
+ import { GraphQLField } from 'graphql';
2
+ import { SchemaDirectiveVisitor } from 'graphql-tools';
3
+ import { ServiceContext } from '../../../typings';
4
+ export declare class TranslatableV2 extends SchemaDirectiveVisitor {
5
+ visitFieldDefinition(field: GraphQLField<any, ServiceContext>): void;
6
+ }
7
+ export declare const translatableV2DirectiveTypeDefs = "\ndirective @translatableV2(\n behavior: String\n withAppsMetaInfo: Boolean\n) on FIELD_DEFINITION\n";
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphql_1 = require("graphql");
4
+ const graphql_tools_1 = require("graphql-tools");
5
+ const translations_1 = require("../../utils/translations");
6
+ const messagesLoaderV2_1 = require("../messagesLoaderV2");
7
+ class TranslatableV2 extends graphql_tools_1.SchemaDirectiveVisitor {
8
+ visitFieldDefinition(field) {
9
+ const { resolve = graphql_1.defaultFieldResolver } = field;
10
+ const { behavior = 'FULL', withAppsMetaInfo = false } = this.args;
11
+ field.resolve = async (root, args, ctx, info) => {
12
+ var _a;
13
+ if (!((_a = ctx.loaders) === null || _a === void 0 ? void 0 : _a.messagesV2)) {
14
+ const { vtex: { locale: to } } = ctx;
15
+ if (to == null) {
16
+ throw new Error('@translatableV2 directive needs the locale variable available in IOContext. You can do this by either setting \`ctx.vtex.locale\` directly or calling this app with \`x-vtex-locale\` header');
17
+ }
18
+ const dependencies = withAppsMetaInfo ? await ctx.clients.apps.getAppsMetaInfos() : undefined;
19
+ ctx.loaders = {
20
+ ...ctx.loaders,
21
+ messagesV2: messagesLoaderV2_1.createMessagesLoader(ctx.clients, to, dependencies),
22
+ };
23
+ }
24
+ const response = await resolve(root, args, ctx, info);
25
+ const { vtex, loaders: { messagesV2 } } = ctx;
26
+ const handler = translations_1.handleSingleString(vtex, messagesV2, behavior, 'translatableV2');
27
+ return Array.isArray(response)
28
+ ? Promise.all(response.map(handler))
29
+ : handler(response);
30
+ };
31
+ }
32
+ }
33
+ exports.TranslatableV2 = TranslatableV2;
34
+ exports.translatableV2DirectiveTypeDefs = `
35
+ directive @translatableV2(
36
+ behavior: String
37
+ withAppsMetaInfo: Boolean
38
+ ) on FIELD_DEFINITION
39
+ `;
@@ -0,0 +1,7 @@
1
+ import { GraphQLField } from 'graphql';
2
+ import { SchemaDirectiveVisitor } from 'graphql-tools';
3
+ import { ServiceContext } from '../../../typings';
4
+ export declare class TranslateTo extends SchemaDirectiveVisitor {
5
+ visitFieldDefinition(field: GraphQLField<any, ServiceContext>): void;
6
+ }
7
+ export declare const translateToDirectiveTypeDefs = "\ndirective @translateTo(\n language: String!\n behavior: String\n) on FIELD_DEFINITION\n";
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphql_1 = require("graphql");
4
+ const graphql_tools_1 = require("graphql-tools");
5
+ const translations_1 = require("../../utils/translations");
6
+ const messagesLoaderV2_1 = require("../messagesLoaderV2");
7
+ class TranslateTo extends graphql_tools_1.SchemaDirectiveVisitor {
8
+ visitFieldDefinition(field) {
9
+ const { resolve = graphql_1.defaultFieldResolver } = field;
10
+ const { language, behavior = 'FULL' } = this.args;
11
+ field.resolve = async (root, args, ctx, info) => {
12
+ var _a;
13
+ if (!((_a = ctx.loaders) === null || _a === void 0 ? void 0 : _a.immutableMessagesV2)) {
14
+ const dependencies = await ctx.clients.apps.getAppsMetaInfos();
15
+ ctx.loaders = {
16
+ ...ctx.loaders,
17
+ immutableMessagesV2: messagesLoaderV2_1.createMessagesLoader(ctx.clients, language, dependencies),
18
+ };
19
+ }
20
+ const response = (await resolve(root, args, ctx, info));
21
+ const { vtex, loaders: { immutableMessagesV2 }, } = ctx;
22
+ const handler = translations_1.handleSingleString(vtex, immutableMessagesV2, behavior, 'translateTo');
23
+ return Array.isArray(response) ? Promise.all(response.map(handler)) : handler(response);
24
+ };
25
+ }
26
+ }
27
+ exports.TranslateTo = TranslateTo;
28
+ exports.translateToDirectiveTypeDefs = `
29
+ directive @translateTo(
30
+ language: String!
31
+ behavior: String
32
+ ) on FIELD_DEFINITION
33
+ `;
@@ -0,0 +1,22 @@
1
+ import { Auth } from './Auth';
2
+ import { CacheControl } from './CacheControl';
3
+ import { Deprecated } from './Deprecated';
4
+ import { Metric } from './Metric';
5
+ import { SanitizeDirective } from './Sanitize';
6
+ import { SettingsDirective } from './Settings';
7
+ import { SmartCacheDirective } from './SmartCacheDirective';
8
+ import { TranslatableV2 } from './TranslatableV2';
9
+ import { TranslateTo } from './TranslateTo';
10
+ export { parseTranslatableStringV2, formatTranslatableStringV2 } from '../../utils/translations';
11
+ export declare const nativeSchemaDirectives: {
12
+ auth: typeof Auth;
13
+ cacheControl: typeof CacheControl;
14
+ deprecated: typeof Deprecated;
15
+ metric: typeof Metric;
16
+ sanitize: typeof SanitizeDirective;
17
+ settings: typeof SettingsDirective;
18
+ smartcache: typeof SmartCacheDirective;
19
+ translatableV2: typeof TranslatableV2;
20
+ translateTo: typeof TranslateTo;
21
+ };
22
+ export declare const nativeSchemaDirectivesTypeDefs: string;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Auth_1 = require("./Auth");
4
+ const CacheControl_1 = require("./CacheControl");
5
+ const Deprecated_1 = require("./Deprecated");
6
+ const Metric_1 = require("./Metric");
7
+ const Sanitize_1 = require("./Sanitize");
8
+ const Settings_1 = require("./Settings");
9
+ const SmartCacheDirective_1 = require("./SmartCacheDirective");
10
+ const TranslatableV2_1 = require("./TranslatableV2");
11
+ const TranslateTo_1 = require("./TranslateTo");
12
+ var translations_1 = require("../../utils/translations");
13
+ exports.parseTranslatableStringV2 = translations_1.parseTranslatableStringV2;
14
+ exports.formatTranslatableStringV2 = translations_1.formatTranslatableStringV2;
15
+ exports.nativeSchemaDirectives = {
16
+ auth: Auth_1.Auth,
17
+ cacheControl: CacheControl_1.CacheControl,
18
+ deprecated: Deprecated_1.Deprecated,
19
+ metric: Metric_1.Metric,
20
+ sanitize: Sanitize_1.SanitizeDirective,
21
+ settings: Settings_1.SettingsDirective,
22
+ smartcache: SmartCacheDirective_1.SmartCacheDirective,
23
+ translatableV2: TranslatableV2_1.TranslatableV2,
24
+ translateTo: TranslateTo_1.TranslateTo,
25
+ };
26
+ exports.nativeSchemaDirectivesTypeDefs = [
27
+ Auth_1.authDirectiveTypeDefs,
28
+ CacheControl_1.cacheControlDirectiveTypeDefs,
29
+ Deprecated_1.deprecatedDirectiveTypeDefs,
30
+ Metric_1.metricDirectiveTypeDefs,
31
+ Sanitize_1.sanitizeDirectiveTypeDefs,
32
+ Settings_1.settingsDirectiveTypeDefs,
33
+ SmartCacheDirective_1.smartCacheDirectiveTypeDefs,
34
+ TranslatableV2_1.translatableV2DirectiveTypeDefs,
35
+ TranslateTo_1.translateToDirectiveTypeDefs,
36
+ ].join('\n\n');
@@ -0,0 +1,7 @@
1
+ import { GraphQLScalarType } from 'graphql';
2
+ export declare const nativeResolvers: {
3
+ IOSanitizedString: import("./sanitizedString").IOSanitizedStringType;
4
+ IOUpload: GraphQLScalarType;
5
+ Upload: GraphQLScalarType;
6
+ };
7
+ export declare const nativeTypeDefs: (metaData: Record<string, boolean>) => string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphql_upload_1 = require("graphql-upload");
4
+ const ramda_1 = require("ramda");
5
+ const ioUpload_1 = require("./ioUpload");
6
+ const sanitizedString_1 = require("./sanitizedString");
7
+ exports.nativeResolvers = {
8
+ 'IOSanitizedString': sanitizedString_1.resolvers,
9
+ 'IOUpload': ioUpload_1.resolvers,
10
+ 'Upload': graphql_upload_1.GraphQLUpload,
11
+ };
12
+ exports.nativeTypeDefs = (metaData) => ramda_1.reduce((acc, scalar) => !metaData[scalar] ? `${acc}\nscalar ${scalar}\n` : acc, '', ramda_1.keys(exports.nativeResolvers));
@@ -0,0 +1,3 @@
1
+ import { GraphQLScalarType } from 'graphql';
2
+ export declare const scalar = "IOUpload";
3
+ export declare const resolvers: GraphQLScalarType;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphql_1 = require("graphql");
4
+ const name = 'IOUpload';
5
+ exports.scalar = name;
6
+ exports.resolvers = new graphql_1.GraphQLScalarType({
7
+ description: 'The `IOUpload` scalar type represents a file upload.',
8
+ name,
9
+ parseValue: (value) => value,
10
+ parseLiteral() {
11
+ throw new Error('‘IOUpload’ scalar literal unsupported.');
12
+ },
13
+ serialize() {
14
+ throw new Error('‘IOUpload’ scalar serialization unsupported.');
15
+ },
16
+ });
@@ -0,0 +1,10 @@
1
+ import { GraphQLScalarType } from 'graphql';
2
+ export declare const scalar = "IOSanitizedString";
3
+ export interface SanitizeOptions {
4
+ allowHTMLTags?: boolean;
5
+ stripIgnoreTag?: boolean;
6
+ }
7
+ export declare class IOSanitizedStringType extends GraphQLScalarType {
8
+ constructor(options?: SanitizeOptions);
9
+ }
10
+ export declare const resolvers: IOSanitizedStringType;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const graphql_1 = require("graphql");
4
+ const xss_1 = require("xss");
5
+ const defaultName = 'IOSanitizedString';
6
+ exports.scalar = defaultName;
7
+ const noop = (html) => html;
8
+ const serialize = (input, options) => {
9
+ return xss_1.filterXSS(input, options);
10
+ };
11
+ const parseValue = (value, options) => {
12
+ return xss_1.filterXSS(value, options);
13
+ };
14
+ class IOSanitizedStringType extends graphql_1.GraphQLScalarType {
15
+ constructor(options) {
16
+ const allowHTMLTags = options && options.allowHTMLTags;
17
+ const stripIgnoreTag = !options || options.stripIgnoreTag !== false;
18
+ const xssOptions = {
19
+ stripIgnoreTag,
20
+ ...!allowHTMLTags && { whiteList: [] },
21
+ ...stripIgnoreTag && { escapeHtml: noop },
22
+ };
23
+ super({
24
+ name: options ? `Custom${defaultName}` : defaultName,
25
+ parseLiteral: ast => {
26
+ switch (ast.kind) {
27
+ case graphql_1.Kind.STRING:
28
+ return parseValue(ast.value, xssOptions);
29
+ default:
30
+ return null;
31
+ }
32
+ },
33
+ parseValue: value => parseValue(value, xssOptions),
34
+ serialize: value => serialize(value, xssOptions),
35
+ });
36
+ }
37
+ }
38
+ exports.IOSanitizedStringType = IOSanitizedStringType;
39
+ exports.resolvers = new IOSanitizedStringType();
@@ -0,0 +1,31 @@
1
+ import { DocumentNode, execute, GraphQLSchema } from 'graphql';
2
+ import { IOClients } from '../../../../clients/IOClients';
3
+ import { ParamsContext, RecorderState, ServiceContext } from '../typings';
4
+ export interface Query {
5
+ variables?: Record<string, any>;
6
+ operationName?: string;
7
+ document: DocumentNode;
8
+ }
9
+ declare type TypeFromPromise<T> = T extends Promise<infer U> ? U : T;
10
+ export declare type GraphQLResponse = TypeFromPromise<ReturnType<typeof execute>>;
11
+ export interface GraphQLCacheControl {
12
+ maxAge: number;
13
+ scope: 'private' | 'public' | 'segment';
14
+ noCache: boolean;
15
+ noStore: boolean;
16
+ }
17
+ export interface GraphQLContext extends ParamsContext {
18
+ graphql: {
19
+ query?: Query;
20
+ graphqlResponse?: GraphQLResponse;
21
+ status: 'success' | 'error';
22
+ cacheControl: GraphQLCacheControl;
23
+ };
24
+ }
25
+ export declare type GraphQLServiceContext = ServiceContext<IOClients, RecorderState, GraphQLContext>;
26
+ export interface ExecutableSchema {
27
+ schema: GraphQLSchema;
28
+ hasProvider: boolean;
29
+ provider?: string;
30
+ }
31
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export declare const cacheControlHTTP: (ctx: import("../../typings").ServiceContext<import("../../../../..").IOClients, import("../../typings").RecorderState, import("../typings").GraphQLContext>) => string;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const domain_1 = require("../../../../../utils/domain");
4
+ const PRIVATE_ROUTE_REGEX = /_v\/graphql\/private\/v*/;
5
+ const linked = !!process.env.VTEX_APP_LINK;
6
+ const isPrivateRoute = ({ request: { headers } }) => PRIVATE_ROUTE_REGEX.test(headers['x-forwarded-path'] || '');
7
+ const publicRegExp = (endpoint) => new RegExp(`.*${endpoint.replace('.', '\\.')}.*`);
8
+ const isPublicEndpoint = ({ request: { headers } }) => {
9
+ const host = headers['x-forwarded-host'];
10
+ if (headers.origin || !host) {
11
+ return false;
12
+ }
13
+ return domain_1.PUBLIC_DOMAINS.some(endpoint => publicRegExp(endpoint).test(host));
14
+ };
15
+ exports.cacheControlHTTP = (ctx) => {
16
+ const { graphql: { cacheControl: { maxAge, scope: scopeHint, noCache: noCacheHint, noStore: noStoreHint, }, }, vtex: { production, }, } = ctx;
17
+ const finalHeader = [];
18
+ const noCache = noCacheHint || !production || isPublicEndpoint(ctx);
19
+ if (noCache) {
20
+ finalHeader.push('no-cache');
21
+ }
22
+ const noStore = noStoreHint || linked;
23
+ if (noStore) {
24
+ finalHeader.push('no-store');
25
+ }
26
+ if (!noCache && !noStore) {
27
+ const scope = scopeHint === 'private' || isPrivateRoute(ctx) ? 'private' : 'public';
28
+ finalHeader.push(scope);
29
+ finalHeader.push(`max-age=${maxAge}`);
30
+ }
31
+ return finalHeader.join(',');
32
+ };
@@ -0,0 +1 @@
1
+ export declare const createFormatError: (ctx: import("../../typings").ServiceContext<import("../../../../..").IOClients, import("../../typings").RecorderState, import("../typings").GraphQLContext>) => (error: any) => any;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ramda_1 = require("ramda");
4
+ const error_1 = require("../../../../../utils/error");
5
+ const ERROR_FIELD_WHITELIST = ['message', 'path', 'stack', 'extensions', 'statusCode', 'name', 'headers', 'originalError', 'code'];
6
+ const QUERY_FIELDS = ['query', 'operationName', 'variables'];
7
+ const trimVariables = (variables) => {
8
+ if (variables) {
9
+ const stringifiedVariables = JSON.stringify(variables);
10
+ return stringifiedVariables.length <= 1024
11
+ ? stringifiedVariables
12
+ : `${stringifiedVariables.slice(0, 992)} [Truncated: variables too long]`;
13
+ }
14
+ return '';
15
+ };
16
+ const detailsFromCtx = (ctx) => {
17
+ const { headers: { 'x-forwarded-host': forwardedHost, 'x-forwarded-proto': forwardedProto, 'x-vtex-platform': platform, }, vtex: { operationId, requestId, }, } = ctx;
18
+ const queryRest = ramda_1.pick(QUERY_FIELDS, ctx.graphql.query || {});
19
+ const variables = ctx.request.is('multipart/form-data')
20
+ ? '[GraphQL Upload]'
21
+ : trimVariables(queryRest.variables);
22
+ const query = {
23
+ ...queryRest,
24
+ variables,
25
+ };
26
+ return {
27
+ forwardedHost,
28
+ forwardedProto,
29
+ operationId,
30
+ platform,
31
+ query,
32
+ requestId,
33
+ };
34
+ };
35
+ const formatError = (error, details) => {
36
+ const formattedError = ramda_1.pick(ERROR_FIELD_WHITELIST, error);
37
+ if (!formattedError.extensions) {
38
+ formattedError.extensions = {
39
+ code: 'INTERNAL_SERVER_ERROR',
40
+ };
41
+ }
42
+ if (formattedError.originalError) {
43
+ formattedError.originalError = error_1.cleanError(formattedError.originalError);
44
+ if (formattedError.stack === formattedError.originalError.stack) {
45
+ delete formattedError.originalError.stack;
46
+ }
47
+ if (!formattedError.extensions.exception) {
48
+ formattedError.extensions.exception = {
49
+ message: formattedError.originalError.message,
50
+ name: formattedError.originalError.name,
51
+ ...ramda_1.omit(error_1.SENSITIVE_EXCEPTION_FIELDS, formattedError.originalError),
52
+ sensitive: ramda_1.pick(error_1.SENSITIVE_EXCEPTION_FIELDS, formattedError.originalError),
53
+ };
54
+ }
55
+ else {
56
+ const mergedException = { ...formattedError.originalError,
57
+ ...formattedError.extensions.exception,
58
+ };
59
+ const extendedException = {
60
+ message: formattedError.originalError.message,
61
+ name: formattedError.originalError.name,
62
+ ...ramda_1.omit(error_1.SENSITIVE_EXCEPTION_FIELDS, mergedException),
63
+ sensitive: ramda_1.pick(error_1.SENSITIVE_EXCEPTION_FIELDS, mergedException),
64
+ };
65
+ formattedError.extensions.exception = error_1.cleanError(extendedException);
66
+ }
67
+ // Make originalError not enumerable to prevent duplicated log and response information
68
+ Object.defineProperty(formattedError, 'originalError', { enumerable: false });
69
+ }
70
+ Object.assign(formattedError, details);
71
+ return formattedError;
72
+ };
73
+ exports.createFormatError = (ctx) => {
74
+ const details = detailsFromCtx(ctx);
75
+ return (error) => formatError(error, details);
76
+ };
@@ -0,0 +1 @@
1
+ export declare const generatePathName: (rpath: [string | number]) => string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ramda_1 = require("ramda");
4
+ exports.generatePathName = (rpath) => {
5
+ const pathFieldNames = ramda_1.filter(value => typeof value === 'string', rpath);
6
+ return pathFieldNames.join('.');
7
+ };
@@ -0,0 +1,14 @@
1
+ import { Behavior } from '../../../../../clients';
2
+ import { IOContext } from '../../typings';
3
+ export declare const CONTEXT_REGEX: RegExp;
4
+ export declare const FROM_REGEX: RegExp;
5
+ export declare const CONTENT_REGEX: RegExp;
6
+ export interface TranslatableMessageV2 {
7
+ from?: string;
8
+ content: string;
9
+ context?: string;
10
+ }
11
+ export declare type TranslationDirectiveType = 'translatableV2' | 'translateTo';
12
+ export declare const parseTranslatableStringV2: (rawMessage: string) => TranslatableMessageV2;
13
+ export declare const formatTranslatableStringV2: ({ from, content, context }: TranslatableMessageV2) => string;
14
+ export declare const handleSingleString: (ctx: IOContext, loader: import("dataloader")<import("../../../../../clients").Message, string>, behavior: Behavior, directiveName: TranslationDirectiveType) => (rawMessage: string | null) => Promise<string | null>;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONTEXT_REGEX = /\(\(\((?<context>(.)*)\)\)\)/;
4
+ exports.FROM_REGEX = /\<\<\<(?<from>(.)*)\>\>\>/;
5
+ exports.CONTENT_REGEX = /\(\(\((?<context>(.)*)\)\)\)|\<\<\<(?<from>(.)*)\>\>\>/g;
6
+ exports.parseTranslatableStringV2 = (rawMessage) => {
7
+ var _a, _b, _c, _d;
8
+ const context = (_b = (_a = rawMessage.match(exports.CONTEXT_REGEX)) === null || _a === void 0 ? void 0 : _a.groups) === null || _b === void 0 ? void 0 : _b.context;
9
+ const from = (_d = (_c = rawMessage.match(exports.FROM_REGEX)) === null || _c === void 0 ? void 0 : _c.groups) === null || _d === void 0 ? void 0 : _d.from;
10
+ const content = rawMessage.replace(exports.CONTENT_REGEX, '');
11
+ return {
12
+ content: content === null || content === void 0 ? void 0 : content.trim(),
13
+ context: context === null || context === void 0 ? void 0 : context.trim(),
14
+ from: from === null || from === void 0 ? void 0 : from.trim(),
15
+ };
16
+ };
17
+ exports.formatTranslatableStringV2 = ({ from, content, context }) => `${content} ${context ? `(((${context})))` : ''} ${from ? `<<<${from}>>>` : ''}`;
18
+ exports.handleSingleString = (ctx, loader, behavior, directiveName) => async (rawMessage) => {
19
+ // Messages only know how to process non empty strings.
20
+ if (rawMessage == null) {
21
+ return rawMessage;
22
+ }
23
+ const { content, context, from: maybeFrom } = exports.parseTranslatableStringV2(rawMessage);
24
+ const { binding, tenant } = ctx;
25
+ if (content == null) {
26
+ throw new Error(`@${directiveName} directive needs a content to translate, but received ${JSON.stringify(rawMessage)}`);
27
+ }
28
+ const from = maybeFrom || (binding === null || binding === void 0 ? void 0 : binding.locale) || (tenant === null || tenant === void 0 ? void 0 : tenant.locale);
29
+ if (from == null) {
30
+ throw new Error(`@${directiveName} directive needs a source language to translate from. You can do this by either setting ${'`ctx.vtex.tenant`'} variable, call this app with the header ${'`x-vtex-tenant`'} or format the string with the ${'`formatTranslatableStringV2`'} function with the ${'`from`'} option set`);
31
+ }
32
+ return loader.load({
33
+ behavior,
34
+ content,
35
+ context,
36
+ from,
37
+ });
38
+ };