File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11{
22 "name" : " nestjs-yookassa" ,
3- "version" : " 2.0.4 " ,
3+ "version" : " 2.1.0 " ,
44 "description" : " A NestJS library for integrating with YooKassa API" ,
55 "keywords" : [
66 " nest" ,
Original file line number Diff line number Diff line change @@ -14,6 +14,53 @@ export type YookassaModuleOptions = {
1414 * Ключ API для аутентификации в YooKassa.
1515 */
1616 apiKey : string
17+
18+ /**
19+ * Настройки HTTP-прокси для отправки запросов.
20+ *
21+ * Используется в случаях, когда запросы к YooKassa должны идти
22+ * через российский IP — например, если сервер находится за границей.
23+ *
24+ * Пример простого подключения:
25+ * {
26+ * host: '192.168.1.10',
27+ * port: 8888,
28+ * protocol: 'http'
29+ * }
30+ */
31+ proxy ?: {
32+ /**
33+ * Хост или IPv4-адрес прокси-сервера.
34+ * Например: "91.218.114.206"
35+ */
36+ host : string
37+
38+ /**
39+ * Порт, на котором работает прокси.
40+ * Для tinyproxy обычно 8888.
41+ */
42+ port : number
43+
44+ /**
45+ * Протокол для подключения к прокси.
46+ * Почти всегда "http", т.к. tinyproxy не использует HTTPS.
47+ */
48+ protocol ?: 'http' | 'https'
49+
50+ /**
51+ * Данные для авторизации на прокси (необязательно).
52+ *
53+ * Используется ТОЛЬКО если прокси защищён логином и паролем.
54+ * В tinyproxy по умолчанию не нужно.
55+ *
56+ * Пример:
57+ * auth: { username: "user", password: "pass" }
58+ */
59+ auth ?: {
60+ username : string
61+ password : string
62+ }
63+ }
1764}
1865
1966/**
Original file line number Diff line number Diff line change @@ -25,7 +25,20 @@ export class YookassaHttpClient {
2525 username : this . config . shopId ,
2626 password : this . config . apiKey
2727 }
28+
2829 client . defaults . headers . common [ 'Content-Type' ] = 'application/json'
30+
31+ if ( this . config . proxy ) {
32+ client . defaults . proxy = {
33+ host : this . config . proxy . host ,
34+ port : this . config . proxy . port ,
35+ protocol : this . config . proxy . protocol ?? 'http' ,
36+ auth : this . config . proxy . auth
37+ }
38+ console . log (
39+ `[YooKassa] Proxy enabled → ${ this . config . proxy . host } :${ this . config . proxy . port } `
40+ )
41+ }
2942 }
3043
3144 public async request < T = any > ( options : AxiosRequestConfig ) : Promise < T > {
@@ -35,8 +48,7 @@ export class YookassaHttpClient {
3548 'Idempotence-Key' : randomUUID ( )
3649 }
3750
38- const $res = this . httpService . request ( options )
39- const res = await firstValueFrom ( $res )
51+ const res = await firstValueFrom ( this . httpService . request ( options ) )
4052
4153 return res . data
4254 } catch ( error : any ) {
You can’t perform that action at this time.
0 commit comments