Skip to content

Commit

Permalink
Release 2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Jan 4, 2025
1 parent ccba3cf commit acdd7ac
Show file tree
Hide file tree
Showing 312 changed files with 1,174 additions and 760 deletions.
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ The Common TypeScript library provides convenient access to the Common API from
npm i -s @commonxyz/api-client
```

## Reference

A full reference for this library is available [here](./reference.md).

## Usage

Instantiate and use the client with the following:
Expand Down Expand Up @@ -62,6 +66,18 @@ try {

## Advanced

### Additional Headers

If you would like to send additional headers as part of the request, use the `headers` request option.

```typescript
const response = await client.community.createContestMetadata(..., {
headers: {
'X-Custom-Header': 'custom value'
}
});
```

### Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
Expand All @@ -70,9 +86,9 @@ retry limit (default: 2).

A request is deemed retriable when any of the following HTTP status codes is returned:

- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)

Use the `maxRetries` request option to configure this behavior.

Expand Down Expand Up @@ -109,12 +125,12 @@ controller.abort(); // aborts the request
The SDK defaults to `node-fetch` but will use the global fetch client if present. The SDK works in the following
runtimes:

- Node.js 18+
- Vercel
- Cloudflare Workers
- Deno v1.25+
- Bun 1.0+
- React Native
- Node.js 18+
- Vercel
- Cloudflare Workers
- Deno v1.25+
- Bun 1.0+
- React Native

### Customizing Fetch Client

Expand Down
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@commonxyz/api-client",
"version": "2.0.0",
"version": "2.1.1",
"private": false,
"repository": "https://github.com/hicommonwealth/common-ts-client",
"license": "MIT",
Expand All @@ -16,21 +16,24 @@
"url-join": "4.0.1",
"form-data": "^4.0.0",
"formdata-node": "^6.0.3",
"node-fetch": "2.7.0",
"qs": "6.11.2"
"node-fetch": "^2.7.0",
"qs": "^6.13.1",
"readable-stream": "^4.5.2"
},
"devDependencies": {
"@types/url-join": "4.0.1",
"@types/qs": "6.9.8",
"@types/node-fetch": "2.6.9",
"fetch-mock-jest": "^1.5.1",
"jest": "29.7.0",
"@types/jest": "29.5.5",
"ts-jest": "29.1.1",
"jest-environment-jsdom": "29.7.0",
"@types/node": "17.0.33",
"prettier": "2.7.1",
"typescript": "4.6.4"
"@types/qs": "^6.9.17",
"@types/node-fetch": "^2.6.12",
"@types/readable-stream": "^4.0.18",
"webpack": "^5.97.1",
"ts-loader": "^9.5.1",
"jest": "^29.7.0",
"@types/jest": "^29.5.14",
"ts-jest": "^29.1.1",
"jest-environment-jsdom": "^29.7.0",
"@types/node": "^17.0.41",
"prettier": "^3.4.2",
"typescript": "~5.7.2"
},
"browser": {
"fs": false,
Expand Down
4 changes: 2 additions & 2 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ await client.community.createCommunity({
id: "id",
name: "name",
chain_node_id: 1,
base: CommonApi.CreateCommunityRequestBase.Cosmos,
base: "cosmos",
default_symbol: "default_symbol",
});
```
Expand Down Expand Up @@ -1282,7 +1282,7 @@ await client.thread.createThread({
topic_id: 1,
title: "title",
body: "body",
kind: CommonApi.CreateThreadRequestKind.Discussion,
kind: "discussion",
stage: "stage",
read_only: true,
});
Expand Down
25 changes: 11 additions & 14 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { Contest } from "./api/resources/contest/client/Client";
import { Reaction } from "./api/resources/reaction/client/Client";

