Skip to content

Commit

Permalink
chore: allow configure requests options
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed Aug 12, 2024
1 parent 4b14012 commit 2262f1d
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 76 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
- name: Install modules
run: bun install

- name: Run tests
run: bun test

- name: Build
run: bunx pkgroll

Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,30 @@ const ткасса = new TKassa((body) => {

И типы опять же совсем не глупы и делают вам благое дело, указывая верный путь.

### RequestsOptions

Вы можете повлиять на поведение запроса

#### Глобально

```ts
const tKassa = new TKassa({
requestsOptions: {
headers: {
"x-awesome": "this library is great",
},
},
});
```

#### Для одного запроса

```ts
await tKassa.getQr(/** some data */, {
signal: AbortSignal.timeout(500)
});
```

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

##### [`generateSignature`](https://jsr.io/@kravets/t-kassa-api/doc/~/generateSignature)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "t-kassa-api",
"version": "0.2.3",
"version": "0.3.0",
"module": "./dist/index.js",
"main": "./dist/index.cjs",
"types": "./dist/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion scripts/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ indexSource = indexSource.replace(
]
: [],
)
.concat(["options?: RequestOptions"])
.join(", ");
return dedent /* js */`
Expand All @@ -145,7 +146,7 @@ indexSource = indexSource.replace(
* [Documentation](${getLinkToMethod(operation.tags || [], operation.operationId || "")})
*/
${fromPascalToCamelCase(operation.operationId!)}(${parameters}): Promise<GetResponse<"${path}", "${method}">> {
return this.request(\`${path.replaceAll(/{/gi, "${")}\`, ${body?.schema ? "body" : "undefined"}, "${method.toUpperCase()}"${contentType?.endsWith("x-www-form-urlencoded") ? `, "x-www-form-urlencoded"` : ""})
return this.request(\`${path.replaceAll(/{/gi, "${")}\`, ${body?.schema ? "body" : "undefined"}, {method: "${method.toUpperCase()}" ${contentType?.endsWith("x-www-form-urlencoded") ? `, mimeType: "x-www-form-urlencoded"` : ""}, ...options})
}
`;
})
Expand Down
Loading

0 comments on commit 2262f1d

Please sign in to comment.