# storage-sdk-xcx

> 支持加密请求

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

## Install

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

## 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.1 |
| Published | 2022-02-23 |
| First published | 2022-02-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 375.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | amaoy |
| Keywords | crypto-js, axios |

## Links

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

## Dependencies (1)

- [deepmerge](https://npm.io/package/deepmerge.md) ^4.2.2

## 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.1 (latest) — 2022-02-23
- 1.0.0 — 2022-02-21

## README

# 1 、下载与安装

#### **环境依赖**

微信开发者工具

#### **安装SDK**

执行以下命令安装小程序npm扩展包：

```text
// 安装前置模块 
npm install crypto-js
// 安装加密SDK
npm install storage-sdk-xcx
```

# 2、开始使用

下面为您演示使用Storage JS SDK完成一个基础操作，如创建一条数据。

```javascript
// app.js
const { create } = require('storage-sdk-xcx')
const http = create({
   baseUrl: 'http://dev-gw.sunac.com.cn',
   crypto: {
      type: 'des',
      key: 'kkkkkkkkkkkkkkkk',
      cfg: {
         iv: 'kkkkkkkkkkkkkkkk'
      }
   },
   signQuery: {
      ak: "ccccc",
      sk: "bbbbb"
   }
})

http.post('/storage/api/v1/tenant/insertOne?tenantId=tenantId_3002', {
   "tenantId": "tenantId_3002",
   "tempId": "tempId-01",
   "data": {
      "name": "ssss",
			"phone": "15811388293"
   }
}, {
   unEncryt: false
}).then(res => {
   console.log(res)
})
```

# 3、初始化http对象

#### 3.1 初始化**create**对象参数说明

| 参数          | 说明                                                         | 类型    | 默认值 |
| ------------- | :----------------------------------------------------------- | ------- | ------ |
| baseUrl       | base 地址                                                    | string  | -      |
| **crypto**    | 加密对象                                                     | object  | -      |
| unEncryt      | 禁用加密，在create 实例传入将覆盖至所有接口，单个接口使用，在config添加该属性中也生效 | boolean | falase |
| **signQuery** | 签名参数配置                                                 | object  | -      |
| ……            | 其余参数均和 【[wx.request](https://developers.weixin.qq.com/miniprogram/dev/api/network/request/wx.request.html)】 配置相同 | -       | -      |

#### 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])
```

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