# storage-sdk-js

> 支持加密请求

Latest version **1.0.3** (published 2022-02-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install storage-sdk-js
pnpm add storage-sdk-js
yarn add storage-sdk-js
bun add storage-sdk-js
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2022-02-23 |
| First published | 2022-02-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 361.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | amaoy |
| Keywords | crypto-js, axios |

## Links

- npm: https://www.npmjs.com/package/storage-sdk-js
- npm.io page: https://npm.io/package/storage-sdk-js

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2022-02-23
- 1.0.2 — 2022-02-22
- 1.0.1 — 2022-02-21

## README

# 1 、下载与安装

#### **环境依赖**

Node：用于下载和安装node编译运行环境，请前往node官网进行下载

#### **安装SDK**

执行以下命令安装Storage JS SDK：

```text
// 安装前置模块 
npm install axios crypto-js
// 安装加密SDK
npm install storage-sdk-js
```

# 2、开始使用

下面为您演示使用Storage JS SDK完成一个基础操作，如创建一条数据。

```javascript
import create from "storage-sdk-js"

const http = create({
  baseURL: "http://dev-gw.sunac.com.cn",
  crypto: {
    type: "aes",
    key: 'kkkkkkkkkkkkkkkk',
    cfg: {
      iv: "kkkkkkkkkkkkkkkk",
    },
  },
  signQuery: {
    ak: "ccccc",
    sk: "bbbbb",
  },
});
http.post("/storage/api/v1/tenant/insertOne?tenantId=tenantId_3001",
          {
            tenantId: "tenantId_3001",
            tempId: "tempId-01",
            data: {
              name: "ssss",
              phone: "15811388293",
            },
          }
         )
.then((res) => {
  console.log(res);
});

```

# 3、初始化http对象

#### 3.1 初始化**create**对象参数说明

| 参数          | 说明                                                         | 类型    | 默认值 |
| ------------- | :----------------------------------------------------------- | ------- | ------ |
| **crypto**    | 加密对象                                                     | object  | -      |
| unEncryt      | 禁用加密，在create 实例传入将覆盖至所有接口，单个接口使用，在config添加该属性中也生效 | boolean | falase |
| **signQuery** | 签名参数配置                                                 | object  | -      |
| ……            | 其余参数均和 【[axios](https://github.com/axios/axios#request-config)】 配置相同 | -       | -      |

#### 3.2 crypto参数说明

| 参数 | 类型                                                         | 是否必填 | 针对加密对象 |
| ---- | ------------------------------------------------------------ | -------- | ------------ |
| type | aes｜des ｜rsa_PKCS1                               | 是       | all          |
| key  | string 加密key值                                             | 是       | all          |
| cfg  | 调整aes、des的加密模式、填充模式等等具体可以查看文档 【[crypto-js](https://cryptojs.gitbook.io/docs/)】,  目前仅支持mode:CBC padding: Pkcs7，其中iv参数非必填项默认为""。 | 否       | ase｜ase     |

#### 3.3 signQuery参数说明

| 参数 | 说明                  | 类型   | 默认值 |
| :--- | --------------------- | ------ | ------ |
| sk   | sercetKey             | string | -      |
| ak   | accessKey             | string | -      |
| exp  | 单位：秒。exp秒后过期 | number | 900    |

# 4、实例方法

##### 拦截器

```javascript
// 请求拦截器
http.interceptors.request.use((config) => {
   return config;
});

// 响应拦截器
http.interceptors.response.use((res) => {
   // 自定义错误
   if (res.code !== 200) {
      return Promise.reject(new Error("Request Error"));
   };

   return res;
}, (error) => {
   const { message, response, config } = error;
   return Promise.reject(error);
});
```

##### **请求**

```javascript
http.request(config)

http.get(url[, data[, config]])

http.post(url[, data[, config]])

http.put(url[, data[, config]])

http.delete(url[, config])

http.head(url[, config])

http.options(url[, config])

http.connect(url[, config])
```



# 5、Webpack5 注意事项 -- 废弃

需要安装对接的模块，支持node-rsa运行

```
const Webpack = require('webpack')
module.exports = {
  ...
  resolve: {
    fallback: {
      // 添加垫片
      "assert": require.resolve("assert"),
      "buffer": require.resolve("buffer"),
      "stream": require.resolve("stream-browserify"),
      "constants": require.resolve("constants-browserify"),
      "crypto": require.resolve("crypto-browserify")
    }
  },
  plugins: [
    new Webpack.ProvidePlugin({
        Buffer: ['buffer', 'Buffer']
    }),
    new Webpack.ProvidePlugin({
        process: 'process/browser',
    }),
  ]
};
```

---
_Source: https://npm.io/package/storage-sdk-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
