Skip to content

Commit

Permalink
fix: use native fetch over superagent
Browse files Browse the repository at this point in the history
  • Loading branch information
kielllll committed Oct 28, 2024
1 parent e32bc49 commit 440efa4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 110 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"redux-saga": "^1.1.3",
"redux-watch": "^1.2.0",
"reselect": "^4.1.6",
"sprintf-js": "^1.1.2",
"superagent": "^9.0.0"
"sprintf-js": "^1.1.2"
},
"devDependencies": {
"@babel/cli": "^7.18.6",
Expand Down
31 changes: 17 additions & 14 deletions src/assets/js/react/api/coreFonts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* Dependencies */
import request from 'superagent/dist/superagent.min'

/**
* @package Gravity PDF
* @copyright Copyright (c) 2024, Blue Liquid Designs
Expand All @@ -15,12 +12,15 @@ import request from 'superagent/dist/superagent.min'
*
* @since 5.2
*/
export function apiGetFilesFromGitHub () {
return request
.get(GFPDF.pluginUrl + 'dist/payload/core-fonts.json')
.accept('application/json')
.type('json')
.parse(response => JSON.parse(response.text))
export async function apiGetFilesFromGitHub () {
const res = await fetch(GFPDF.pluginUrl + 'dist/payload/core-fonts.json', {
method: 'GET',
headers: {
Accept: 'application/json'
}
})

return await res.json()
}

/**
Expand All @@ -32,9 +32,12 @@ export function apiGetFilesFromGitHub () {
* @since 5.2
*/
export function apiPostDownloadFonts (file) {
return request
.post(GFPDF.ajaxUrl)
.field('action', 'gfpdf_save_core_font')
.field('nonce', GFPDF.ajaxNonce)
.field('font_name', file)
return fetch(GFPDF.ajaxUrl, {
method: 'POST',
body: JSON.stringify({
action: 'gfpdf_save_core_font',
nonce: GFPDF.ajaxNonce,
font_name: file
})
})
}
7 changes: 2 additions & 5 deletions src/assets/js/react/api/help.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* Dependencies */
import request from 'superagent/dist/superagent.min'

/**
* @package Gravity PDF
* @copyright Copyright (c) 2024, Blue Liquid Designs
Expand All @@ -17,6 +14,6 @@ import request from 'superagent/dist/superagent.min'
*
* @since 5.2
*/
export const apiGetSearchResult = searchQuery => {
return request.get(`https://gravitypdf.com/wp-json/wp/v2/v6_docs/?search=${searchQuery}`)
export const apiGetSearchResult = async searchQuery => {
return fetch(`https://gravitypdf.com/wp-json/wp/v2/v6_docs/?search=${searchQuery}`)
}
41 changes: 24 additions & 17 deletions src/assets/js/react/api/templates.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/* Dependencies */
import request from 'superagent/dist/superagent.min'

/**
* @package Gravity PDF
* @copyright Copyright (c) 2024, Blue Liquid Designs
Expand All @@ -16,10 +13,13 @@ import request from 'superagent/dist/superagent.min'
* @since 5.2
*/
export function apiPostUpdateSelectBox () {
return request
.post(GFPDF.ajaxUrl)
.field('action', 'gfpdf_get_template_options')
.field('nonce', GFPDF.ajaxNonce)
return fetch(GFPDF.ajaxUrl, {
method: 'POST',
body: JSON.stringify({
action: 'gfpdf_get_template_options',
nonce: GFPDF.ajaxNonce
})
})
}

/**
Expand All @@ -32,11 +32,14 @@ export function apiPostUpdateSelectBox () {
* @since 5.2
*/
export function apiPostTemplateProcessing (templateId) {
return request
.post(GFPDF.ajaxUrl)
.field('action', 'gfpdf_delete_template')
.field('nonce', GFPDF.ajaxNonce)
.field('id', templateId)
return fetch(GFPDF.ajaxUrl, {
method: 'POST',
body: JSON.stringify({
action: 'gfpdf_delete_template',
nonce: GFPDF.ajaxNonce,
id: templateId
})
})
}

/**
Expand All @@ -49,9 +52,13 @@ export function apiPostTemplateProcessing (templateId) {
* @since 5.2
*/
export function apiPostTemplateUploadProcessing (file, filename) {
return request
.post(GFPDF.ajaxUrl)
.field('action', 'gfpdf_upload_template')
.field('nonce', GFPDF.ajaxNonce)
.attach('template', file, filename)
const formData = new FormData()
formData.append('action', 'gfpdf_upload_template')
formData.append('nonce', GFPDF.ajaxNonce)
formData.append('template', file, filename)

return fetch(GFPDF.ajaxUrl, {
method: 'POST',
body: formData
})
}
2 changes: 1 addition & 1 deletion src/assets/js/react/sagas/coreFonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { apiGetFilesFromGitHub, apiPostDownloadFonts } from '../api/coreFonts'
export function * getFilesFromGitHub () {
try {
const response = yield call(apiGetFilesFromGitHub)
yield put(getFilesFromGitHubSuccess(response.body))
yield put(getFilesFromGitHubSuccess(response))

Check warning on line 32 in src/assets/js/react/sagas/coreFonts.js

View check run for this annotation

Codecov / codecov/patch

src/assets/js/react/sagas/coreFonts.js#L32

Added line #L32 was not covered by tests
} catch (error) {
yield put(getFilesFromGitHubFailed(GFPDF.coreFontGithubError))
}
Expand Down
73 changes: 2 additions & 71 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3029,11 +3029,6 @@ arraybuffer.prototype.slice@^1.0.3:
is-array-buffer "^3.0.4"
is-shared-array-buffer "^1.0.2"

asap@^2.0.0:
version "2.0.6"
resolved "https://registry.yarnpkg.com/asap/-/asap-2.0.6.tgz#e50347611d7e690943208bbdafebcbc2fb866d46"
integrity sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==

asn1@~0.2.3:
version "0.2.6"
resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.6.tgz#0d3a7bb6e64e02a90c0303b31f292868ea09a08d"
Expand Down Expand Up @@ -3797,7 +3792,7 @@ common-path-prefix@^3.0.0:
resolved "https://registry.yarnpkg.com/common-path-prefix/-/common-path-prefix-3.0.0.tgz#7d007a7e07c58c4b4d5f433131a19141b29f11e0"
integrity sha512-QE33hToZseCH3jS0qN96O/bSh3kaw/h+Tq7ngyY9eWDUnTlTNUyqfqvCXioLe5Na5jFsL78ra/wuBU4iuEgd4w==

component-emitter@^1.2.1, component-emitter@^1.3.0:
component-emitter@^1.2.1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.1.tgz#ef1d5796f7d93f135ee6fb684340b26403c97d17"
integrity sha512-T0+barUSQRTUQASh8bx02dl+DhF54GtIDY13Y3m9oWTklKbb3Wv974meRpeZ3lp1JpLVECWWNHC4vaG2XHXouQ==
Expand Down Expand Up @@ -3827,11 +3822,6 @@ convert-source-map@^2.0.0:
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-2.0.0.tgz#4b560f649fc4e918dd0ab75cf4961e8bc882d82a"
integrity sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==

cookiejar@^2.1.4:
version "2.1.4"
resolved "https://registry.yarnpkg.com/cookiejar/-/cookiejar-2.1.4.tgz#ee669c1fea2cf42dc31585469d193fef0d65771b"
integrity sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==

copy-descriptor@^0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
Expand Down Expand Up @@ -4121,7 +4111,7 @@ data-view-byte-offset@^1.0.0:
es-errors "^1.3.0"
is-data-view "^1.0.1"

debug@4, debug@^4.3.4, debug@^4.3.5:
debug@4, debug@^4.3.5:
version "4.3.5"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.5.tgz#e83444eceb9fedd4a1da56d671ae2446a01a6e1e"
integrity sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==
Expand Down Expand Up @@ -4323,14 +4313,6 @@ device-specs@^1.0.0:
resolved "https://registry.yarnpkg.com/device-specs/-/device-specs-1.0.1.tgz#b1a26c717a5339815238abf07f427e0b340d35ac"
integrity sha512-rxns/NDZfbdYumnn801z9uo8kWIz3Eld7Bk/F0V9zw4sZemSoD93+gxHEonLdxYulkws4iCMt7ZP8zuM8EzUSg==

dezalgo@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/dezalgo/-/dezalgo-1.0.4.tgz#751235260469084c132157dfa857f386d4c33d81"
integrity sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==
dependencies:
asap "^2.0.0"
wrappy "1"

diff-sequences@^29.6.3:
version "29.6.3"
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-29.6.3.tgz#4deaf894d11407c51efc8418012f9e70b84ea921"
Expand Down Expand Up @@ -5327,11 +5309,6 @@ fast-levenshtein@^2.0.6, fast-levenshtein@~2.0.6:
resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917"
integrity sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==

fast-safe-stringify@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz#c406a83b6e70d9e35ce3b30a81141df30aeba884"
integrity sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==

fast-uri@^3.0.1:
version "3.0.3"
resolved "https://registry.yarnpkg.com/fast-uri/-/fast-uri-3.0.3.tgz#892a1c91802d5d7860de728f18608a0573142241"
Expand Down Expand Up @@ -5515,15 +5492,6 @@ form-data@~2.3.2:
combined-stream "^1.0.6"
mime-types "^2.1.12"

formidable@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/formidable/-/formidable-3.5.1.tgz#9360a23a656f261207868b1484624c4c8d06ee1a"
integrity sha512-WJWKelbRHN41m5dumb0/k8TeAx7Id/y3a+Z7QfhxP/htI9Js5zYaEDtG8uMgG0vM0lOlqnmjE99/kfpOYi/0Og==
dependencies:
dezalgo "^1.0.4"
hexoid "^1.0.0"
once "^1.4.0"

fragment-cache@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/fragment-cache/-/fragment-cache-0.2.1.tgz#4290fad27f13e89be7f33799c6bc5a0abfff0d19"
Expand Down Expand Up @@ -5923,11 +5891,6 @@ hasown@^2.0.0, hasown@^2.0.1, hasown@^2.0.2:
dependencies:
function-bind "^1.1.2"

hexoid@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/hexoid/-/hexoid-1.0.0.tgz#ad10c6573fb907de23d9ec63a711267d9dc9bc18"
integrity sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==

highlight-es@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/highlight-es/-/highlight-es-1.0.3.tgz#12abc300a27e686f6f18010134e3a5c6d2fe6930"
Expand Down Expand Up @@ -7808,11 +7771,6 @@ merge2@^1.2.3, merge2@^1.3.0, merge2@^1.4.1:
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==

methods@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
integrity sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==

micromatch@^3.1.10, micromatch@^3.1.4:
version "3.1.10"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-3.1.10.tgz#70859bc95c9840952f359a068a3fc49f9ecfac23"
Expand Down Expand Up @@ -7860,11 +7818,6 @@ mime-types@^2.1.12, mime-types@^2.1.27, mime-types@~2.1.19:
dependencies:
mime-db "1.52.0"

mime@2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-2.6.0.tgz#a2a682a95cd4d0cb1d6257e28f83da7e35800367"
integrity sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==

mime@~1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.4.1.tgz#121f9ebc49e3766f311a76e1fa1c8003c4b03aa6"
Expand Down Expand Up @@ -8966,13 +8919,6 @@ qrcode-terminal@^0.10.0:
resolved "https://registry.yarnpkg.com/qrcode-terminal/-/qrcode-terminal-0.10.0.tgz#a76a48e2610a18f97fa3a2bd532b682acff86c53"
integrity sha512-ZvWjbAj4MWAj6bnCc9CnculsXnJr7eoKsvH/8rVpZbqYxP2z05HNQa43ZVwe/dVRcFxgfFHE2CkUqn0sCyLfHw==

qs@^6.11.0:
version "6.12.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.12.1.tgz#39422111ca7cbdb70425541cba20c7d7b216599a"
integrity sha512-zWmv4RSuB9r2mYQw3zxQuHWeU+42aKi1wWig/j4ele4ygELZ7PEO6MM7rim9oAQH2A5MWfsAVf/jPvTPgCbvUQ==
dependencies:
side-channel "^1.0.6"

"qs@^6.5.1 < 6.10":
version "6.9.7"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.7.tgz#4610846871485e1e048f44ae3b94033f0e675afe"
Expand Down Expand Up @@ -10143,21 +10089,6 @@ stylehacks@^7.0.4:
browserslist "^4.23.3"
postcss-selector-parser "^6.1.2"

superagent@^9.0.0:
version "9.0.2"
resolved "https://registry.yarnpkg.com/superagent/-/superagent-9.0.2.tgz#a18799473fc57557289d6b63960610e358bdebc1"
integrity sha512-xuW7dzkUpcJq7QnhOsnNUgtYp3xRwpt2F7abdRYIpCsAt0hhUqia0EdxyXZQQpNmGtsCzYHryaKSV3q3GJnq7w==
dependencies:
component-emitter "^1.3.0"
cookiejar "^2.1.4"
debug "^4.3.4"
fast-safe-stringify "^2.1.1"
form-data "^4.0.0"
formidable "^3.5.1"
methods "^1.1.2"
mime "2.6.0"
qs "^6.11.0"

supports-color@^5.3.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"
Expand Down

0 comments on commit 440efa4

Please sign in to comment.