Skip to content

Commit

Permalink
fix(DEVX-363): remove node 16 support (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
lojzatran authored Jan 7, 2025
1 parent 2663316 commit 7a6ee4e
Show file tree
Hide file tree
Showing 36 changed files with 199 additions and 177 deletions.
99 changes: 64 additions & 35 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,6 @@ version: 2.1
aliases:
- &working_directory ~/commercetools-sdk-typescript

# node version 16
- &restore_yarn_cache_node_16
name: 'Restoring yarn cache'
keys:
- yarn-cache-node_16-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}

- &save_yarn_cache_node_16
name: 'Saving yarn cache'
key: yarn-cache-node_16-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn


# node version 18
- &restore_yarn_cache_node_18
name: 'Restoring yarn cache'
Expand Down Expand Up @@ -44,13 +31,22 @@ aliases:
paths:
- ~/.cache/yarn

# node version 22
- &restore_yarn_cache_node_22
name: 'Restoring yarn cache'
keys:
- yarn-cache-node_22-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}

- &save_yarn_cache_node_22
name: 'Saving yarn cache'
key: yarn-cache-node_22-{{ .Environment.CACHE_VERSION }}-{{ checksum "yarn.lock" }}
# Persisting to the workspace is always relative to the root which is our working directory.
# https://circleci.com/docs/2.0/configuration-reference/#persist_to_workspace
paths:
- ~/.cache/yarn

# executors
executors:
node_16:
docker:
- image: cimg/node:16.20.2
working_directory: *working_directory

node_18:
docker:
- image: cimg/node:18.20.3
Expand All @@ -61,22 +57,27 @@ executors:
- image: cimg/node:20.14.0
working_directory: *working_directory

node_22:
docker:
- image: cimg/node:22.12.0
working_directory: *working_directory


# orbs
orbs:
codecov: codecov/[email protected]

# jobs
jobs:
install_test_node_16:
executor: node_16
install_test_node_18:
executor: node_18
steps:
- checkout
- restore_cache: *restore_yarn_cache_node_16
- restore_cache: *restore_yarn_cache_node_18
- run:
name: Installing dependencies
command: yarn install --ignore-engines --frozen-lockfile # temp ignore engine checks [will deprecate node v16 soon]
- save_cache: *save_yarn_cache_node_16
command: yarn install --frozen-lockfile
- save_cache: *save_yarn_cache_node_18
- run:
name: Install example dependencies
command: |
Expand All @@ -93,16 +94,22 @@ jobs:
- run:
name: Running tests
command: yarn test --testPathIgnorePatterns='packages/platform-sdk/test/integration-tests'
- run:
name: Running integration tests
command: yarn test packages/platform-sdk/test/integration-tests --coverage
- codecov/upload:
file: coverage/clover.xml
flags: integrationtests

install_test_node_18:
executor: node_18
install_test_node_20:
executor: node_20
steps:
- checkout
- restore_cache: *restore_yarn_cache_node_18
- restore_cache: *restore_yarn_cache_node_20
- run:
name: Installing dependencies
command: yarn install --frozen-lockfile
- save_cache: *save_yarn_cache_node_18
- save_cache: *save_yarn_cache_node_20
- run:
name: Install example dependencies
command: |
Expand All @@ -119,16 +126,38 @@ jobs:
- run:
name: Running tests
command: yarn test --testPathIgnorePatterns='packages/platform-sdk/test/integration-tests'
- run:
name: Running integration tests
command: yarn test packages/platform-sdk/test/integration-tests --coverage
- codecov/upload:
file: coverage/clover.xml
flags: integrationtests

