Skip to content

Commit

Permalink
Fix all code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlong committed Sep 25, 2023
1 parent 9cc4152 commit 43aba38
Show file tree
Hide file tree
Showing 1,454 changed files with 14,088 additions and 10,505 deletions.
24 changes: 9 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
RingCentral Extensible is a SDK with a tiny core and lots of extensions.
It is an endeavour to get rid of bloated SDK. You install extensions on demand.


## Getting help and support

If you are having difficulty using this SDK, or working with the RingCentral API, please visit our [developer community forums](https://community.ringcentral.com/spaces/144/) for help and to get quick answers to your questions. If you wish to contact the RingCentral Developer Support team directly, please [submit a help ticket](https://developers.ringcentral.com/support/create-case) from our developer website.


## Installation

```
Expand All @@ -23,21 +21,18 @@ Then you should be able to import the SDK like this:
import RingCentral from '@rc-ex/core';
```


## Usage

#### [Sample code for all endpoints](./packages/core/src/samples.md)

You can also find lots of useful code snippets from [test cases](./test).


## [Extensions](./packages/extensions)

This SDK supports [extensions](./packages/extensions). You can enable features by installing extensions.

If you want to add features to this SDK, create an extension.


## Logging

The logging implementation copies [AWS SDK logging](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/logging-sdk-calls.html).
Expand Down Expand Up @@ -72,7 +67,6 @@ Sample log entries:

[A demo application printing logs to console](https://github.com/tylerlong/rc-logging-demo-ts).


## Binary content downloading

Some [sample code](./packages/core/src/samples.md) for binary content downloading may not work.
Expand All @@ -83,15 +77,21 @@ For example, to download the attachment of a fax:

```ts
// `message` is the fax message object
const r = await rc.get(message.attachments[0].uri, undefined, { responseType: 'arraybuffer' })
const content = r.data
const r = await rc.get(message.attachments[0].uri, undefined, { responseType: 'arraybuffer' });
const content = r.data;
```

The following does **NOT** work:

```ts
// `message` is the fax message object
const content = await rc.restapi().account().extension().messageStore(message.id).content(message.attachments[0].id).get()
const content = await rc
.restapi()
.account()
.extension()
.messageStore(message.id)
.content(message.attachments[0].id)
.get();
```

### Rule of thumb
Expand All @@ -100,28 +100,24 @@ But not all binary content has been migrated to CDN.
If the resource to download provides you with a CDN uri, use that CDN uri.
If there is no CDN uri provided, construct the uri as [sample code](./packages/core/src/samples.md) shows.


## For maintainers

### Regenerate code using latest swagger spec

Please refer to the [RingCentral Code Generator](https://github.com/tylerlong/ringcentral-code-generator-typescript) project.


### Test

```
yarn reset && yarn compile && yarn test
```


### Test one test case

```
t=auto-recover yarn test
```


## Publish

Update version number in `packages/core/src/Rest.ts`
Expand All @@ -137,14 +133,12 @@ By default lerna check git tag to determine which packages to publish.

I don't know how to make it work with lerna and I have to disable it via npmjs.com GUI: I disabled "Require two-factor authentication for write actions".


## Add dependency

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


### Todo

- Extension to refresh token
Expand Down
6 changes: 1 addition & 5 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"version": "independent",
"npmClient": "yarn",
"packages": [
"packages/core",
"packages/extensions/*",
"test"
]
"packages": ["packages/core", "packages/extensions/*", "test"]
}
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
{
"name": "ringcentral-extensible",
"license": "MIT",
"version": "0.1.0",
"private": "true",
"description": "RingCentral Extensible SDK",
"license": "MIT",
"workspaces": [
"packages/core",
"packages/extensions/*",
"test"
],
"scripts": {
"compile": "lerna exec tsc --scope=@rc-ex/core && lerna exec tsc --no-private --ignore=@rc-ex/core",
"lint": "eslint --fix '**/*.{ts,tsx,js,jsx}' && prettier --write . && sort-package-json",
"test": "yarn workspace @rc-ex/test run jest -w 1 --detectOpenHandles -c jest.config.ts $t",
"upgrade-all": "yarn-upgrade-all -W && yarn workspaces run yarn-upgrade-all && yarn install",
"prepublishOnly": "yarn reset && yarn compile",
"reset": "lerna exec 'rm -rf lib'",
"compile": "lerna exec tsc --scope=@rc-ex/core && lerna exec tsc --no-private --ignore=@rc-ex/core",
"prepublishOnly": "yarn reset && yarn compile"
"test": "yarn workspace @rc-ex/test run jest -w 1 --detectOpenHandles -c jest.config.ts $t",
"upgrade-all": "yarn-upgrade-all -W && yarn workspaces run yarn-upgrade-all && yarn install"
},
"description": "RingCentral Extensible SDK",
"devDependencies": {
"@types/node": "^20.6.0",
"@typescript-eslint/eslint-plugin": "^6.7.0",
Expand All @@ -27,10 +32,5 @@
"ttpt": "^0.6.6",
"typescript": "^5.2.2",
"yarn-upgrade-all": "^0.7.2"
},
"workspaces": [
"packages/core",
"packages/extensions/*",
"test"
]
}
}
1 change: 0 additions & 1 deletion packages/core/code-generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import generate from 'ringcentral-code-generator';
import path from 'path';

Expand Down
17 changes: 7 additions & 10 deletions packages/core/src/FormData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stream } from 'stream';
import type { Stream } from 'stream';