export declare namespace CommonApiClient {
interface Options {
export interface Options {
environment?: core.Supplier<environments.CommonApiEnvironment | string>;
apiKey: core.Supplier<string>;
/** Override the address header */
address?: core.Supplier<string | undefined>;
}

interface RequestOptions {
export interface RequestOptions {
/** The maximum time to wait for a response in seconds. */
timeoutInSeconds?: number;
/** The number of times to retry the request. Defaults to 2. */
Expand All @@ -28,44 +28,41 @@ export declare namespace CommonApiClient {
abortSignal?: AbortSignal;
/** Override the address header */
address?: string | undefined;
/** Additional headers to include in the request. */
headers?: Record<string, string>;
}
}

export class CommonApiClient {
constructor(protected readonly _options: CommonApiClient.Options) {}

protected _user: User | undefined;
protected _community: Community | undefined;
protected _comment: Comment | undefined;
protected _thread: Thread | undefined;
protected _contest: Contest | undefined;
protected _reaction: Reaction | undefined;

constructor(protected readonly _options: CommonApiClient.Options) {}

public get user(): User {
return (this._user ??= new User(this._options));
}

protected _community: Community | undefined;

public get community(): Community {
return (this._community ??= new Community(this._options));
}

protected _comment: Comment | undefined;

public get comment(): Comment {
return (this._comment ??= new Comment(this._options));
}

protected _thread: Thread | undefined;

public get thread(): Thread {
return (this._thread ??= new Thread(this._options));
}

protected _contest: Contest | undefined;

public get contest(): Contest {
return (this._contest ??= new Contest(this._options));
}

protected _reaction: Reaction | undefined;

public get reaction(): Reaction {
return (this._reaction ??= new Reaction(this._options));
}
Expand Down
50 changes: 28 additions & 22 deletions src/api/resources/comment/client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import urlJoin from "url-join";
import * as errors from "../../../../errors/index";

export declare namespace Comment {
interface Options {
export interface Options {
environment?: core.Supplier<environments.CommonApiEnvironment | string>;
apiKey: core.Supplier<string>;
/** Override the address header */
address?: core.Supplier<string | undefined>;
}

interface RequestOptions {
export interface RequestOptions {
/** The maximum time to wait for a response in seconds. */
timeoutInSeconds?: number;
/** The number of times to retry the request. Defaults to 2. */
Expand All @@ -25,6 +25,8 @@ export declare namespace Comment {
abortSignal?: AbortSignal;
/** Override the address header */
address?: string | undefined;
/** Additional headers to include in the request. */
headers?: Record<string, string>;
}
}

Expand All @@ -42,7 +44,7 @@ export class Comment {
*/
public async getComments(
request: CommonApi.GetCommentsRequest,
requestOptions?: Comment.RequestOptions
requestOptions?: Comment.RequestOptions,
): Promise<CommonApi.GetCommentsResponse> {
const {
limit,
Expand Down Expand Up @@ -87,7 +89,7 @@ export class Comment {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.CommonApiEnvironment.Default,
"GetComments"
"GetComments",
),
method: "GET",
headers: {
Expand All @@ -97,11 +99,12 @@ export class Comment {
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@commonxyz/api-client",
"X-Fern-SDK-Version": "2.0.0",
"User-Agent": "@commonxyz/api-client/2.0.0",
"X-Fern-SDK-Version": "2.1.1",
"User-Agent": "@commonxyz/api-client/2.1.1",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
...requestOptions?.headers,
},
contentType: "application/json",
queryParameters: _queryParams,
Expand All @@ -128,7 +131,7 @@ export class Comment {
body: _response.error.rawBody,
});
case "timeout":
throw new errors.CommonApiTimeoutError();
throw new errors.CommonApiTimeoutError("Timeout exceeded when calling GET /GetComments.");
case "unknown":
throw new errors.CommonApiError({
message: _response.error.errorMessage,
Expand All @@ -148,12 +151,12 @@ export class Comment {
*/
public async createComment(
request: CommonApi.CreateCommentRequest,
requestOptions?: Comment.RequestOptions
requestOptions?: Comment.RequestOptions,
): Promise<CommonApi.CreateCommentResponse> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.CommonApiEnvironment.Default,
"CreateComment"
"CreateComment",
),
method: "POST",
headers: {
Expand All @@ -163,11 +166,12 @@ export class Comment {
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@commonxyz/api-client",
"X-Fern-SDK-Version": "2.0.0",
"User-Agent": "@commonxyz/api-client/2.0.0",
"X-Fern-SDK-Version": "2.1.1",
"User-Agent": "@commonxyz/api-client/2.1.1",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
Expand All @@ -194,7 +198,7 @@ export class Comment {
body: _response.error.rawBody,
});
case "timeout":
throw new errors.CommonApiTimeoutError();
throw new errors.CommonApiTimeoutError("Timeout exceeded when calling POST /CreateComment.");
case "unknown":
throw new errors.CommonApiError({
message: _response.error.errorMessage,
Expand All @@ -214,12 +218,12 @@ export class Comment {
*/
public async updateComment(
request: CommonApi.UpdateCommentRequest,
requestOptions?: Comment.RequestOptions
requestOptions?: Comment.RequestOptions,
): Promise<CommonApi.UpdateCommentResponse> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.CommonApiEnvironment.Default,
"UpdateComment"
"UpdateComment",
),
method: "POST",
headers: {
Expand All @@ -229,11 +233,12 @@ export class Comment {
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@commonxyz/api-client",
"X-Fern-SDK-Version": "2.0.0",
"User-Agent": "@commonxyz/api-client/2.0.0",
"X-Fern-SDK-Version": "2.1.1",
"User-Agent": "@commonxyz/api-client/2.1.1",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
Expand All @@ -260,7 +265,7 @@ export class Comment {
body: _response.error.rawBody,
});
case "timeout":
throw new errors.CommonApiTimeoutError();
throw new errors.CommonApiTimeoutError("Timeout exceeded when calling POST /UpdateComment.");
case "unknown":
throw new errors.CommonApiError({
message: _response.error.errorMessage,
Expand All @@ -279,12 +284,12 @@ export class Comment {
*/
public async deleteComment(
request: CommonApi.DeleteCommentRequest,
requestOptions?: Comment.RequestOptions
requestOptions?: Comment.RequestOptions,
): Promise<CommonApi.DeleteCommentResponse> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this._options.environment)) ?? environments.CommonApiEnvironment.Default,
"DeleteComment"
"DeleteComment",
),
method: "POST",
headers: {
Expand All @@ -294,11 +299,12 @@ export class Comment {
: undefined,
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@commonxyz/api-client",
"X-Fern-SDK-Version": "2.0.0",
"User-Agent": "@commonxyz/api-client/2.0.0",
"X-Fern-SDK-Version": "2.1.1",
"User-Agent": "@commonxyz/api-client/2.1.1",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
...(await this._getCustomAuthorizationHeaders()),
...requestOptions?.headers,
},
contentType: "application/json",
requestType: "json",
Expand All @@ -325,7 +331,7 @@ export class Comment {
body: _response.error.rawBody,
});
case "timeout":
throw new errors.CommonApiTimeoutError();
throw new errors.CommonApiTimeoutError("Timeout exceeded when calling POST /DeleteComment.");
case "unknown":
throw new errors.CommonApiError({
message: _response.error.errorMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

export type CreateCommentResponseAddressRole = "admin" | "moderator" | "member";

export const CreateCommentResponseAddressRole = {
Admin: "admin",
Moderator: "moderator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

export type CreateCommentResponseAddressUserEmailNotificationInterval = "weekly" | "never";

export const CreateCommentResponseAddressUserEmailNotificationInterval = {
Weekly: "weekly",
Never: "never",
Expand Down
Loading

0 comments on commit acdd7ac

Please sign in to comment.