Skip to content

Commit

Permalink
chore: use fetch parameters instead of RequestInit and also add guide…
Browse files Browse the repository at this point in the history
… for proxy usage
  • Loading branch information
kravetsone committed Aug 17, 2024
1 parent a3c1108 commit f9bf2c5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,34 @@ await tKassa.getQr(/** some data */, {
});
```

Таким образом вы можете, например, воспользоваться прокси.

В [Node.js](https://nodejs.org/)

```ts
import { ProxyAgent } from "undici";

const proxyAgent = new ProxyAgent("my.proxy.server");

const tKassa = new TKassa({
requestsOptions: {
dispatcher: proxyAgent,
},
});
```

Несмотря на то что `undici` работает под капотом `Node.js`, вам придётся его скачать. Также убедитесь, что у вас нет `"lib": ["DOM"]` в вашем `tsconfig.json`, иначе вы не увидите свойства `dispatcher` (хотя `undici` всё равно его обработает).

В [Bun](https://bun.sh)

```ts
const tKassa = new TKassa({
requestsOptions: {
proxy: "my.proxy.server",
},
});
```

### Функции-хелперы

##### [`generateSignature`](https://jsr.io/@kravets/t-kassa-api/doc/~/generateSignature)
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "t-kassa-api",
"version": "0.3.1",
"version": "0.3.2",
"module": "./dist/index.js",
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -41,7 +41,7 @@
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@scalar/openapi-parser": "^0.7.2",
"@types/bun": "latest",
"@types/bun": "^1.1.6",
"cheerio": "^1.0.0-rc.12",
"openapi-typescript": "^7.0.2",
"pkgroll": "^2.1.1",
Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ export type Prettify<T> = {

export type MaybePromise<T> = Promise<T> | T;

export type RequestOptions = Omit<RequestInit, "headers"> & {
export type RequestOptions = Omit<
NonNullable<Parameters<typeof fetch>[1]>,
"headers"
> & {
mimeType?: "json" | "x-www-form-urlencoded";
headers?: Record<string, string>;
};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext", "DOM"],
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
Expand Down

0 comments on commit f9bf2c5

Please sign in to comment.