
Research
/Security News
9 Malicious NuGet Packages Deliver Time-Delayed Destructive Payloads
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.
@privyid/nuapi
Advanced tools
Nuxt HTTP Client module
@privyid/nuapi dependency to your projectyarn add --dev @privyid/nuapi
@privyid/nuapi to the modules section of nuxt.config.tsexport default defineNuxtConfig({
modules: [
'@privyid/nuapi'
]
})
That's it! You can now use NuAPI in your Nuxt app ✨
import {
createLazyton,
ApiResponse,
AxiosRequestConfig
} from '@privyid/nuapi'
const useApi = createLazyton({ prefixURL: '/api' })
interface User {
userId: string,
email: string,
name: string
role: string,
}
interface FormUser {
name: string,
email: string,
role: string,
}
function getUserProfile (config?: AxiosRequestConfig): ApiResponse<User> {
return useApi().get('/user/profile', config)
}
function postUserProfile (body: FormUser, config?: AxiosRequestConfig): ApiResponse<User> {
return useApi().post('/user/profile', body, config)
}
There are available hook for add request/response interceptors.
import {
onRequest,
onRequestError,
onResponse,
onResponseError,
onError,
getCode,
getMessage,
} from '@privyid/nuapi/core'
function isUnauthorize (error: Error): boolean {
const code = getCode(error)
const message = getMessage(error)
return code === 401 && message.includes('Unauthorized')
}
/** set additional or custom headers */
onRequest((config) => {
const token: string = cookies.get('session/token') || ''
// check available authorization header
// and set authorization header
if (config.headers && !config.headers.Authorization && token)
config.headers.Authorization = `Bearer ${token}`
return config
})
/**
* check unauthorize error response
* cause of invalid or expired token
*/
onResponseError(async (error) => {
if (isUnauthorize(error)) {
await navigateTo('/login')
}
throw error
})
All request per instance will be add into queue before sent with priority MEDIUM (20).
If you want to send your request first before the others, you can set using option priority. The higher priority will run first.
import { QueuePriority } from '@privyid/nuapi/core'
useApi().get('/document/load', {
// Using presets
priority: QueuePriority.HIGH,
// Or using number
priority: 50,
})
Sometime, you want to cancel request with same endpoint like when you working with searching or filter.
NuAPI has built in function for this case. Just set requestkey, multiple sent request with same id will cancel last request before.
useApi().get('/document/load', {
requestkey: 'document-load',
})
Cancel spesific request by requestKey using .cancel()
useApi().cancel('document-load')
Or cancel all requests that have requestKey using .cancelAll()
useApi().cancelAll()
NuAPI automatically retries request when got an error with status code:
By default will retries 3 times (except for PATCH, POST, PUT, DELETE) can be changed using option retry.
useApi().get('/document/load', {
retry: 5,
})
You can customize when request should retries using retryOn
useApi().get('/document/load', {
retryOn (error) {
return getCode(error) === 423
&& error.config.retryCount < 3
},
})
👉 You can learn more about usage in JSDocs Documentation.
corepack enable (use npm i -g corepack for Node.js < 16.10)yarn installyarn dev:prepare to generate type stubs.yarn dev to start playground in development mode.MIT License
FAQs
Nuxt HTTP Client module
The npm package @privyid/nuapi receives a total of 20 weekly downloads. As such, @privyid/nuapi popularity was classified as not popular.
We found that @privyid/nuapi demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.