diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bf4b8f9b..72fe9f6e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [6.46.0-beta.0] - 2023-03-07 + +## [6.46.0-beta] - 2023-03-07 + ## [6.45.15] - 2023-02-01 ### Changed - Removed unnecessary worker signal logs @@ -1757,7 +1761,9 @@ instead - `HttpClient` now adds `'Accept-Encoding': 'gzip'` header by default. -[Unreleased]: https://github.com/vtex/node-vtex-api/compare/v6.45.15...HEAD +[Unreleased]: https://github.com/vtex/node-vtex-api/compare/v6.46.0-beta.0...HEAD +[6.46.0-beta.0]: https://github.com/vtex/node-vtex-api/compare/v6.46.0-beta...v6.46.0-beta.0 +[6.46.0-beta]: https://github.com/vtex/node-vtex-api/compare/v6.45.15...v6.46.0-beta [6.45.15]: https://github.com/vtex/node-vtex-api/compare/v6.45.14...v6.45.15 [6.45.14]: https://github.com/vtex/node-vtex-api/compare/v6.45.13...v6.45.14 [6.45.13]: https://github.com/vtex/node-vtex-api/compare/v6.45.12...v6.45.13 diff --git a/package.json b/package.json index d0a381602..6088d244f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vtex/api", - "version": "6.45.15", + "version": "6.46.0-beta.0", "description": "VTEX I/O API client", "main": "lib/index.js", "typings": "lib/index.d.ts", @@ -54,7 +54,7 @@ "agentkeepalive": "^4.0.2", "apollo-server-errors": "^2.2.1", "archiver": "^3.0.0", - "axios": "^0.21.1", + "axios": "0.27.2", "axios-retry": "^3.1.2", "bluebird": "^3.5.4", "chalk": "^2.4.2", diff --git a/src/HttpClient/middlewares/cache.ts b/src/HttpClient/middlewares/cache.ts index 6af403290..80d58d8ae 100644 --- a/src/HttpClient/middlewares/cache.ts +++ b/src/HttpClient/middlewares/cache.ts @@ -12,7 +12,7 @@ const cacheableStatusCodes = [200, 203, 204, 206, 300, 301, 404, 405, 410, 414, export const cacheKey = (config: AxiosRequestConfig) => { const {baseURL = '', url = '', params, headers} = config - const locale = headers[LOCALE_HEADER] + const locale = headers?.[LOCALE_HEADER] const encodedBaseURL = baseURL.replace(/\//g, '\\') const encodedURL = url.replace(/\//g, '\\') @@ -93,7 +93,7 @@ export const cacheMiddleware = ({ type, storage }: CacheOptions) => { const span = ctx.tracing!.rootSpan const key = cacheKey(ctx.config) - const segmentToken = ctx.config.headers[SEGMENT_HEADER] + const segmentToken = ctx.config.headers?.[SEGMENT_HEADER] const keyWithSegment = key + segmentToken span.log({ @@ -139,6 +139,9 @@ export const cacheMiddleware = ({ type, storage }: CacheOptions) => { span.setTag(CACHE_RESULT_TAG, CacheResult.STALE) const validateStatus = addNotModified(ctx.config.validateStatus!) if (cachedEtag && validateStatus(response.status as number)) { + if (!ctx.config.headers) { + ctx.config.headers = {} + } ctx.config.headers['if-none-match'] = cachedEtag ctx.config.validateStatus = validateStatus } @@ -193,7 +196,7 @@ export const cacheMiddleware = ({ type, storage }: CacheOptions) => { const currentAge = revalidated ? 0 : age const varySegment = ctx.response.headers.vary && ctx.response.headers.vary.includes(SEGMENT_HEADER) const setKey = varySegment ? keyWithSegment : key - const responseEncoding = configResponseEncoding || (responseType === 'arraybuffer' ? 'base64' : undefined) + const responseEncoding = (configResponseEncoding || (responseType === 'arraybuffer' ? 'base64' : undefined)) as BufferEncoding const cacheableData = type === CacheType.Disk && responseType === 'arraybuffer' ? (data as Buffer).toString(responseEncoding) : data diff --git a/src/HttpClient/middlewares/request/index.ts b/src/HttpClient/middlewares/request/index.ts index 5c874b41a..547cc297e 100644 --- a/src/HttpClient/middlewares/request/index.ts +++ b/src/HttpClient/middlewares/request/index.ts @@ -47,7 +47,7 @@ export const defaultsMiddleware = ({ baseURL, rawHeaders, params, timeout, retri ...ctx.config, headers: { ...headers, - ...renameBy(toLower, ctx.config.headers), + ...renameBy(toLower, ctx.config.headers!), }, params: { ...params, diff --git a/src/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.ts b/src/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.ts index e59497744..83fff08f4 100644 --- a/src/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.ts +++ b/src/HttpClient/middlewares/request/setupAxios/interceptors/tracing/spanSetup.ts @@ -12,7 +12,7 @@ export const injectRequestInfoOnSpan = (span: Span, http: AxiosInstance, config: [OpentracingTags.HTTP_URL]: buildFullPath(config.baseURL, http.getUri(config)), }) - span.log({ 'request-headers': cloneAndSanitizeHeaders(config.headers) }) + span.log({ 'request-headers': cloneAndSanitizeHeaders(config.headers!) }) } // Response may be undefined in case of client timeout, invalid URL, ... diff --git a/src/HttpClient/typings.ts b/src/HttpClient/typings.ts index 2ff13464d..c1b4e2229 100644 --- a/src/HttpClient/typings.ts +++ b/src/HttpClient/typings.ts @@ -48,7 +48,6 @@ export interface RequestConfig extends AxiosRequestConfig, RequestTracingConfig memoizeable?: boolean inflightKey?: InflightKeyGenerator forceMaxAge?: number - responseEncoding?: BufferEncoding nullIfNotFound?: boolean ignoreRecorder?: boolean } diff --git a/src/clients/infra/VBase.ts b/src/clients/infra/VBase.ts index 291ab918e..530c72013 100644 --- a/src/clients/infra/VBase.ts +++ b/src/clients/infra/VBase.ts @@ -176,7 +176,7 @@ export class VBase extends InfraClient { } public deleteFile = (bucket: string, path: string, tracingConfig?: RequestTracingConfig, ifMatch?: string) => { - const headers = ifMatch ? { 'If-Match': ifMatch } : null + const headers = ifMatch ? { 'If-Match': ifMatch } : {} as Record const metric = 'vbase-delete-file' return this.http.delete(routes.File(bucket, path), {headers, metric, tracing: { requestSpanNameSuffix: metric, diff --git a/yarn.lock b/yarn.lock index e2df9517a..53fc1cc8f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1025,12 +1025,13 @@ axios-retry@^3.1.2: dependencies: is-retry-allowed "^1.1.0" -axios@^0.21.1: - version "0.21.1" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" - integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== +axios@0.27.2: + version "0.27.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972" + integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ== dependencies: - follow-redirects "^1.10.0" + follow-redirects "^1.14.9" + form-data "^4.0.0" babel-jest@^25.1.0: version "25.1.0" @@ -1383,7 +1384,7 @@ color-name@~1.1.4: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== -combined-stream@^1.0.6, combined-stream@~1.0.6: +combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6: version "1.0.8" resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== @@ -1978,10 +1979,10 @@ find-up@^4.0.0, find-up@^4.1.0: locate-path "^5.0.0" path-exists "^4.0.0" -follow-redirects@^1.10.0: - version "1.14.1" - resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.1.tgz#d9114ded0a1cfdd334e164e6662ad02bfd91ff43" - integrity sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg== +follow-redirects@^1.14.9: + version "1.15.2" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13" + integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA== for-in@^1.0.2: version "1.0.2" @@ -1993,6 +1994,15 @@ forever-agent@~0.6.1: resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE= +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + form-data@~2.3.2: version "2.3.3" resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6" @@ -5117,4 +5127,4 @@ zip-stream@^2.1.2: dependencies: archiver-utils "^2.1.0" compress-commons "^2.1.1" - readable-stream "^3.4.0" \ No newline at end of file + readable-stream "^3.4.0"