install_test_node_20:
executor: node_20
install_test_node_22:
executor: node_22
steps:
- checkout
- restore_cache: *restore_yarn_cache_node_20
- restore_cache: *restore_yarn_cache_node_22
- run:
name: Installing dependencies
command: yarn install --frozen-lockfile
- save_cache: *save_yarn_cache_node_20
- save_cache: *save_yarn_cache_node_22
- run:
name: Install example dependencies
command: |
cd examples
yarn install --frozen-lockfile
- run:
name: Building packages
command: yarn build
- run:
name: Running example tests
command: |
cd examples
yarn test
- run:
name: Running tests
command: yarn test --testPathIgnorePatterns='packages/platform-sdk/test/integration-tests'
- run:
name: Running integration tests
command: yarn test packages/platform-sdk/test/integration-tests --coverage
Expand All @@ -141,13 +170,13 @@ workflows:
version: 2
build_and_test:
jobs:
- install_test_node_16:
context: org-global
- install_test_node_18:
context: org-global
# requires:
# - install_test_node_16
- install_test_node_20:
context: org-global
requires:
- install_test_node_18
- install_test_node_22:
context: org-global
requires:
- install_test_node_20
3 changes: 1 addition & 2 deletions BEST_PRACTICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ type HttpErrorType = {
Proxies can be configured at the http client level in the JS/TS SDK, here we pass the proxy url/ip address
```ts
import fetch from 'node-fetch'
import HttpsProxyAgent from 'https-proxy-agent'

const fetcherProxy = (url, fetchOptions = {}) => {
Expand Down Expand Up @@ -341,7 +340,7 @@ client

## Using HTTP client

The JS/TS SDK uses [node-fetch](https://github.com/bitinn/node-fetch) and its close relatives like [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch), [whatwg-fetch](https://github.com/whatwg/fetch) or [unfetch](https://github.com/developit/unfetch).
The JS/TS SDK uses [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) and its close relatives like [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch), [whatwg-fetch](https://github.com/whatwg/fetch) or [unfetch](https://github.com/developit/unfetch).
It is important to also note that due to changes in version 3 of `node-fetch`, it is expected that all projects using the v3 of `node-fetch` within the SDK must be in ESM (.mjs) module system. The JS/TS SDK fully supports v2 of `node-fetch` without any restrictions.

## The `Process` Function
Expand Down
2 changes: 0 additions & 2 deletions packages/history-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const {
createHttpClient,
} = require('@commercetools/sdk-client-v2')
const { createApiBuilderFromCtpClient } = require('@commercetools/history-sdk')
const fetch = require('node-fetch')

const projectKey = 'mc-project-key'
const authMiddlewareOptions = {
Expand Down Expand Up @@ -115,7 +114,6 @@ import {
createAuthForClientCredentialsFlow,
} from '@commercetools/sdk-client-v2'
import { createApiBuilderFromCtpClient } from '@commercetools/history-sdk'
import fetch from 'node-fetch'

const projectKey = 'some_project_key'

Expand Down
1 change: 0 additions & 1 deletion packages/history-sdk/test/helpers/api-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
createExecutorFromMiddlewares,
executeRequest,
} from './../../src'
import fetch from 'node-fetch'
import { requireEnvVar } from './test-utils'

const projectKey = requireEnvVar('CTP_PROJECT_KEY')
Expand Down
1 change: 0 additions & 1 deletion packages/history-sdk/test/helpers/ctp-api-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
createExecutorFromMiddlewares,
executeRequest,
} from '@commercetools/platform-sdk'
import fetch from 'node-fetch'
import { requireEnvVar } from './test-utils'

const projectKey = requireEnvVar('CTP_PROJECT_KEY')
Expand Down
2 changes: 0 additions & 2 deletions packages/importapi-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const {
createHttpClient,
} = require('@commercetools/sdk-client-v2')
const { createApiBuilderFromCtpClient } = require('@commercetools/importapi-sdk')
const fetch = require('node-fetch')

const projectKey = 'mc-project-key'
const authMiddlewareOptions = {
Expand Down Expand Up @@ -98,7 +97,6 @@ import {
createAuthForClientCredentialsFlow,
} from '@commercetools/sdk-client-v2'
import { createApiBuilderFromCtpClient } from '@commercetools/importapi-sdk')
import fetch from 'node-fetch'

const projectKey = 'some_project_key'

Expand Down
1 change: 0 additions & 1 deletion packages/importapi-sdk/test/helpers/ctp-api-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
createAuthForClientCredentialsFlow,
createHttpClient,
} from '@commercetools/sdk-client-v2'
import fetch from 'node-fetch'
import { requireEnvVar } from './test-utils'
import {
ApiRoot,
Expand Down
2 changes: 0 additions & 2 deletions packages/platform-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const {
createHttpClient,
} = require('@commercetools/sdk-client-v2')
const { createApiBuilderFromCtpClient } = require('@commercetools/platform-sdk')
const fetch = require('node-fetch')

const projectKey = 'mc-project-key'
const authMiddlewareOptions = {
Expand Down Expand Up @@ -128,7 +127,6 @@ import {
createAuthForClientCredentialsFlow,
} from '@commercetools/sdk-client-v2'
import { createApiBuilderFromCtpClient } from '@commercetools/platform-sdk'
import fetch from 'node-fetch'

const projectKey = 'some_project_key'

Expand Down
1 change: 0 additions & 1 deletion packages/platform-sdk/test/helpers/ctp-api-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
createHttpClient,
createClient,
} from '@commercetools/sdk-client-v2'
import fetch from 'node-fetch'
import { requireEnvVar } from './test-utils'
import {
ApiRoot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
import { requireEnvVar } from '../../helpers/test-utils'
import { ClientBuilder } from '@commercetools/sdk-client-v2'
import { ByProjectKeyRequestBuilder } from '../../../src/generated/client/by-project-key-request-builder'
import fetch from 'node-fetch'
import { randomUUID } from 'crypto'
import { apiRoot } from '../test-utils'
import { createCategory } from '../category/category-fixture'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Middleware,
} from '@commercetools/sdk-client-v2'
import { createApiBuilderFromCtpClient } from '@commercetools/platform-sdk'
import fetch from 'node-fetch'

const projectKey = requireEnvVar('CTP_PROJECT_KEY')
const clientId = requireEnvVar('CTP_CLIENT_ID')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ClientBuilder } from '@commercetools/sdk-client-v2'
import { createApiBuilderFromCtpClient } from '@commercetools/platform-sdk'
import fetch from 'node-fetch'

describe('integration test for process function', () => {
const projectKey = process.env.CTP_PROJECT_KEY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
projectKey,
} from '../test-utils'
import { createApiBuilderFromCtpClient } from '../../../src'
import fetch from 'node-fetch'
import { TokenCache } from '@commercetools/ts-client'

describe('testing error cases', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ describe('Correlation ID and user agent middlewares', () => {
)

const response = await apiRootV3.get().execute()
expect(response.headers?.['x-correlation-id'][0]).toEqual(correlationId)
expect(response.headers?.['x-correlation-id']).toEqual(correlationId)
expect((response?.originalRequest as any).headers['User-Agent']).toContain(
'test-app/commercetools-sdk-javascript-v3'
)
Expand Down
1 change: 0 additions & 1 deletion packages/platform-sdk/test/integration-tests/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from '@commercetools/ts-client'
import { createApiBuilderFromCtpClient } from '../../src'
import { requireEnvVar } from '../helpers/test-utils'
const fetch = require('node-fetch')

export const projectKey = requireEnvVar('CTP_PROJECT_KEY')
const clientId = requireEnvVar('CTP_CLIENT_ID')
Expand Down
1 change: 0 additions & 1 deletion packages/sdk-client-v3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
ClientBuilder,
} from '@commercetools/ts-client'
import { createApiBuilderFromCtpClient } from '@commercetools/platform-sdk'
import fetch from 'node-fetch'

const projectKey = 'mc-project-key'
const authMiddlewareOptions = {
Expand Down
6 changes: 2 additions & 4 deletions packages/sdk-client-v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
"url": "https://github.com/commercetools/commercetools-sdk-typescript/issues"
},
"dependencies": {
"abort-controller": "3.0.0",
"buffer": "^6.0.3",
"node-fetch": "^2.6.1"
"buffer": "^6.0.3"
},
"files": ["dist", "CHANGELOG.md"],
"author": "Chukwuemeka Ajima <[email protected]>",
Expand All @@ -49,7 +47,7 @@
"common-tags": "1.8.2",
"dotenv": "16.4.5",
"jest": "29.7.0",
"nock": "12.0.3",
"nock": "^14.0.0-beta.19",
"organize-imports-cli": "0.10.0"
},
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion packages/sdk-client-v3/src/client/builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch'
import * as middleware from '../middleware'
import { constants } from '../utils'
import { default as createClient } from './client'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch'
import {
AuthMiddlewareOptions,
Middleware,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch'
import {
AuthMiddlewareOptions,
Middleware,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch'
import {
Middleware,
MiddlewareRequest,
Expand Down
2 changes: 0 additions & 2 deletions packages/sdk-client-v3/src/types/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import AbortController, { AbortSignal } from 'abort-controller'

export type Nullable<T> = T | null
export type Keys = string | number | symbol
export type JsonObject<T = unknown> = { [key in Keys]: T }
Expand Down
9 changes: 7 additions & 2 deletions packages/sdk-client-v3/src/utils/executor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import AbortController from 'abort-controller'
import { HttpClientConfig, IResponse, TResponse } from '../types/types'
import { calculateRetryDelay, sleep, validateRetryCodes } from '../utils'

Expand Down Expand Up @@ -106,7 +105,13 @@ export default async function executor(request: HttpClientConfig) {
return { _response, shouldRetry: true }
}
} catch (e) {
if (e.name.includes('AbortError') && retryWhenAborted) {
// in nodejs v18, the error is AbortError, in nodejs v20, the error is TimeoutError
// https://github.com/nodejs/undici/issues/2590
if (
(e.name.includes('AbortError') ||
e.name.includes('TimeoutError')) &&
retryWhenAborted
) {
return { _response: e, shouldRetry: true }
} else {
throw e
Expand Down
7 changes: 4 additions & 3 deletions packages/sdk-client-v3/src/utils/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export default function getHeaders(

// whatwg-fetch
const map: JsonObject<string> = {}
return headers.forEach(
(value: any, name: string | number) => (map[name] = value)
)
headers.forEach((value: any, name: string | number) => {
return (map[name] = value)
})
return map
}
Loading

0 comments on commit 7a6ee4e

Please sign in to comment.