New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

request-crypto

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

request-crypto - npm Package Compare versions

Comparing version 1.1.2 to 1.2.0

packages/instance.ts

27

dist/index.cjs.js

@@ -1,26 +0,1 @@

'use strict'
var r = require('axios')
exports.createRequestInstance = (e, t = {}) => {
const n = r.create(e)
return (
(function (r, e = {}) {
const { encryptFn: t, decryptFn: n } = e
t &&
r.interceptors.request.use((r) => {
const e = r.transformRequest
if (!e) throw new Error(`request ${r} has no transformRequest`)
if (!Array.isArray(e))
throw new Error(`transformRequest ${e} is not an array`)
if ((e.push(t), !n)) return r
const s = r.transformResponse
if (!s) throw new Error(`request ${r} has no transformResponse`)
if ('function' != typeof n)
throw new Error(`decryptFn ${n} is not a function`)
if (!Array.isArray(s))
throw new Error(`transformResponse ${s} is not an array`)
return s.unshift(n), r
})
})(n, t),
n
)
}
"use strict";var r=require("axios");const t=(r=16,t="high")=>{const e=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],n=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],o=[0,1,2,3,4,5,6,7,8,9],s=["!","@","-","_","=","<",">","#","*","%","+","&","^","$"],a=[];let u="";const i=function(...r){let t="";return r.forEach((r=>{t+=r[Math.floor(Math.random()*r.length)]})),t};switch(t){case"high":u+=i(e,n,o,s),a.push(...e,...n,...o,...s);break;case"medium":u+=i(e,n,o),a.push(...e,...n,...o);break;default:u+=i(e,o),a.push(...e,...o)}const c=r-u.length;for(let r=0;r<c;r++)u+=i(a);return u};exports.createRequestInstance=(t,e={})=>{const n=r.create(t);return function(r,t={}){const{encryptFn:e,decryptFn:n}=t;e&&r.interceptors.request.use((r=>{const t=r.transformRequest;if(!t)throw new Error(`request ${r} has no transformRequest`);if(!Array.isArray(t))throw new Error(`transformRequest ${t} is not an array`);if(t.push(e),!n)return r;const o=r.transformResponse;if(!o)throw new Error(`request ${r} has no transformResponse`);if("function"!=typeof n)throw new Error(`decryptFn ${n} is not a function`);if(!Array.isArray(o))throw new Error(`transformResponse ${o} is not an array`);return o.unshift(n),r}))}(n,e),n},exports.getCryptoInfo=r=>{const e=r||t(16,"high");return{info:{key:e,algorithm:"SM4"},key:[...Buffer.from(e)]}},exports.getSm4EncryptConfig=()=>({mode:"ecb",padding:"pkcs#7",output:"array"}),exports.randomPassword=t;

@@ -1,26 +0,1 @@

import r from 'axios'
const n = (n, t = {}) => {
const o = r.create(n)
return (
(function (r, n = {}) {
const { encryptFn: t, decryptFn: o } = n
t &&
r.interceptors.request.use((r) => {
const n = r.transformRequest
if (!n) throw new Error(`request ${r} has no transformRequest`)
if (!Array.isArray(n))
throw new Error(`transformRequest ${n} is not an array`)
if ((n.push(t), !o)) return r
const e = r.transformResponse
if (!e) throw new Error(`request ${r} has no transformResponse`)
if ('function' != typeof o)
throw new Error(`decryptFn ${o} is not a function`)
if (!Array.isArray(e))
throw new Error(`transformResponse ${e} is not an array`)
return e.unshift(o), r
})
})(o, t),
o
)
}
export { n as createRequestInstance }
import r from"axios";const t=(t,n={})=>{const e=r.create(t);return function(r,t={}){const{encryptFn:n,decryptFn:e}=t;n&&r.interceptors.request.use((r=>{const t=r.transformRequest;if(!t)throw new Error(`request ${r} has no transformRequest`);if(!Array.isArray(t))throw new Error(`transformRequest ${t} is not an array`);if(t.push(n),!e)return r;const o=r.transformResponse;if(!o)throw new Error(`request ${r} has no transformResponse`);if("function"!=typeof e)throw new Error(`decryptFn ${e} is not a function`);if(!Array.isArray(o))throw new Error(`transformResponse ${o} is not an array`);return o.unshift(e),r}))}(e,n),e};const n=(r=16,t="high")=>{const n=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],e=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],o=[0,1,2,3,4,5,6,7,8,9],s=["!","@","-","_","=","<",">","#","*","%","+","&","^","$"],a=[];let f="";const i=function(...r){let t="";return r.forEach((r=>{t+=r[Math.floor(Math.random()*r.length)]})),t};switch(t){case"high":f+=i(n,e,o,s),a.push(...n,...e,...o,...s);break;case"medium":f+=i(n,e,o),a.push(...n,...e,...o);break;default:f+=i(n,o),a.push(...n,...o)}const u=r-f.length;for(let r=0;r<u;r++)f+=i(a);return f},e=r=>{const t=r||n(16,"high");return{info:{key:t,algorithm:"SM4"},key:[...Buffer.from(t)]}},o=()=>({mode:"ecb",padding:"pkcs#7",output:"array"});export{t as createRequestInstance,e as getCryptoInfo,o as getSm4EncryptConfig,n as randomPassword};
{
"name": "request-crypto",
"description": "axios with crypto callback",
"version": "1.1.1",
"version": "1.2.0",
"main": "index.cjs.js",

@@ -6,0 +6,0 @@ "module": "index.esm.js",

{
"name": "request-crypto",
"version": "1.1.2",
"version": "1.2.0",
"description": "axios with crypto callback",

@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js",

@@ -1,55 +0,4 @@

import axios, { AxiosInstance, CreateAxiosDefaults } from 'axios'
import { createRequestInstanceType, cryptoFnsType } from './types'
const createRequestInstance: createRequestInstanceType = <T>(
options: CreateAxiosDefaults<T> | undefined,
cryptoFns: cryptoFnsType = {},
) => {
const instance = axios.create(options)
addEncryptFnToTransformRequest(instance, cryptoFns)
return instance
}
function addEncryptFnToTransformRequest(
instance: AxiosInstance,
cryptoFns: cryptoFnsType = {},
) {
const { encryptFn, decryptFn } = cryptoFns
if (encryptFn) {
instance.interceptors.request.use((value) => {
const transformRequest = value.transformRequest
if (!transformRequest) {
throw new Error(`request ${value} has no transformRequest`)
}
if (Array.isArray(transformRequest)) {
transformRequest.push(encryptFn)
} else {
throw new Error(`transformRequest ${transformRequest} is not an array`)
}
if (!decryptFn) {
return value
}
const transformResponse = value.transformResponse
if (!transformResponse) {
throw new Error(`request ${value} has no transformResponse`)
}
if (typeof decryptFn !== 'function') {
throw new Error(`decryptFn ${decryptFn} is not a function`)
}
if (Array.isArray(transformResponse)) {
transformResponse.unshift(decryptFn)
} else {
throw new Error(
`transformResponse ${transformResponse} is not an array`,
)
}
return value
})
}
}
export { createRequestInstance }
export { createRequestInstance } from './instance'
export type { createRequestInstanceType, cryptoFnsType } from './types'
export { randomPassword } from './utils'
export { getCryptoInfo, getSm4EncryptConfig } from './sm'

@@ -21,1 +21,5 @@ import {

}
export interface randomPassType {
(length: number, mode?: 'low' | 'medium' | 'high'): string
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc