open-index/open-npm huggingface dataset:
npm package: @rc-component/context
Description: React way perf context selector
Latest version: 2.0.1

# @rc-component/context

---

React way perf context selector

[![NPM version][npm-image]][npm-url] [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![node version][node-image]][node-url] [![npm download][download-image]][download-url]

[npm-image]: http://img.shields.io/npm/v/@rc-component/context.svg?style=flat-square
[npm-url]: http://npmjs.org/package/@rc-component/context
[github-actions-image]: https://github.com/react-component/context/workflows/CI/badge.svg
[github-actions-url]: https://github.com/react-component/context/actions
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/context/master.svg?style=flat-square
[codecov-url]: https://app.codecov.io/gh/react-component/context
[node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square
[node-url]: http://nodejs.org/download/
[download-image]: https://img.shields.io/npm/dm/@rc-component/context.svg?style=flat-square
[download-url]: https://npmjs.org/package/@rc-component/context

## Development

```
npm install
npm start
```
npm package: @rc-component/father-plugin
Description: The father plugin for all react-component projects
Latest version: 2.1.3

# @rc-component/father-plugin

[![NPM version](https://img.shields.io/npm/v/@rc-component/father-plugin.svg?style=flat)](https://npmjs.org/package/@rc-component/father-plugin) [![NPM downloads](http://img.shields.io/npm/dm/@rc-component/father-plugin.svg?style=flat)](https://npmjs.org/package/@rc-component/father-plugin)

The father plugin for all react-component projects.

## Usage

Install this plugin in `devDependencies`:

```bash
$ npm i @rc-component/father-plugin -D
```

Register it in `.fatherrc.ts`:

```ts
import { defineConfig } from 'father';

export default defineConfig({
  plugins: ['@rc-component/father-plugin'],
});
```

## Development

```bash
$ pnpm install
```

```bash
$ npm run dev
$ npm run build
```

## LICENSE

MIT
npm package: @rc-component/mini-decimal
Description: Lite lib to only support decimal add calculation
Author: smith3816@gmail.com
Latest version: 1.1.3

# @rc-component/mini-decimal

A mini decimal calculator which only support `add`, `multi` or compare operation for mini bundle size.

[![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![npm download][download-image]][download-url]

[npm-image]: http://img.shields.io/npm/v/@rc-component/mini-decimal.svg?style=flat-square
[npm-url]: http://npmjs.org/package/@rc-component/mini-decimal
[github-actions-image]: https://github.com/react-component/mini-decimal/workflows/CI/badge.svg
[github-actions-url]: https://github.com/react-component/mini-decimal/actions
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/mini-decimal/master.svg?style=flat-square
[codecov-url]: https://codecov.io/gh/react-component/mini-decimal/branch/master
[download-image]: https://img.shields.io/npm/dm/@rc-component/mini-decimal.svg?style=flat-square
[download-url]: https://npmjs.org/package/@rc-component/mini-decimal

## Development

```bash
npm install
npm test
```

## Usage

```tsx
import getMiniDecimal from '@rc-component/mini-decimal';

// Add
getMiniDecimal('0.1').add('0.2').toString(); // 0.3

// Multi
getMiniDecimal('0.1').multi('0.2').toString(); // 0.02

// Negate
getMiniDecimal('0.1').negate().toString(); // -0.1

// Equal
getMiniDecimal('0.1').equal('0.1'); // true
getMiniDecimal('0.1').equal('0.2'); // false

// Less Equals
getMiniDecimal('0.1').lessEquals('0.2'); // true
getMiniDecimal('0.1').lessEquals('0.1'); // false
```
npm package: @rc-component/overflow
Description: Auto collapse box when overflow
Latest version: 1.0.0

# @rc-component/overflow 🐾

[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]
[![build status][github-actions-image]][github-actions-url]
[![Codecov][codecov-image]][codecov-url]
[![bundle size][bundlephobia-image]][bundlephobia-url]
[![dumi][dumi-image]][dumi-url]

[npm-image]: http://img.shields.io/npm/v/@rc-component/overflow.svg?style=flat-square
[npm-url]: http://npmjs.org/package/@rc-component/overflow
[github-actions-image]: https://github.com/react-component/overflow/workflows/CI/badge.svg
[github-actions-url]: https://github.com/react-component/overflow/actions
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/overflow/master.svg?style=flat-square
[codecov-url]: https://codecov.io/gh/react-component/overflow/branch/master
[david-url]: https://david-dm.org/react-component/overflow
[david-image]: https://david-dm.org/react-component/overflow/status.svg?style=flat-square
[david-dev-url]: https://david-dm.org/react-component/overflow?type=dev
[david-dev-image]: https://david-dm.org/react-component/overflow/dev-status.svg?style=flat-square
[download-image]: https://img.shields.io/npm/dm/@rc-component/overflow.svg?style=flat-square
[download-url]: https://npmjs.org/package/@rc-component/overflow
[bundlephobia-url]: https://bundlephobia.com/result?p=@rc-component/overflow
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/overflow
[dumi-url]: https://github.com/umijs/dumi
[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square

Auto collapse box when overflow

## Live Demo

https://overflow-react-component.vercel.app/

## Install

[![@rc-component/overflow](https://nodei.co/npm/@rc-component/overflow.png)](https://npmjs.org/package/@rc-component/overflow)

## Usage

```ts
// TODO
```

## API

| Property | Type | Default | Description |
| -------- | ---- | ------- | ----------- |

## Development

```
npm install
npm start
```

## License

@rc-component/overflow is released under the MIT license.
npm package: @rc-component/portal
Description: React Portal Component
Author: smith3816@gmail.com
Latest version: 2.2.0

# rc-portal

React 18 supported Portal Component.

[![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![npm download][download-image]][download-url]

[npm-image]: http://img.shields.io/npm/v/rc-portal.svg?style=flat-square
[npm-url]: http://npmjs.org/package/rc-portal
[github-actions-image]: https://github.com/react-component/portal/workflows/CI/badge.svg
[github-actions-url]: https://github.com/react-component/portal/actions
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/portal/master.svg?style=flat-square
[codecov-url]: https://app.codecov.io/gh/react-component/portal
[download-image]: https://img.shields.io/npm/dm/rc-portal.svg?style=flat-square
[download-url]: https://npmjs.org/package/rc-portal

## Development

```bash
npm install
npm start
open http://localhost:8000
```

## Feature

- React life cycle support portal component

## Install

[![rc-portal](https://nodei.co/npm/rc-portal.png)](https://npmjs.org/package/rc-portal)

## Usage

```js | pure
import Portal from '@rc-component/portal';

const Demo = () => {
  return <Portal open>Hello World</Portal>;
};

export default Demo;
```

## 🔥 API

We use typescript to create the Type definition. You can view directly in IDE. But you can still check the type definition [here](https://github.com/react-component/portal/blob/master/src/interface.ts).

### Portal

| Prop         | Description                        | Type                     | Default       |
| ------------ | ---------------------------------- | ------------------------ | ------------- |
| getContainer | Customize portal container element | Element \| () => Element | document.body |
| open         | Show the portal                    | boolean                  | false         |
| autoLock     | Lock screen scroll when open       | boolean                  | false         |
npm package: @rc-component/qrcode
Description: base abstract trigger component for react
Latest version: 1.1.1

# @rc-component/qrcode

React QRCode Component

[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]
[![build status][github-actions-image]][github-actions-url]
[![Test coverage][codecov-image]][codecov-url]
[![bundle size][bundlephobia-image]][bundlephobia-url]
[![dumi][dumi-image]][dumi-url]

[npm-image]: http://img.shields.io/npm/v/@rc-component/qrcode.svg?style=flat-square
[npm-url]: http://npmjs.org/package/@rc-component/qrcode
[travis-image]: https://img.shields.io/travis/react-component/qrcode/master?style=flat-square
[travis-url]: https://travis-ci.com/react-component/qrcode
[github-actions-image]: https://github.com/react-component/qrcode/workflows/CI/badge.svg
[github-actions-url]: https://github.com/react-component/qrcode/actions
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/qrcode/master.svg?style=flat-square
[codecov-url]: https://app.codecov.io/gh/react-component/qrcode
[david-url]: https://david-dm.org/react-component/qrcode
[david-image]: https://david-dm.org/react-component/qrcode/status.svg?style=flat-square
[david-dev-url]: https://david-dm.org/react-component/qrcode?type=dev
[david-dev-image]: https://david-dm.org/react-component/qrcode/dev-status.svg?style=flat-square
[download-image]: https://img.shields.io/npm/dm/@rc-component/qrcode.svg?style=flat-square
[download-url]: https://npmjs.org/package/@rc-component/qrcode
[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/qrcode
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/qrcode
[dumi-url]: https://github.com/umijs/dumi
[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square

## Install

[![@rc-component/qrcode](https://nodei.co/npm/@rc-component/qrcode.png)](https://npmjs.org/package/@rc-component/qrcode)

## Usage

## Example

http://localhost:8001

## Development

```
npm install
npm start
```

## API

### props

## API

| Name | Type | Default | Description |
| ---- | ---- | ------- | ----------- |

## Test Case

```
npm test
npm run coverage
```

open coverage/ dir

## License

rc-qrcode is released under the MIT license.

### Refs

- Util part is from [qrcode.react](https://github.com/zpao/qrcode.react) under ISC license.
- QR Code generation part is from [qrcode-generator](https://www.nayuki.io/page/qr-code-generator-library) under MIT license.

## 🤝 Contributing 

<a href="https://openomy.app/github/react-component/qrcode" target="_blank" style="display: block; width: 100%;" align="center">
  <img src="https://www.openomy.app/svg?repo=react-component/qrcode&chart=bubble&latestMonth=24" target="_blank" alt="Contribution Leaderboard" style="display: block; width: 100%;" />
</a>
npm package: @rc-component/resize-observer
Description: Resize observer for React
Latest version: 1.1.2

# rc-resize-observer

[![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![npm download][download-image]][download-url]

[npm-image]: http://img.shields.io/npm/v/rc-resize-observer.svg?style=flat-square
[npm-url]: http://npmjs.org/package/rc-resize-observer
[github-actions-image]: https://github.com/react-component/resize-observer/workflows/CI/badge.svg
[github-actions-url]: https://github.com/react-component/resize-observer/actions
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/resize-observer/master.svg?style=flat-square
[codecov-url]: https://codecov.io/gh/react-component/resize-observer/branch/master
[download-image]: https://img.shields.io/npm/dm/rc-resize-observer.svg?style=flat-square
[download-url]: https://npmjs.org/package/rc-resize-observer

Resize observer for React.

## Live Demo

https://resize-observer-react-component.vercel.app/

## Install

[![rc-resize-observer](https://nodei.co/npm/rc-resize-observer.png)](https://npmjs.org/package/rc-resize-observer)

## Usage

```js
import ResizeObserver from 'rc-resize-observer';
import { render } from 'react-dom';

render(
  <ResizeObserver
    onResize={() => {
      console.log('resized!');
    }}
  >
    <textarea />
  </ResizeObserver>,
  mountNode,
);
```

## API

| Property | Type                        | Default | Description                     |
| -------- | --------------------------- | ------- | ------------------------------- |
| disabled | boolean                     | false   |                                 |
| onResize | ({ width, height }) => void | -       | Trigger when child node resized |

## Development

```
npm install
npm start
```

## License

rc-resize-observer is released under the MIT license.
npm package: @rc-component/textarea
Description: Pretty Textarea react component used in used in ant.design
Latest version: 1.2.0

# rc-textarea

[![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![npm download][download-image]][download-url] [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![bundle size][bundlephobia-image]][bundlephobia-url]

[npm-image]: http://img.shields.io/npm/v/rc-textarea.svg?style=flat-square
[npm-url]: http://npmjs.org/package/rc-textarea
[github-actions-image]: https://github.com/react-component/textarea/workflows/CI/badge.svg
[github-actions-url]: https://github.com/react-component/textarea/actions
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/textarea/master.svg?style=flat-square
[codecov-url]: https://codecov.io/gh/react-component/textarea/branch/master
[download-image]: https://img.shields.io/npm/dm/rc-textarea.svg?style=flat-square
[download-url]: https://npmjs.org/package/rc-textarea
[bundlephobia-url]: https://bundlephobia.com/result?p=rc-textarea
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-textarea

Pretty Textarea react component used in [ant.design](https://ant.design).

## Live Demo

https://react-component.github.io/textarea/

## Install

[![rc-textarea](https://nodei.co/npm/rc-textarea.png)](https://npmjs.org/package/rc-textarea)

## Usage

```js
import Textarea from 'rc-textarea';
import { render } from 'react-dom';

render(<Textarea />, mountNode);
```

## API

| Property     | Type                        | Default     | Description                                                                                    |
| ------------ | --------------------------- | ----------- | ---------------------------------------------------------------------------------------------- |
| prefixCls    | string                      | rc-textarea |                                                                                                |
| className    | string                      | ''          | additional class name of textarea                                                              |
| style        | React.CSSProperties         | -           | style properties of textarea                                                                   |
| autoSize     | boolean \| object           | -           | Height autosize feature, can be set to `true\|false` or an object `{ minRows: 2, maxRows: 6 }` |
| onPressEnter | function(e)                 | -           | The callback function that is triggered when Enter key is pressed                              |
| onResize     | function({ width, height }) | -           | The callback function that is triggered when resize                                            |

## Development

```
npm install
npm start
```

## License

rc-textarea is released under the MIT license.
npm package: @rc-design/core
Description: rc-design 是一个基于 react 的 UI 组件库
Latest version: 0.0.3

# rc-design

<img src="/public/logo.png"/>

rc-design，是一款为 react 开发的组件库，为开发者提供更轻量、简洁的组件库选择。使用 tsx 编写逻辑，less 编写样式，dumi2 编写文档站，jest+ts-jest+react-testing-library 单元测试。

## 开始使用

### 下载安装

```shell
npm install @rc-design/core
```

### 如何引入

请务必注意，rc-design 目前没有实现按需引入样式，所以请用户**手动导入全局样式**

```js
// bad:
import { Button } from '@rc-design/core';
// good: tree-shaking
import Button from '@rc-design/core/dist/button';
import '@rc-design/core/dist/index.css';
```

把 Button 换成需要的组件。

## 问题反馈

如果在使用过程中发现任何问题，欢迎在 GitHub Issues 进行反馈：https://github.com/Sunny-117/rc-design/issues
npm package: @rc-essential/keep-alive
Description: 基于react18模拟vue的keep-alive组件，实现页面/组件的状态保存
Author: wenzhen
Latest version: 1.0.6

# react-keep-alive
基于react18模拟vue的keep-alive组件，实现页面/组件的状态保存

## 安装
```bash
pnpm add @rc-essential/keep-alive
```

## 使用
### 基于react-router-dom路由页面缓存
```tsx
import '@rc-essential/keep-alive/dist/style.css'
import { KeepProvider, KeepAlive } from '@rc-essential/keep-alive'
import { useLocation, useOutlet } from 'react-router-dom'

const BasicLayoutWidthCache = () => {
  const outlet = useOutlet()
  const location = useLocation()
  
  /**
   * 用于区分不同页面以进行缓存
   */
  const cacheKey = useMemo(() => {
    return location.pathname + location.search
  }, [location])

  return (
    <div>
      <KeepAlive activeName={cacheKey}>{outlet}</KeepAlive>
    </div>
  )
}
```
### useActivated/useDeactivated
useActivated: 用于监听被KeepAlive包装的组件的激活状态。
useDeactivated: 用于监听被KeepAlive包装的组件的失活状态。

```tsx
  import { useActivated } from '@rc-essential/keep-alive'
    /**
     * 用于区分不同页面以进行缓存
     */
    const cacheKey = useMemo(() => {
      return location.pathname + location.search;
    }, [location])
  useActivated(cacheKey, () => {
    console.log('useActivated', cacheKey);
  })
```
npm package: @rc-ex/authorize-uri
Description: Authorize URI extension for ringcentral-extensible project
Author: Tyler Liu
Latest version: 2.1.0

# Authorize URI Extension

Generate Authorize URI.

## Install

```
yarn add @rc-ex/authorize-uri
```

## Usage

```ts
import RingCentral from '@rc-ex/core';
import AuthorizeUriExtension from '@rc-ex/authorize-uri';

const rc = new RingCentral(...);
const authorizeUriExtension = new AuthorizeUriExtension();
await rc.installExtension(authorizeUriExtension);
const authorizeUri = authorizeUriExtension.buildUri({
  state: 'hello',
  redirect_uri: 'https://example.com',
});
```

For a working sample, please check this
[test case](../../../test/authorize-uri-extension.spec.ts).

## PKCE

Ref:
https://medium.com/ringcentral-developers/use-authorization-code-pkce-for-ringcentral-api-in-client-app-e9108f04b5f0

First and foremost, you should not specify client secret in your project, that's
the whole point of PKCE.

Secondly, specify `code_challenge_method: 'S256'`:

```ts
const authorizeUri = authorizeUriExtension.buildUri({
  state: "hello",
  redirect_uri: "https://example.com",
  code_challenge_method: "S256",
});
```

And you should save the `codeVerifier`:

```ts
const codeVerifier = authorizeUriExtension.codeVerifier;
```

You may need to persist `codeVerifier` in case browser web page refreshes.

And when you make the authorize API call, remember to specify `code_verifier`:

```ts
await rc.authorize({
  code: "...",
  redirect_uri: "...",
  code_verifier: codeVerifier,
});
```

### PKCE demo

- [Online demo](https://chuntaoliu.com/pkce-demo-ts/)
- [Source code](https://github.com/tylerlong/pkce-demo-ts)

## Base Authorization URI

Optionally, you can specify `baseAuthorizationUri` as parameter to the
constructor of this extension. If it's not specified,
`${rc.rest.server}/restapi/oauth/authorize` is used as `baseAuthorizationUri`.
npm package: @rc-ex/auto-refresh
Description: Auto Refresh extension for ringcentral-extensible project
Author: Tyler Liu
Latest version: 0.4.0

# Auto Refrsh Extension

This extension will auto refresh your token every 30 minutes(customizable).

## Install

```
yarn add @rc-ex/auto-refresh
```

## Usage

```ts
import RingCentral from '@rc-ex/core';
import AutoRefreshExtension from '@rc-ex/auto-refresh';

const rc = new RingCentral(...);
const autoRefreshExtension = new AutoRefreshExtension();
await rc.installExtension(autoRefreshExtension);
autoRefreshExtension.start();
// autoRefreshExtension.stop();
```

For a working sample, please check this
[test case](../../../test/auto-refresh-extension.spec.ts).

## Disclaimer

[Token management](https://medium.com/ringcentral-developers/ringcentral-token-management-477578f00954)
is a complicated topic. There is no one-fit-all solution. This extension is an
quick-and-dirty out-of-box solution to refresh your token. It is by no means the
best practice. It simply starts a background timers to refresh your token
periodically. For serious production applications, you may need better token
management strategy.
npm package: @rc-ex/debug
Description: Debug extension for ringcentral-extensible project
Author: Tyler Liu
Latest version: 1.4.0

# Debug Extension

Provide debug mode for this SDK.

## Install

```
yarn add @rc-ex/debug
```

## Usage

```ts
import RingCentral from '@rc-ex/core';
import DebugExtension from '@rc-ex/debug';

const rc = new RingCentral(...);
const debugExtension = new DebugExtension();
await rc.installExtension(debugExtension);
```

With this extension installed, details for every API request traffic will be
printed using `console.debug`.

Below is sample output for
`await rc.restapi().account().extension().messageStore().list()`:

```
console.debug
HTTP 200 OK

Response:
{
    "data": {
    "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/233676004/extension/233676004/message-store?availability=Alive&dateFrom=2020-06-03T01:35:00.000Z&page=1&perPage=100",
    "records": [],
    "paging": {
        "page": 1,
        "totalPages": 1,
        "perPage": 100,
        "totalElements": 0
    },
    "navigation": {
        "firstPage": {
        "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/233676004/extension/233676004/message-store?availability=Alive&dateFrom=2020-06-03T01:35:00.000Z&page=1&perPage=100"
        },
        "lastPage": {
        "uri": "https://platform.devtest.ringcentral.com/restapi/v1.0/account/233676004/extension/233676004/message-store?availability=Alive&dateFrom=2020-06-03T01:35:00.000Z&page=1&perPage=100"
        }
    }
    },
    "status": 200,
    "statusText": "OK",
    "headers": {
    "server": "nginx",
    "date": "Thu, 04 Jun 2020 01:34:47 GMT",
    "content-type": "application/json;charset=utf-8",
    "content-length": "779",
    "connection": "close",
    "rcrequestid": "9379f134-a603-11ea-899e-005056bbcdd9",
    "routingkey": "SJC11P01PAS02",
    "content-language": "en-US",
    "vary": "Accept-Encoding, User-Agent",
    "x-rate-limit-group": "light",
    "x-rate-limit-limit": "100",
    "x-rate-limit-remaining": "99",
    "x-rate-limit-window": "60"
    }
}

Request:
{
    "method": "get",
    "baseURL": "https://platform.devtest.ringcentral.com",
    "url": "/restapi/v1.0/account/~/extension/~/message-store",
    "headers": {
    "Accept": "application/json, text/plain, */*",
    "X-User-Agent": "Unknown/0.0.1 ringcentral-extensible/core/0.5.5",
    "Authorization": "Bearer U0pDMTFQMDFQQVMwMHxBQUFmUXE0dG9FbTBBNll2eDlWYUhoNkQyblBWVXlXZnc0b0VxWldtVjNTZkw1MGExNG8wbHdscU4tOVEwU1RiWU9IYUt3NUY2Y2lVQk9oaDE4amlSN2VqTDl0VlhNMnZNYzVOa1FLZWJyejJRRDk3VnFESkdIV3k2U1RuU28zeG52RHlPdW5OcXFIR3FkbU1IQWhTaUluY0psN3A2ckQxbEhPRG1MdkIxX0FpSlhQeXlES2tYaURWejkwWFdiVjlfQXxrRjF4RVF8S1BrdVJvLVhBMlhIMXdlcnV6VVdjd3xBUQ",
    "User-Agent": "axios/0.19.2"
    }
}
```

For a working sample, please check this
[test case](../../../test/debug-extension.spec.ts).

## loggingAction

Optionally, you can specify a `loggingAction` function to the extension
constructor.

```ts
export type LoggingAction = (message: string) => void;
```

`loggingAction` determines how debug messages are logged. By default it is:

```ts
((message) => console.debug(message));
```
npm package: @rc-ex/discovery
Description: Discovery extension for ringcentral-extensible project
Author: Tyler Liu
Latest version: 1.1.3

# Discovery Extension

Entry Point Discovery.


## Install

```
yarn add @rc-ex/discovery
```


## Usage

```ts
import RingCentral from '@rc-ex/core';
import DiscoveryExtension from '@rc-ex/discovery';

const rc = new RingCentral();
// install Discovery Extension
const discoveryExtension = new DiscoveryExtension({
    discoveryServer: process.env.RINGCENTRAL_DISCOVERY_SERVER!,
    brandId: '1210',
});
rc.installExtension(discoveryExtension);
await discoveryExtension.discover(); // discover entry points

console.log(discoveryExtension.initialEntryPoints)

// Then you don't have to manually configure the platform API server
```

### With @ringcentral/sdk

```ts
const rc = new RingCentral();

// install Discovery Extension
const discoveryExtension = new DiscoveryExtension({
    discoveryServer: process.env.RINGCENTRAL_DISCOVERY_SERVER!,
    brandId: '1210',
});
rc.installExtension(discoveryExtension);
await discoveryExtension.discover(); // discover entry points

// install RingCentral Extension
const sdk = new SDK({
    clientId: process.env.RINGCENTRAL_CLIENT_ID!,
    clientSecret: process.env.RINGCENTRAL_CLIENT_SECRET!,
    server: discoveryExtension.initialEntryPoints!.coreApi.baseUri, // use the discovered entry point
});
await sdk.login({
    username: process.env.RINGCENTRAL_USERNAME!,
    extension: process.env.RINGCENTRAL_EXTENSION!,
    password: process.env.RINGCENTRAL_PASSWORD!,
});
const ringCentralExtension = new RingCentralExtension(sdk);
await rc.installExtension(ringCentralExtension);

const extInfo = await rc.restapi().account().extension().get();
```
npm package: @rc-ex/engage-voice
Description: Engage Voice extension for ringcentral-extensible project
Author: Tyler Liu
Latest version: 0.3.7

# Engage Voice Extension

Engage Voice Extension adds support for RingCentral Engage Voice API.


## Install

```
yarn add @rc-ex/engage-voice
```


## Usage

```ts
import RingCentral from '@rc-ex/core';
import EngageVoiceExtension from '@rc-ex/engage-voice';

const rc = new RingCentral(...);
const engageVoiceExtension = new EngageVoiceExtension();
await rc.installExtension(engageVoiceExtension);

await rc.authorize(...);
await engageVoiceExtension.authorize();

const r = await engageVoiceExtension.get('/voice/api/v1/admin/accounts');
console.log(r.data);
```


## To generate code

Rename `.env.sample` to `.env` and specify the EV spec file.

```
yarn lerna run generate --scope=@rc-ex/engage-voice
```
npm package: @rc-ex/events
Description: Events extension for ringcentral-extensible project
Author: Tyler Liu
Latest version: 1.4.0

# Events Extension

This extension emits API call related events.

## Install

```
yarn add @rc-ex/events
```

## Usage

```ts
import RingCentral from '@rc-ex/core';
import EventsExtension, {Events} from '@rc-ex/events';

const rc = new RingCentral(...);
const eventsExtension = new EventsExtension(eventsOptions);
await rc.installExtension(eventsExtension);

eventsExtension.eventEmitter.on(Events.requestSuccess, r => {
  console.log(`There is a request error: ${r}`)
})
```

For a working sample, please check this
[test case](../../../test/events-extension.spec.ts).

## EventsOptions

`EventsExtension` constructor accepts optional `EventsOptions` as parameter:

```ts
type EventsOptions = {
  enabledEvents?: Events[];
};
```

### enabledEvents

`enabledEvents` specifies which events are enabled:

```ts
enum Events {
  beforeRequest = "beforeRequest",
  requestSuccess = "requestSuccess",
  requestError = "requestError",

  // enum values below are from
  // https://github.com/ringcentral/ringcentral-js/blob/master/sdk/src/platform/Platform.ts
  beforeLogin = "beforeLogin",
  loginSuccess = "loginSuccess",
  loginError = "loginError",
  beforeRefresh = "beforeRefresh",
  refreshSuccess = "refreshSuccess",
  refreshError = "refreshError",
  beforeLogout = "beforeLogout",
  logoutSuccess = "logoutSuccess",
  logoutError = "logoutError",
  rateLimitError = "rateLimitError",
}
```

If you don't specify this parameter, all events are enabled by default.
npm package: @rc-ex/pubnub
Description: PubNub extension for ringcentral-extensible project
Author: Tyler Liu
Latest version: 1.1.15

# PubNub Extension

PubNub Extension adds PubNub notifications feature.

It is deprecated. Please use [WebSocket Extension](../ws) instead.

## Install

```
yarn add @rc-ex/pubnub
```

## Usage

```ts
import RingCentral from '@rc-ex/core';
import PubNubExtension from '@rc-ex/pubnub';

const rc = new RingCentral(...);
const pubNubExtension = new PubNubExtension();
await rc.installExtension(pubNubExtension);

const subscription = await pubNubExtension.subscribe(
    ['/restapi/v1.0/account/~/extension/~/message-store'],
    message => {
       ...
    }
);
```

## Known issue

The last pubnub version I tested is 7.3.3. I confirmed that it worked.

However, after I upgrade to pubnub 7.4.x, it stopped working. I don't know why.

We are not going to spend time on it any more because pubnub support is deprecated.
npm package: @rc-ex/rate-limit
Description: Rate limit extension for ringcentral-extensible project
Author: Tyler Liu
Latest version: 1.4.0

# Rate Limit Extension

Rate limit extension handles rate limit automatically by delaying and retrying
API calls.

This extension is based on the [Retry Extension](../retry).

## Install

```
yarn add @rc-ex/rate-limit
```

## Usage

```ts
import RingCentral from '@rc-ex/core';
import RateLimitExtension from '@rc-ex/rate-limit';

const rc = new RingCentral(...);
const rateLimitExtension = new RateLimitExtension(rateLimitOptions);
await rc.installExtension(rateLimitExtension);
```

## RateLimitOptions

`RetryExtension` constructor accepts optional `RateLimitOptions` as parameter:

```ts
type RateLimitOptions = {
  maxRetries?: number;
  rateLimitWindow?: number;
};
```

### maxRetries

`maxRetries` defines maximum times of retries before aborting.

Default value is 3.

### rateLimitWindow

`rateLimitWindow` defines the rate limit window. This parameter will only take
effect when there is no `x-rate-limit-window` HTTP header available.

Default value is 60 (seconds).

Its value is used to determine the
[retryInterval](https://github.com/ringcentral/ringcentral-extensible/tree/master/packages/extensions/retry#retryinterval).
npm package: @rc-ex/rcsdk
Description: @ringcentral/sdk extension for ringcentral-extensible project
Author: Tyler Liu
Latest version: 1.5.0

# RingCentral SDK extension

This extension makes
[@ringcentral/sdk](https://www.npmjs.com/package/@ringcentral/sdk) the HTTP
engine.

## Install

```
yarn add @rc-ex/rcsdk
```

## Usage

```ts
import SDK from "@ringcentral/sdk";
import RingCentral from "@rc-ex/core";
import RcSdkExtension from "@rc-ex/rcsdk";

// @ringcentral/sdk
const sdk = new SDK({ clientId, clientSecret, server });
await sdk.login({ username, extension, password });

// ringcentral-extensible + rcsdk extension
const rc = new RingCentral();
const rcSdkExtension = new RcSdkExtension({ rcSdk: sdk });
await rc.installExtension(rcSdkExtension);

// API call with @ringcentral/sdk as HTTP engine
const extensionInfo = await rc.restapi().account().extension().get();
```

For a working sample, please check this
[test case](../../../test/rcsdk-extension.spec.ts).

## Known issues

`multipart/form-data` does not work, because `@rc-ex/core` is originally
designed for [axios](https://github.com/axios/axios). For such cases, please use
`@ringcentral/sdk` directly, such as
`await sdk.post('/restapi/v1.0/account/~/extension/~/fax', ...);`

Some extensions don't work with this extension. For example, the Retry Extension
and RateLimit Extension because they rely on RestException object which
`@ringcentral/sdk` doesn't throw.

## Switch between @ringcentral/sdk and axios

[axios][https://github.com/axios/axios] is the default HTTP engine. This
extension makes `@ringcentral/sdk` as HTTP engine. to switch back to `axios`,
just disable this extension:

```ts
// ringcentral-extensible + rcsdk extension
const rc = new RingCentral({...});
const rcSdkExtension = new RcSdkExtension({rcSdk: sdk});
await rc.installExtension(rcSdkExtension);

// API call with @ringcentral/sdk as HTTP engine
const extensionInfo = await rc.restapi().account().extension().get();

rcSdkExtension.disable();
// API call with axios as HTTP engine
const extensionInfo2 = await rc.restapi().account().extension().get();
```

Please note that by default `@ringcentral/sdk` and `axios` doesn't share tokens.
You may need to manage tokens separately. Or you can make them share tokens
explicitly by getting token from one and setting to the other.
npm package: @rc-ex/retry
Description: Retry extension for ringcentral-extensible project
Author: Tyler Liu
Latest version: 1.4.0

# Retry Extension

Retry API calls upon `RestException`

## Install

```
yarn add @rc-ex/retry
```

## Usage

```ts
import RingCentral from '@rc-ex/core';
import RetryExtension from '@rc-ex/retry';

const rc = new RingCentral(...);
const retryExtension = new RetryExtension(retryOptions);
await rc.installExtension(retryExtension);
```

## Options

### RetryOptions

`RetryExtension` constructor accepts optional `RetryOptions` as parameter:

```ts
type RetryOptions = {
  shouldRetry?: ShouldRetry;
  retryInterval?: RetryInterval;
};
```

### ShouldRetry

`ShouldRetry` defines condition about should retry or abort:

```ts
type ShouldRetry = (
  restException: RestException,
  retriesAttempted: number,
) => boolean;
```

By default, `ShouldRetry` returns true when `restException.response.status` is
429 or 503 and `retriesAttempted` is smaller than 3:

```ts
((restException, retriesAttempted) => {
  return retriesAttempted < 3 &&
    [429, 503].includes(restException.response.status);
});
```

### RetryInterval

`RetryInterval` defines how long should wait before try:

```ts
type RetryInterval = (
  restException: RestException,
  retriesAttempted: number,
) => number;
```

By default `RetryInterval` is 60 seconds with exponential back off:

```ts
((restException, retriesAttempted) => {
  return 60 * 1000 * Math.pow(2, retriesAttempted); // exponential back off
});
```
npm package: @rc-ex/ws-legacy
Description: Legacy WebSocket extension for ringcentral-extensible project
Author: Tyler Liu
Latest version: 0.4.9

# WebSocket Extension (legacy and deprecated)

WebSocket Extension adds support for WebSocket protocol.


## Install

```
yarn add @rc-ex/ws-legacy
```


## Usage

```ts
import RingCentral from '@rc-ex/core';
import WebSocketExtension from '@rc-ex/ws-legacy';

const rc = new RingCentral(...);
const webSocketExtension = new WebSocketExtension(webSocketOptions);
await rc.installExtension(webSocketExtension);
```

You can setup subscriptions:

```ts
await webSocketExtension.subscribe(
    ['/restapi/v1.0/account/~/extension/~/message-store'],
    event => {
       ...
    }
);
```

You can also make Rest API calls over WebSocket if you specified `webSocketOptions.restOverWebSocket` as `true`:

```ts
const webSocketExtension = new WebSocketExtension({
  server: '...',
  restOverWebSocket: true
});
await rc.installExtension(webSocketExtension);

const extInfo = await rc.restapi().account().extension().get();
console.log(extInfo.id);
```


## WebSocketOptions

`WebSocketExtension` constructor requires `WebSocketOptions` as parameter:


```ts
type WebSocketOptions = {
  server: string;
  restOverWebSocket?: boolean;
};
```


### server

`server` defines WebSocket server uri.

For sandbox it is `wss://ws-api.devtest.ringcentral.com/ws` while for production it is `wss://ws-api.ringcentral.com/ws`.

You may have different server uri depending on your testing/running environment.


### restOverWebSocket

`restOverWebSocket` indicates whether to make Rest API call over WebSocket protocol.

Default value is false.

Please note that, not all Rest API calls can be done over WebSocket protocol. The following are not supported at the moment:

- Binary downloading
- `form-data/multipart` POST / PUT
- Authorization, such as get token and revoke token

If `restOverWebSocket` is true and an Rest API call cannot be done over WebSocket, it will be done over HTTPS instead.