Skip to content

Commit

Permalink
Deno fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlong committed Jan 24, 2025
1 parent 05e463a commit e3dace5
Show file tree
Hide file tree
Showing 1,329 changed files with 14,048 additions and 10,391 deletions.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

9 changes: 0 additions & 9 deletions .eslintrc.js

This file was deleted.

34 changes: 17 additions & 17 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@ name: Node.js

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:
environment: prod
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 21.x
- run: yarn install
- run: yarn reset
- run: yarn compile
- run: yarn test
env:
RINGCENTRAL_SERVER_URL: ${{ secrets.RINGCENTRAL_SERVER_URL }}
RINGCENTRAL_CLIENT_ID: ${{ secrets.RINGCENTRAL_CLIENT_ID }}
RINGCENTRAL_CLIENT_SECRET: ${{ secrets.RINGCENTRAL_CLIENT_SECRET }}
RINGCENTRAL_JWT_TOKEN: ${{ secrets.RINGCENTRAL_JWT_TOKEN }}
RINGCENTRAL_SENDER: ${{ secrets.RINGCENTRAL_SENDER }}
RINGCENTRAL_RECEIVER: ${{ secrets.RINGCENTRAL_RECEIVER }}
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 21.x
- run: yarn install
- run: yarn reset
- run: yarn compile
- run: yarn test
env:
RINGCENTRAL_SERVER_URL: ${{ secrets.RINGCENTRAL_SERVER_URL }}
RINGCENTRAL_CLIENT_ID: ${{ secrets.RINGCENTRAL_CLIENT_ID }}
RINGCENTRAL_CLIENT_SECRET: ${{ secrets.RINGCENTRAL_CLIENT_SECRET }}
RINGCENTRAL_JWT_TOKEN: ${{ secrets.RINGCENTRAL_JWT_TOKEN }}
RINGCENTRAL_SENDER: ${{ secrets.RINGCENTRAL_SENDER }}
RINGCENTRAL_RECEIVER: ${{ secrets.RINGCENTRAL_RECEIVER }}
4 changes: 0 additions & 4 deletions .prettierignore

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierrc.js

This file was deleted.

45 changes: 30 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

[![Build Status](https://github.com/ringcentral/ringcentral-extensible/actions/workflows/node.js.yml/badge.svg)](https://github.com/ringcentral/ringcentral-extensible/actions)

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.
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.
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 @@ -18,7 +24,7 @@ yarn add @rc-ex/core
Then you should be able to import the SDK like this:

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

## Usage
Expand All @@ -29,13 +35,15 @@ 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.
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).
The logging implementation copies
[AWS SDK logging](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/logging-sdk-calls.html).

To enable logging:

Expand All @@ -46,7 +54,7 @@ RingCentral.config.logger = console;
Or you could use a third-party logger:

```ts
import winston from 'winston';
import winston from "winston";

const logger = winston.createLogger({
transports: [
Expand All @@ -69,15 +77,19 @@ Sample log entries:

## Binary content downloading

Some [sample code](./packages/core/src/samples.md) for binary content downloading may not work.
Some [sample code](./packages/core/src/samples.md) for binary content
downloading may not work.

Because RingCentral is gradually migrating binary content to CDN such as `media.ringcentral.com`.
Because RingCentral is gradually migrating binary content to CDN such as
`media.ringcentral.com`.

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 r = await rc.get(message.attachments[0].uri, undefined, {
responseType: "arraybuffer",
});
const content = r.data;
```

Expand All @@ -96,15 +108,17 @@ const content = await rc

### Rule of thumb

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.
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.
Please refer to the
[RingCentral Code Generator](https://github.com/tylerlong/ringcentral-code-generator-typescript)
project.

### Test

Expand Down Expand Up @@ -133,7 +147,8 @@ As I just tried, it works without `from-package` option.

### NPM 2FA

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".
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

Expand Down
14 changes: 1 addition & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,19 @@
],
"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",
"prepublishOnly": "yarn reset && yarn compile",
"reset": "lerna exec 'rm -rf lib'",
"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"
},
"devDependencies": {
"@types/node": "^22.10.7",
"@typescript-eslint/eslint-plugin": "^8.20.0",
"@typescript-eslint/parser": "^8.20.0",
"eslint": "^8.57.0",
"eslint-config-alloy": "^5.1.2",
"eslint-config-prettier": "^10.0.1",
"eslint-plugin-prettier": "^5.2.2",
"@types/node": "^22.10.10",
"lerna": "^8.1.9",
"prettier": "^3.4.2",
"sort-package-json": "^2.14.0",
"ts-node": "^10.9.2",
"ttpt": "^0.13.0",
"typescript": "^5.7.3",
"yarn-upgrade-all": "^0.7.4"
},
"yarn-upgrade-all": {
"ignore": [
"eslint"
]
}
}
4 changes: 3 additions & 1 deletion packages/core/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Core of RingCentral Extension SDK