import { FormFile } from './types';
import type { FormFile } from './types';

async function stream2buffer(stream: Stream): Promise<Buffer> {
return new Promise<Buffer>((resolve, reject) => {
Expand All @@ -13,17 +13,17 @@ async function stream2buffer(stream: Stream): Promise<Buffer> {

export const boundary = 'ad05fc42-a66d-4a94-b807-f1c91136c17b';
class FormData {
files: FormFile[] = [];
public files: FormFile[] = [];

append(formFile: FormFile) {
public append(formFile: FormFile) {
this.files.push(formFile);
}

prepend(formFile: FormFile) {
public prepend(formFile: FormFile) {
this.files.unshift(formFile);
}

async getBody() {
public async getBody() {
let buffer = Buffer.alloc(0);
for (const formFile of this.files) {
let temp = `--${boundary}\r\n`;
Expand All @@ -43,10 +43,7 @@ class FormData {
}
buffer = Buffer.concat([buffer, fileBuffer]);
}
return Buffer.concat([
buffer,
Buffer.from(`\r\n--${boundary}--\r\n`, 'utf8'),
]);
return Buffer.concat([buffer, Buffer.from(`\r\n--${boundary}--\r\n`, 'utf8')]);
}
}

Expand Down
42 changes: 17 additions & 25 deletions packages/core/src/Rest.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
import axios, {
AxiosInstance,
} from 'axios';
import type { AxiosInstance } from 'axios';
import axios from 'axios';
import qs from 'qs';
import { boundary } from './FormData';

import RestException from './RestException';
import TokenInfo from './definitions/TokenInfo';
import {
RestMethod,
RestOptions,
RestRequestConfig,
RestResponse,
} from './types';
import type TokenInfo from './definitions/TokenInfo';
import type { RestMethod, RestOptions, RestRequestConfig, RestResponse } from './types';

const version = '1.3.3';

export default class Rest {
static sandboxServer = 'https://platform.devtest.ringcentral.com';
public static sandboxServer = 'https://platform.devtest.ringcentral.com';

static productionServer = 'https://platform.ringcentral.com';
public static productionServer = 'https://platform.ringcentral.com';

server: string;
public server: string;

clientId: string;
public clientId: string;

clientSecret?: string;
public clientSecret?: string;

token?: TokenInfo;
public token?: TokenInfo;

appName: string;
public appName: string;

appVersion: string;
public appVersion: string;

httpClient: AxiosInstance;
public httpClient: AxiosInstance;

constructor(options: RestOptions) {
public constructor(options: RestOptions) {
this.server = options.server ?? Rest.sandboxServer;
this.clientId = options.clientId ?? '';
this.clientSecret = options.clientSecret;
Expand Down Expand Up @@ -63,7 +57,8 @@ export default class Rest {
});
}

async request<T>(
// eslint-disable-next-line max-params
public async request<T>(
method: RestMethod,
endpoint: string,
content?: {},
Expand All @@ -79,10 +74,7 @@ export default class Rest {
...config,
};
// /restapi/oauth/wstoken uses bearer token
if (
endpoint === '/restapi/oauth/token'
|| endpoint === '/restapi/oauth/revoke'
) {
if (endpoint === '/restapi/oauth/token' || endpoint === '/restapi/oauth/revoke') {
if (this.clientSecret) {
// basic token
newConfig.auth = {
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/RestException.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { RestResponse } from './types';
import type { RestResponse } from './types';
import Utils from './Utils';

class RestException extends Error {
response: RestResponse;
public response: RestResponse;

message: string;
public message: string;

constructor(r: RestResponse) {
public constructor(r: RestResponse) {
const message = Utils.formatTraffic(r);
super(message);
Object.setPrototypeOf(this, RestException.prototype);
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/SdkExtension.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { RingCentralInterface } from './types';
import type { RingCentralInterface } from './types';

abstract class SdkExtension {
enabled = true;
public enabled = true;

enable() {
public enable() {
this.enabled = true;
}

disable() {
public disable() {
this.enabled = false;
}

abstract install(rc: RingCentralInterface): Promise<void>;
abstract revoke(): Promise<void>;
public abstract install(rc: RingCentralInterface): Promise<void>;
public abstract revoke(): Promise<void>;
}

export default SdkExtension;
Loading

0 comments on commit 43aba38

Please sign in to comment.