Skip to content

Commit 3d6878f

Browse files
committed
fix: Some CR fixes
1 parent 88e878a commit 3d6878f

File tree

11 files changed

+3565
-692
lines changed

11 files changed

+3565
-692
lines changed

package-lock.json

Lines changed: 3540 additions & 673 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
"scripts": {
1616
"build": "tsc",
1717
"test": "jest",
18+
"unused-deps": "npx depcheck --json | jq '.dependencies == []'",
19+
"clean-build": "rm -rf ./dist",
1820
"lint": "npx eslint 'src/**/*.{ts,tsx}' --no-ignore",
1921
"format": "prettier --write \"src/**/*.ts\"",
2022
"prepare": "npm run build",
21-
"example": "npx tsx src/example.ts"
23+
"example": "npx tsx src/example.ts",
24+
"circular": "madge --circular --extensions ts src",
25+
"quality": "npm run circular && npm run lint && tsc --noEmit && npm run format && npm run unused-deps"
2226
},
2327
"files": [
2428
"dist"
@@ -32,9 +36,6 @@
3236
"license": "MIT",
3337
"dependencies": {
3438
"@types/node": "^18.11.18",
35-
"abort-controller": "^3.0.0",
36-
"agentkeepalive": "^4.5.0",
37-
"form-data-encoder": "^4.0.2",
3839
"formdata-node": "^6.0.3",
3940
"node-fetch": "^2.7.0"
4041
},
@@ -47,6 +48,7 @@
4748
"eslint-config-prettier": "^9.1.0",
4849
"eslint-plugin-prettier": "^5.2.1",
4950
"globals": "^15.12.0",
51+
"madge": "^6.1.0",
5052
"prettier": "^3.3.3",
5153
"ts-node": "^10.5.0",
5254
"tsc-multi": "^1.1.0",

src/Client.ts renamed to src/AI21.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import * as Core from './Core';
2-
import * as Models from './types';
1+
import * as Types from './types';
32
import { AI21EnvConfig } from './EnvConfig';
43
import { MissingAPIKeyError } from './errors';
54
import { Chat } from './resources/chat';
5+
import { APIClient } from './APIClient';
66

77
export interface AI21Options {
88
apiKey: string;
@@ -11,7 +11,7 @@ export interface AI21Options {
1111
timeout: number;
1212
maxRetries: number;
1313
}
14-
export class AI21 extends Core.APIClient {
14+
export class AI21 extends APIClient {
1515
private apiKey: string;
1616
private _options: AI21Options;
1717

@@ -46,13 +46,13 @@ export class AI21 extends Core.APIClient {
4646
}
4747

4848
// eslint-disable-next-line @typescript-eslint/no-unused-vars
49-
protected override authHeaders(_: Models.FinalRequestOptions): Core.Headers {
49+
protected override authHeaders(_: Types.FinalRequestOptions): Types.Headers {
5050
return {
5151
Authorization: `Bearer ${this.apiKey}`,
5252
};
5353
}
5454

55-
protected override defaultHeaders(opts: Models.FinalRequestOptions): Core.Headers {
55+
protected override defaultHeaders(opts: Types.FinalRequestOptions): Types.Headers {
5656
return {
5757
...super.defaultHeaders(opts),
5858
'User-Agent': this.getUserAgent(),

src/Core.ts renamed to src/APIClient.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { AI21Error } from './errors.js';
2-
import { VERSION } from './version.js';
1+
import { AI21Error } from './errors';
2+
import { VERSION } from './version';
33

44
import fetch from 'node-fetch';
55
import { HeadersInit, RequestInit } from 'node-fetch';
@@ -10,12 +10,11 @@ import {
1010
HTTPMethod,
1111
PromiseOrValue,
1212
DefaultQuery,
13+
Headers,
1314
} from './types/index.js';
1415
import { AI21EnvConfig } from './EnvConfig.js';
1516
import { handleAPIResponse } from './ResponseHandler.js';
1617

17-
export type Headers = Record<string, string | null | undefined>;
18-
1918
const validatePositiveInteger = (name: string, n: unknown): number => {
2019
if (typeof n !== 'number' || !Number.isInteger(n)) {
2120
throw new AI21Error(`${name} must be an integer`);

src/APIResource.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { AI21 } from './index';
1+
import type { APIClient } from './APIClient';
22

33
export class APIResource {
4-
protected _client: AI21;
4+
protected _client: APIClient;
55

6-
constructor(client: AI21) {
6+
constructor(client: APIClient) {
77
this._client = client;
88
}
99
}

src/example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AI21 } from './Client';
1+
import { AI21 } from './ai21';
22

33
/*
44
This is a temporary example to test the API streaming/non-streaming functionality.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { AI21 } from './Client';
1+
export { AI21 } from './ai21';
22
export { VERSION } from './version';
33
export { RequestOptions } from './types';
44
export { AI21Error, MissingAPIKeyError } from './errors';

src/types/API.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ export type FinalRequestOptions = RequestOptions & {
3131

3232
export type DefaultQuery = Record<string, unknown>;
3333
export type PromiseOrValue<T> = T | Promise<T>;
34+
export type Headers = Record<string, string | null | undefined>;

src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ export {
3434
type HTTPMethod,
3535
type DefaultQuery,
3636
type PromiseOrValue,
37+
type Headers,
3738
} from './API';

src/version.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export const VERSION = '0.0.1';
1+
import { version } from '../package.json';
2+
3+
export const VERSION = version;

0 commit comments

Comments
 (0)