Please read the readme file of the [parent project](https://github.com/ringcentral/ringcentral-extensible) for more information.
Please read the readme file of the
[parent project](https://github.com/ringcentral/ringcentral-extensible) for more
information.
6 changes: 3 additions & 3 deletions packages/core/code-generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import generate from 'ringcentral-code-generator';
import path from 'path';
import generate from "ringcentral-code-generator";
import path from "path";

generate(process.env.SPEC_FILE_PATH!, path.join(__dirname, 'src'));
generate(process.env.SPEC_FILE_PATH!, path.join(__dirname, "src"));
29 changes: 18 additions & 11 deletions packages/core/src/FormData.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import type { Stream } from 'stream';
import type { Stream } from "stream";

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

async function stream2buffer(stream: Stream): Promise<Buffer> {
return new Promise<Buffer>((resolve, reject) => {
const buf = Array<any>();
stream.on('data', (chunk) => buf.push(chunk));
stream.on('end', () => resolve(Buffer.concat(buf)));
stream.on('error', (err) => reject(new Error(`error converting stream - ${err}`)));
stream.on("data", (chunk) => buf.push(chunk));
stream.on("end", () => resolve(Buffer.concat(buf)));
stream.on(
"error",
(err) => reject(new Error(`error converting stream - ${err}`)),
);
});
}

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

Expand All @@ -28,11 +31,12 @@ class FormData {
for (const formFile of this.files) {
let temp = `--${boundary}\r\n`;
temp += `Content-Type: ${formFile.contentType}\r\n`;
temp += `Content-Disposition: form-data; name="${formFile.name}"; filename="${formFile.filename}"\r\n\r\n`;
buffer = Buffer.concat([buffer, Buffer.from(temp, 'utf-8')]);
temp +=
`Content-Disposition: form-data; name="${formFile.name}"; filename="${formFile.filename}"\r\n\r\n`;
buffer = Buffer.concat([buffer, Buffer.from(temp, "utf-8")]);
let fileBuffer = Buffer.alloc(0);
if (typeof formFile.content === 'string') {
fileBuffer = Buffer.from(`${formFile.content}\r\n`, 'utf-8');
if (typeof formFile.content === "string") {
fileBuffer = Buffer.from(`${formFile.content}\r\n`, "utf-8");
} else if (Buffer.isBuffer(formFile.content)) {
fileBuffer = formFile.content;
} else if (formFile.content instanceof Blob) {
Expand All @@ -43,7 +47,10 @@ 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
4 changes: 2 additions & 2 deletions packages/core/src/RestException.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { RestResponse } from './types';
import Utils from './Utils';
import type { RestResponse } from "./types";
import Utils from "./Utils";

class RestException extends Error {
public response: RestResponse;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/SdkExtension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RingCentralInterface } from './types';
import type { RingCentralInterface } from "./types";

abstract class SdkExtension {
public enabled = true;
Expand Down
67 changes: 37 additions & 30 deletions packages/core/src/Utils.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
import FormData from './FormData';
import FormData from "./FormData";

import type Attachment from './definitions/Attachment';
import type { RestResponse } from './types';
import type Attachment from "./definitions/Attachment";
import type { RestResponse } from "./types";

class Utils {
public static formatTraffic(r: RestResponse): string {
return `HTTP ${r.status} ${r.statusText}${r.data.message ? ` - ${r.data.message}` : ''}
return `HTTP ${r.status} ${r.statusText}${
r.data.message ? ` - ${r.data.message}` : ""
}
Response:
${JSON.stringify(
{
data: r.data,
status: r.status,
statusText: r.statusText,
headers: r.headers,
},
null,
2,
)}
${
JSON.stringify(
{
data: r.data,
status: r.status,
statusText: r.statusText,
headers: r.headers,
},
null,
2,
)
}
Request:
${JSON.stringify(
{
method: r.config.method,
baseURL: r.config.baseURL,
url: r.config.url,
params: r.config.params,
data: Buffer.isBuffer(r.config.data) ? '<Buffer>' : r.config.data,
headers: r.config.headers,
},
null,
2,
)}
${
JSON.stringify(
{
method: r.config.method,
baseURL: r.config.baseURL,
url: r.config.url,
params: r.config.params,
data: Buffer.isBuffer(r.config.data) ? "<Buffer>" : r.config.data,
headers: r.config.headers,
},
null,
2,
)
}
`;
}

public static isAttachment(obj: {}): boolean {
return typeof obj === 'object' && obj !== null && 'filename' in obj && 'content' in obj;
return typeof obj === "object" && obj !== null && "filename" in obj &&
"content" in obj;
}

public static getFormData(...objects: {}[]): Promise<Buffer> {
Expand Down Expand Up @@ -73,9 +80,9 @@ class Utils {
}
if (Object.keys(obj).length > 0) {
formData.prepend({
name: 'request.json',
filename: 'request.json',
contentType: 'application/json',
name: "request.json",
filename: "request.json",
contentType: "application/json",
content: JSON.stringify(obj),
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/definitions/ADGErrorResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type ADGError from './ADGError';
import type ADGError from "./ADGError";

/**
* Format of response in case that any error occurred during request processing
Expand Down
Loading

0 comments on commit e3dace5

Please sign in to comment.