Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #725 from devoxa/update-node-v20
Browse files Browse the repository at this point in the history
Update NodeJS to v20
  • Loading branch information
kodiakhq[bot] authored Jan 7, 2024
2 parents cf257a3 + a8053c2 commit 7572716
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
uses: actions/checkout@v4

- name: 'Setup Node.JS'
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '18.17'
node-version: '20.9'

- name: 'Cache dependencies'
uses: buildjet/cache@v3
Expand Down
1 change: 0 additions & 1 deletion generators/generate-api-routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from 'fs'
import fetch from 'node-fetch'

const INCLUDE_COMMENTS = true

Expand Down
1 change: 0 additions & 1 deletion generators/generate-enums.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { matchAll } from '@devoxa/flocky'
import fs from 'fs'
import fetch from 'node-fetch'

const DOCUMENTATION_URLS = {
RawPaddleEnumCurrencies: `https://developer.paddle.com/reference/platform-parameters/supported-currencies`,
Expand Down
1 change: 0 additions & 1 deletion generators/generate-webhook-alerts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import fs from 'fs'
import fetch from 'node-fetch'

const INCLUDE_COMMENTS = true

Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@devoxa/aes-encryption": "2.0.0",
"dayjs": "1.11.10",
"form-data": "4.0.0",
"node-fetch": "2.7.0",
"php-serialize": "4.1.1"
},
"devDependencies": {
Expand All @@ -37,8 +36,7 @@
"@swc/core": "1.3.102",
"@swc/jest": "0.2.29",
"@types/jest": "29.5.11",
"@types/node": "18.19.4",
"@types/node-fetch": "2.6.10",
"@types/node": "20.9.5",
"eslint": "8.56.0",
"jest": "29.7.0",
"prettier": "3.1.1",
Expand All @@ -49,6 +47,6 @@
"access": "public"
},
"volta": {
"node": "18.19.0"
"node": "20.9.0"
}
}
5 changes: 2 additions & 3 deletions src/helpers/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import FormData from 'form-data'
import nodeFetch from 'node-fetch'

type Body = Record<string, string | number | undefined>

export async function fetch<T>(url: string, options: { method: string; body: Body }): Promise<T> {
const response = await nodeFetch(url, {
const response = await global.fetch(url, {
method: options.method,
body: objectToFormData(options.body),
})

return response.json()
return response.json() as T
}

function objectToFormData(object: Body): FormData {
Expand Down
5 changes: 5 additions & 0 deletions tests/__snapshots__/metadata.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`metadata codecs "encrypt" codec throws error on decryption failure 1`] = `"Failed decrypting metadata: Invalid authentication tag length: 0"`;

exports[`metadata codecs "stringify" codec throws error on parse failure 1`] = `"Failed parsing metadata: Unexpected token 'g', "garbage" is not valid JSON"`;
12 changes: 5 additions & 7 deletions tests/helpers/fetch.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import FormData from 'form-data'
import nodeFetch from 'node-fetch'
import { fetch } from '../../src/helpers/fetch'

jest.mock('node-fetch', () => jest.fn())
const mockFetch = jest.fn()
global.fetch = mockFetch

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function mockNextNodeFetchCall(json: any) {
;(nodeFetch as unknown as jest.Mock).mockImplementationOnce(async () => ({
json: async () => json,
}))
mockFetch.mockImplementationOnce(async () => ({ json: async () => json }))
}

function getLastNodeFetchCall() {
return (nodeFetch as unknown as jest.Mock).mock.calls[0]
return mockFetch.mock.calls[0]
}

describe('helpers -> fetch', () => {
beforeEach(() => {
;(nodeFetch as unknown as jest.Mock).mockClear()
mockFetch.mockClear()
})

test('can make a fetch request using a form data body', async () => {
Expand Down
8 changes: 2 additions & 6 deletions tests/metadata.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ describe('metadata codecs', () => {
test('"stringify" codec throws error on parse failure', () => {
const codec = stringifyMetadata()

expect(() => {
codec.parse('garbage')
}).toThrowError('Failed parsing metadata: Unexpected token g in JSON at position 0')
expect(() => codec.parse('garbage')).toThrowErrorMatchingSnapshot()
})

test('"encrypt" codec encrypts and decrypts metadata values', () => {
Expand All @@ -53,8 +51,6 @@ describe('metadata codecs', () => {
test('"encrypt" codec throws error on decryption failure', () => {
const codec = encryptMetadata(passthroughMetadata(), '01234567890123456789012345678901')

expect(() => {
codec.parse('garbage')
}).toThrowError('Failed decrypting metadata: Invalid authentication tag length: 0')
expect(() => codec.parse('garbage')).toThrowErrorMatchingSnapshot()
})
})
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"incremental": true,

// Type-Checking Options
"lib": ["es2022"],
"lib": ["es2023"],
"strict": true,
"skipLibCheck": true,
"strictPropertyInitialization": false,
Expand Down
43 changes: 5 additions & 38 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1180,23 +1180,15 @@
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.12.tgz#d70faba7039d5fca54c83c7dbab41051d2b6f6cb"
integrity sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==

"@types/[email protected]":
version "2.6.10"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.10.tgz#ff5c1ceacab782f2b7ce69957d38c1c27b0dc469"
integrity sha512-PPpPK6F9ALFTn59Ka3BaL+qGuipRfxNE8qVgkp0bVixeiR2c2/L+IVOiBdu9JhhT22sWnQEp6YyHGI2b2+CMcA==
dependencies:
"@types/node" "*"
form-data "^4.0.0"

"@types/node@*":
version "15.12.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.12.4.tgz#e1cf817d70a1e118e81922c4ff6683ce9d422e26"
integrity sha512-zrNj1+yqYF4WskCMOHwN+w9iuD12+dGm0rQ35HLl9/Ouuq52cEtd0CH9qMgrdNmi5ejC1/V7vKEXYubB+65DkA==

"@types/node@18.19.4":
version "18.19.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.4.tgz#89672e84f11a2c19543d694dac00ab8d7bc20ddb"
integrity sha512-xNzlUhzoHotIsnFoXmJB+yWmBvFZgKCI9TtPIEdYIMM1KWfwuY8zh7wvc1u1OAXlC7dlf6mZVx/s+Y5KfFz19A==
"@types/node@20.9.5":
version "20.9.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.5.tgz#bb441014bcb91c63742b0e1fe25b902f5d581faa"
integrity sha512-Uq2xbNq0chGg+/WQEU0LJTSs/1nKxz6u1iemLcGomkSnKokbW1fbLqc3HOqCf2JP7KjlL4QkS7oZZTrOQHQYgQ==
dependencies:
undici-types "~5.26.4"

Expand Down Expand Up @@ -2251,7 +2243,7 @@ for-each@^0.3.3:
dependencies:
is-callable "^1.1.3"

[email protected], form-data@^4.0.0:
[email protected]:
version "4.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==
Expand Down Expand Up @@ -3375,13 +3367,6 @@ natural-compare@^1.4.0:
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=

[email protected]:
version "2.7.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
dependencies:
whatwg-url "^5.0.0"

node-int64@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"
Expand Down Expand Up @@ -3995,11 +3980,6 @@ to-regex-range@^5.0.1:
dependencies:
is-number "^7.0.0"

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=

ts-api-utils@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.1.tgz#8144e811d44c749cd65b2da305a032510774452d"
Expand Down Expand Up @@ -4103,19 +4083,6 @@ walker@^1.0.8:
dependencies:
makeerror "1.0.12"

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

which-boxed-primitive@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6"
Expand Down

0 comments on commit 7572716

Please sign in to comment.