@payabli/sdk-node 0.0.116 → 0.0.117

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. package/README.md +24 -7
  2. package/dist/cjs/BaseClient.d.ts +10 -1
  3. package/dist/cjs/BaseClient.js +57 -0
  4. package/dist/cjs/Client.d.ts +87 -86
  5. package/dist/cjs/Client.js +31 -72
  6. package/dist/cjs/api/resources/bill/client/Client.d.ts +33 -33
  7. package/dist/cjs/api/resources/bill/client/Client.js +69 -216
  8. package/dist/cjs/api/resources/boarding/client/Client.d.ts +27 -27
  9. package/dist/cjs/api/resources/boarding/client/Client.js +51 -198
  10. package/dist/cjs/api/resources/chargeBacks/client/Client.d.ts +17 -15
  11. package/dist/cjs/api/resources/chargeBacks/client/Client.js +38 -79
  12. package/dist/cjs/api/resources/checkCapture/client/Client.d.ts +7 -7
  13. package/dist/cjs/api/resources/checkCapture/client/Client.js +11 -28
  14. package/dist/cjs/api/resources/cloud/client/Client.d.ts +17 -17
  15. package/dist/cjs/api/resources/cloud/client/Client.js +33 -89
  16. package/dist/cjs/api/resources/customer/client/Client.d.ts +17 -17
  17. package/dist/cjs/api/resources/customer/client/Client.js +31 -113
  18. package/dist/cjs/api/resources/export/client/Client.d.ts +93 -89
  19. package/dist/cjs/api/resources/export/client/Client.js +205 -582
  20. package/dist/cjs/api/resources/hostedPaymentPages/client/Client.d.ts +11 -11
  21. package/dist/cjs/api/resources/hostedPaymentPages/client/Client.js +19 -62
  22. package/dist/cjs/api/resources/import/client/Client.d.ts +11 -11
  23. package/dist/cjs/api/resources/import/client/Client.js +19 -62
  24. package/dist/cjs/api/resources/invoice/client/Client.d.ts +31 -31
  25. package/dist/cjs/api/resources/invoice/client/Client.js +62 -209
  26. package/dist/cjs/api/resources/lineItem/client/Client.d.ts +15 -15
  27. package/dist/cjs/api/resources/lineItem/client/Client.js +27 -96
  28. package/dist/cjs/api/resources/moneyIn/client/Client.d.ts +39 -39
  29. package/dist/cjs/api/resources/moneyIn/client/Client.js +79 -249
  30. package/dist/cjs/api/resources/moneyOut/client/Client.d.ts +43 -26
  31. package/dist/cjs/api/resources/moneyOut/client/Client.js +105 -168
  32. package/dist/cjs/api/resources/moneyOut/client/requests/MoneyOutTypesRequestOutAuthorize.d.ts +2 -1
  33. package/dist/cjs/api/resources/moneyOutTypes/types/AuthorizePayoutBody.d.ts +3 -1
  34. package/dist/cjs/api/resources/notification/client/Client.d.ts +16 -16
  35. package/dist/cjs/api/resources/notification/client/Client.js +32 -101
  36. package/dist/cjs/api/resources/notificationlogs/client/Client.d.ts +13 -13
  37. package/dist/cjs/api/resources/notificationlogs/client/Client.js +23 -79
  38. package/dist/cjs/api/resources/ocr/client/Client.d.ts +13 -9
  39. package/dist/cjs/api/resources/ocr/client/Client.js +19 -45
  40. package/dist/cjs/api/resources/organization/client/Client.d.ts +19 -19
  41. package/dist/cjs/api/resources/organization/client/Client.js +35 -130
  42. package/dist/cjs/api/resources/paymentLink/client/Client.d.ts +23 -23
  43. package/dist/cjs/api/resources/paymentLink/client/Client.js +43 -164
  44. package/dist/cjs/api/resources/paymentMethodDomain/client/Client.d.ts +19 -19
  45. package/dist/cjs/api/resources/paymentMethodDomain/client/Client.js +35 -130
  46. package/dist/cjs/api/resources/paypoint/client/Client.d.ts +22 -22
  47. package/dist/cjs/api/resources/paypoint/client/Client.js +44 -152
  48. package/dist/cjs/api/resources/query/client/Client.d.ts +71 -71
  49. package/dist/cjs/api/resources/query/client/Client.js +137 -572
  50. package/dist/cjs/api/resources/query/client/requests/ListPayoutOrgRequest.d.ts +1 -0
  51. package/dist/cjs/api/resources/query/client/requests/ListPayoutRequest.d.ts +1 -0
  52. package/dist/cjs/api/resources/query/client/requests/ListTransactionsRequest.d.ts +1 -0
  53. package/dist/cjs/api/resources/statistic/client/Client.d.ts +50 -50
  54. package/dist/cjs/api/resources/statistic/client/Client.js +80 -133
  55. package/dist/cjs/api/resources/statistic/client/requests/BasicStatsRequest.d.ts +2 -2
  56. package/dist/cjs/api/resources/statistic/types/StatBasicExtendedQueryRecord.d.ts +76 -0
  57. package/dist/cjs/api/resources/statistic/types/StatBasicExtendedQueryRecord.js +3 -0
  58. package/dist/cjs/api/resources/statistic/types/index.d.ts +1 -0
  59. package/dist/cjs/api/resources/statistic/types/index.js +1 -0
  60. package/dist/cjs/api/resources/subscription/client/Client.d.ts +13 -13
  61. package/dist/cjs/api/resources/subscription/client/Client.js +23 -79
  62. package/dist/cjs/api/resources/templates/client/Client.d.ts +15 -15
  63. package/dist/cjs/api/resources/templates/client/Client.js +28 -84
  64. package/dist/cjs/api/resources/tokenStorage/client/Client.d.ts +13 -13
  65. package/dist/cjs/api/resources/tokenStorage/client/Client.js +23 -79
  66. package/dist/cjs/api/resources/user/client/Client.d.ts +54 -32
  67. package/dist/cjs/api/resources/user/client/Client.js +84 -222
  68. package/dist/cjs/api/resources/vendor/client/Client.d.ts +13 -13
  69. package/dist/cjs/api/resources/vendor/client/Client.js +23 -79
  70. package/dist/cjs/api/resources/wallet/client/Client.d.ts +13 -13
  71. package/dist/cjs/api/resources/wallet/client/Client.js +23 -79
  72. package/dist/cjs/api/types/ApplicationDetailsRecord.d.ts +2 -2
  73. package/dist/cjs/api/types/NotificationContent.d.ts +1 -0
  74. package/dist/cjs/api/types/NotificationContent.js +1 -0
  75. package/dist/cjs/api/types/NotificationStandardRequest.d.ts +1 -0
  76. package/dist/cjs/api/types/NotificationStandardRequest.js +1 -0
  77. package/dist/cjs/api/types/QueryResponseSettlements.d.ts +1 -1
  78. package/dist/cjs/auth/HeaderAuthProvider.d.ts +14 -0
  79. package/dist/cjs/auth/HeaderAuthProvider.js +71 -0
  80. package/dist/cjs/auth/index.d.ts +1 -0
  81. package/dist/cjs/auth/index.js +5 -0
  82. package/dist/cjs/core/auth/AuthProvider.d.ts +7 -0
  83. package/dist/cjs/{version.js → core/auth/AuthProvider.js} +0 -2
  84. package/dist/cjs/core/auth/AuthRequest.d.ts +9 -0
  85. package/dist/cjs/core/auth/AuthRequest.js +2 -0
  86. package/dist/cjs/core/auth/BasicAuth.d.ts +8 -0
  87. package/dist/cjs/core/auth/BasicAuth.js +27 -0
  88. package/dist/cjs/core/auth/BearerToken.d.ts +7 -0
  89. package/dist/cjs/core/auth/BearerToken.js +16 -0
  90. package/dist/cjs/core/auth/NoOpAuthProvider.d.ts +5 -0
  91. package/dist/cjs/core/auth/NoOpAuthProvider.js +9 -0
  92. package/dist/cjs/core/auth/index.d.ts +5 -0
  93. package/dist/cjs/core/auth/index.js +9 -0
  94. package/dist/cjs/core/base64.d.ts +2 -0
  95. package/dist/cjs/core/base64.js +26 -0
  96. package/dist/cjs/core/fetcher/BinaryResponse.d.ts +6 -7
  97. package/dist/cjs/core/fetcher/Fetcher.d.ts +5 -1
  98. package/dist/cjs/core/fetcher/Fetcher.js +42 -24
  99. package/dist/cjs/core/fetcher/getResponseBody.js +18 -4
  100. package/dist/cjs/core/fetcher/makeRequest.d.ts +1 -1
  101. package/dist/cjs/core/fetcher/makeRequest.js +0 -2
  102. package/dist/cjs/core/fetcher/requestWithRetries.js +0 -9
  103. package/dist/cjs/core/fetcher/signals.d.ts +1 -7
  104. package/dist/cjs/core/fetcher/signals.js +0 -12
  105. package/dist/cjs/core/index.d.ts +2 -0
  106. package/dist/cjs/core/index.js +2 -0
  107. package/dist/cjs/core/logging/logger.js +1 -1
  108. package/dist/cjs/core/runtime/runtime.js +11 -10
  109. package/dist/cjs/core/url/join.js +0 -1
  110. package/dist/cjs/errors/handleNonStatusCodeError.d.ts +2 -0
  111. package/dist/cjs/errors/handleNonStatusCodeError.js +65 -0
  112. package/dist/esm/BaseClient.d.mts +10 -1
  113. package/dist/esm/BaseClient.mjs +22 -1
  114. package/dist/esm/Client.d.mts +87 -86
  115. package/dist/esm/Client.mjs +59 -67
  116. package/dist/esm/api/resources/bill/client/Client.d.mts +33 -33
  117. package/dist/esm/api/resources/bill/client/Client.mjs +67 -214
  118. package/dist/esm/api/resources/boarding/client/Client.d.mts +27 -27
  119. package/dist/esm/api/resources/boarding/client/Client.mjs +50 -197
  120. package/dist/esm/api/resources/chargeBacks/client/Client.d.mts +17 -15
  121. package/dist/esm/api/resources/chargeBacks/client/Client.mjs +36 -77
  122. package/dist/esm/api/resources/checkCapture/client/Client.d.mts +7 -7
  123. package/dist/esm/api/resources/checkCapture/client/Client.mjs +10 -27
  124. package/dist/esm/api/resources/cloud/client/Client.d.mts +17 -17
  125. package/dist/esm/api/resources/cloud/client/Client.mjs +31 -87
  126. package/dist/esm/api/resources/customer/client/Client.d.mts +17 -17
  127. package/dist/esm/api/resources/customer/client/Client.mjs +29 -111
  128. package/dist/esm/api/resources/export/client/Client.d.mts +93 -89
  129. package/dist/esm/api/resources/export/client/Client.mjs +204 -581
  130. package/dist/esm/api/resources/hostedPaymentPages/client/Client.d.mts +11 -11
  131. package/dist/esm/api/resources/hostedPaymentPages/client/Client.mjs +17 -60
  132. package/dist/esm/api/resources/import/client/Client.d.mts +11 -11
  133. package/dist/esm/api/resources/import/client/Client.mjs +17 -60
  134. package/dist/esm/api/resources/invoice/client/Client.d.mts +31 -31
  135. package/dist/esm/api/resources/invoice/client/Client.mjs +60 -207
  136. package/dist/esm/api/resources/lineItem/client/Client.d.mts +15 -15
  137. package/dist/esm/api/resources/lineItem/client/Client.mjs +25 -94
  138. package/dist/esm/api/resources/moneyIn/client/Client.d.mts +39 -39
  139. package/dist/esm/api/resources/moneyIn/client/Client.mjs +77 -247
  140. package/dist/esm/api/resources/moneyOut/client/Client.d.mts +43 -26
  141. package/dist/esm/api/resources/moneyOut/client/Client.mjs +103 -166
  142. package/dist/esm/api/resources/moneyOut/client/requests/MoneyOutTypesRequestOutAuthorize.d.mts +2 -1
  143. package/dist/esm/api/resources/moneyOutTypes/types/AuthorizePayoutBody.d.mts +3 -1
  144. package/dist/esm/api/resources/notification/client/Client.d.mts +16 -16
  145. package/dist/esm/api/resources/notification/client/Client.mjs +31 -100
  146. package/dist/esm/api/resources/notificationlogs/client/Client.d.mts +13 -13
  147. package/dist/esm/api/resources/notificationlogs/client/Client.mjs +22 -78
  148. package/dist/esm/api/resources/ocr/client/Client.d.mts +13 -9
  149. package/dist/esm/api/resources/ocr/client/Client.mjs +18 -44
  150. package/dist/esm/api/resources/organization/client/Client.d.mts +19 -19
  151. package/dist/esm/api/resources/organization/client/Client.mjs +33 -128
  152. package/dist/esm/api/resources/paymentLink/client/Client.d.mts +23 -23
  153. package/dist/esm/api/resources/paymentLink/client/Client.mjs +41 -162
  154. package/dist/esm/api/resources/paymentMethodDomain/client/Client.d.mts +19 -19
  155. package/dist/esm/api/resources/paymentMethodDomain/client/Client.mjs +34 -129
  156. package/dist/esm/api/resources/paypoint/client/Client.d.mts +22 -22
  157. package/dist/esm/api/resources/paypoint/client/Client.mjs +43 -151
  158. package/dist/esm/api/resources/query/client/Client.d.mts +71 -71
  159. package/dist/esm/api/resources/query/client/Client.mjs +136 -571
  160. package/dist/esm/api/resources/query/client/requests/ListPayoutOrgRequest.d.mts +1 -0
  161. package/dist/esm/api/resources/query/client/requests/ListPayoutRequest.d.mts +1 -0
  162. package/dist/esm/api/resources/query/client/requests/ListTransactionsRequest.d.mts +1 -0
  163. package/dist/esm/api/resources/statistic/client/Client.d.mts +50 -50
  164. package/dist/esm/api/resources/statistic/client/Client.mjs +79 -132
  165. package/dist/esm/api/resources/statistic/client/requests/BasicStatsRequest.d.mts +2 -2
  166. package/dist/esm/api/resources/statistic/types/StatBasicExtendedQueryRecord.d.mts +76 -0
  167. package/dist/esm/api/resources/statistic/types/StatBasicExtendedQueryRecord.mjs +2 -0
  168. package/dist/esm/api/resources/statistic/types/index.d.mts +1 -0
  169. package/dist/esm/api/resources/statistic/types/index.mjs +1 -0
  170. package/dist/esm/api/resources/subscription/client/Client.d.mts +13 -13
  171. package/dist/esm/api/resources/subscription/client/Client.mjs +21 -77
  172. package/dist/esm/api/resources/templates/client/Client.d.mts +15 -15
  173. package/dist/esm/api/resources/templates/client/Client.mjs +27 -83
  174. package/dist/esm/api/resources/tokenStorage/client/Client.d.mts +13 -13
  175. package/dist/esm/api/resources/tokenStorage/client/Client.mjs +21 -77
  176. package/dist/esm/api/resources/user/client/Client.d.mts +54 -32
  177. package/dist/esm/api/resources/user/client/Client.mjs +83 -221
  178. package/dist/esm/api/resources/vendor/client/Client.d.mts +13 -13
  179. package/dist/esm/api/resources/vendor/client/Client.mjs +22 -78
  180. package/dist/esm/api/resources/wallet/client/Client.d.mts +13 -13
  181. package/dist/esm/api/resources/wallet/client/Client.mjs +22 -78
  182. package/dist/esm/api/types/ApplicationDetailsRecord.d.mts +2 -2
  183. package/dist/esm/api/types/NotificationContent.d.mts +1 -0
  184. package/dist/esm/api/types/NotificationContent.mjs +1 -0
  185. package/dist/esm/api/types/NotificationStandardRequest.d.mts +1 -0
  186. package/dist/esm/api/types/NotificationStandardRequest.mjs +1 -0
  187. package/dist/esm/api/types/QueryResponseSettlements.d.mts +1 -1
  188. package/dist/esm/auth/HeaderAuthProvider.d.mts +14 -0
  189. package/dist/esm/auth/HeaderAuthProvider.mjs +34 -0
  190. package/dist/esm/auth/index.d.mts +1 -0
  191. package/dist/esm/auth/index.mjs +1 -0
  192. package/dist/esm/core/auth/AuthProvider.d.mts +7 -0
  193. package/dist/esm/core/auth/AuthProvider.mjs +1 -0
  194. package/dist/esm/core/auth/AuthRequest.d.mts +9 -0
  195. package/dist/esm/core/auth/AuthRequest.mjs +1 -0
  196. package/dist/esm/core/auth/BasicAuth.d.mts +8 -0
  197. package/dist/esm/core/auth/BasicAuth.mjs +24 -0
  198. package/dist/esm/core/auth/BearerToken.d.mts +7 -0
  199. package/dist/esm/core/auth/BearerToken.mjs +13 -0
  200. package/dist/esm/core/auth/NoOpAuthProvider.d.mts +5 -0
  201. package/dist/esm/core/auth/NoOpAuthProvider.mjs +5 -0
  202. package/dist/esm/core/auth/index.d.mts +5 -0
  203. package/dist/esm/core/auth/index.mjs +3 -0
  204. package/dist/esm/core/base64.d.mts +2 -0
  205. package/dist/esm/core/base64.mjs +22 -0
  206. package/dist/esm/core/fetcher/BinaryResponse.d.mts +6 -7
  207. package/dist/esm/core/fetcher/Fetcher.d.mts +5 -1
  208. package/dist/esm/core/fetcher/Fetcher.mjs +42 -24
  209. package/dist/esm/core/fetcher/getResponseBody.mjs +18 -4
  210. package/dist/esm/core/fetcher/makeRequest.d.mts +1 -1
  211. package/dist/esm/core/fetcher/makeRequest.mjs +0 -2
  212. package/dist/esm/core/fetcher/requestWithRetries.mjs +0 -9
  213. package/dist/esm/core/fetcher/signals.d.mts +1 -7
  214. package/dist/esm/core/fetcher/signals.mjs +0 -12
  215. package/dist/esm/core/index.d.mts +2 -0
  216. package/dist/esm/core/index.mjs +2 -0
  217. package/dist/esm/core/logging/logger.mjs +1 -1
  218. package/dist/esm/core/runtime/runtime.mjs +11 -10
  219. package/dist/esm/core/url/join.mjs +0 -1
  220. package/dist/esm/errors/handleNonStatusCodeError.d.mts +2 -0
  221. package/dist/esm/errors/handleNonStatusCodeError.mjs +29 -0
  222. package/package.json +4 -4
  223. package/reference.md +761 -473
  224. package/dist/cjs/core/fetcher/ResponseWithBody.d.ts +0 -4
  225. package/dist/cjs/core/fetcher/ResponseWithBody.js +0 -6
  226. package/dist/cjs/version.d.ts +0 -1
  227. package/dist/esm/core/fetcher/ResponseWithBody.d.mts +0 -4
  228. package/dist/esm/core/fetcher/ResponseWithBody.mjs +0 -3
  229. package/dist/esm/version.d.mts +0 -1
  230. package/dist/esm/version.mjs +0 -1
@@ -0,0 +1,7 @@
1
+ export type BearerToken = string;
2
+ declare function toAuthorizationHeader(token: string | undefined): string | undefined;
3
+ export declare const BearerToken: {
4
+ toAuthorizationHeader: typeof toAuthorizationHeader;
5
+ fromAuthorizationHeader: (header: string) => BearerToken;
6
+ };
7
+ export {};
@@ -0,0 +1,13 @@
1
+ const BEARER_AUTH_HEADER_PREFIX = /^Bearer /i;
2
+ function toAuthorizationHeader(token) {
3
+ if (token == null) {
4
+ return undefined;
5
+ }
6
+ return `Bearer ${token}`;
7
+ }
8
+ export const BearerToken = {
9
+ toAuthorizationHeader: toAuthorizationHeader,
10
+ fromAuthorizationHeader: (header) => {
11
+ return header.replace(BEARER_AUTH_HEADER_PREFIX, "").trim();
12
+ },
13
+ };
@@ -0,0 +1,5 @@
1
+ import type { AuthProvider } from "./AuthProvider.mjs";
2
+ import type { AuthRequest } from "./AuthRequest.mjs";
3
+ export declare class NoOpAuthProvider implements AuthProvider {
4
+ getAuthRequest(): Promise<AuthRequest>;
5
+ }
@@ -0,0 +1,5 @@
1
+ export class NoOpAuthProvider {
2
+ getAuthRequest() {
3
+ return Promise.resolve({ headers: {} });
4
+ }
5
+ }
@@ -0,0 +1,5 @@
1
+ export type { AuthProvider } from "./AuthProvider.mjs";
2
+ export type { AuthRequest } from "./AuthRequest.mjs";
3
+ export { BasicAuth } from "./BasicAuth.mjs";
4
+ export { BearerToken } from "./BearerToken.mjs";
5
+ export { NoOpAuthProvider } from "./NoOpAuthProvider.mjs";
@@ -0,0 +1,3 @@
1
+ export { BasicAuth } from "./BasicAuth.mjs";
2
+ export { BearerToken } from "./BearerToken.mjs";
3
+ export { NoOpAuthProvider } from "./NoOpAuthProvider.mjs";
@@ -0,0 +1,2 @@
1
+ export declare function base64Encode(input: string): string;
2
+ export declare function base64Decode(input: string): string;
@@ -0,0 +1,22 @@
1
+ function base64ToBytes(base64) {
2
+ const binString = atob(base64);
3
+ return Uint8Array.from(binString, (m) => m.codePointAt(0));
4
+ }
5
+ function bytesToBase64(bytes) {
6
+ const binString = String.fromCodePoint(...bytes);
7
+ return btoa(binString);
8
+ }
9
+ export function base64Encode(input) {
10
+ if (typeof Buffer !== "undefined") {
11
+ return Buffer.from(input, "utf8").toString("base64");
12
+ }
13
+ const bytes = new TextEncoder().encode(input);
14
+ return bytesToBase64(bytes);
15
+ }
16
+ export function base64Decode(input) {
17
+ if (typeof Buffer !== "undefined") {
18
+ return Buffer.from(input, "base64").toString("utf8");
19
+ }
20
+ const bytes = base64ToBytes(input);
21
+ return new TextDecoder().decode(bytes);
22
+ }
@@ -1,20 +1,19 @@
1
- import type { ResponseWithBody } from "./ResponseWithBody.mjs";
2
1
  export type BinaryResponse = {
3
2
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bodyUsed) */
4
- bodyUsed: boolean;
3
+ bodyUsed: Response["bodyUsed"];
5
4
  /**
6
5
  * Returns a ReadableStream of the response body.
7
6
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/body)
8
7
  */
9
- stream: () => ReadableStream<Uint8Array>;
8
+ stream: () => Response["body"];
10
9
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/arrayBuffer) */
11
- arrayBuffer: () => Promise<ArrayBuffer>;
10
+ arrayBuffer: () => ReturnType<Response["arrayBuffer"]>;
12
11
  /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/blob) */
13
- blob: () => Promise<Blob>;
12
+ blob: () => ReturnType<Response["blob"]>;
14
13
  /**
15
14
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes)
16
15
  * Some versions of the Fetch API may not support this method.
17
16
  */
18
- bytes?(): Promise<Uint8Array>;
17
+ bytes?(): ReturnType<Response["bytes"]>;
19
18
  };
20
- export declare function getBinaryResponse(response: ResponseWithBody): BinaryResponse;
19
+ export declare function getBinaryResponse(response: Response): BinaryResponse;
@@ -22,7 +22,7 @@ export declare namespace Fetcher {
22
22
  fetchFn?: typeof fetch;
23
23
  logging?: LogConfig | Logger;
24
24
  }
25
- type Error = FailedStatusCodeError | NonJsonError | TimeoutError | UnknownError;
25
+ type Error = FailedStatusCodeError | NonJsonError | BodyIsNullError | TimeoutError | UnknownError;
26
26
  interface FailedStatusCodeError {
27
27
  reason: "status-code";
28
28
  statusCode: number;
@@ -33,6 +33,10 @@ export declare namespace Fetcher {
33
33
  statusCode: number;
34
34
  rawBody: string;
35
35
  }
36
+ interface BodyIsNullError {
37
+ reason: "body-is-null";
38
+ statusCode: number;
39
+ }
36
40
  interface TimeoutError {
37
41
  reason: "timeout";
38
42
  }
@@ -15,23 +15,31 @@ import { getErrorResponseBody } from "./getErrorResponseBody.mjs";
15
15
  import { getFetchFn } from "./getFetchFn.mjs";
16
16
  import { getRequestBody } from "./getRequestBody.mjs";
17
17
  import { getResponseBody } from "./getResponseBody.mjs";
18
+ import { Headers } from "./Headers.mjs";
18
19
  import { makeRequest } from "./makeRequest.mjs";
19
20
  import { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.mjs";
20
21
  import { requestWithRetries } from "./requestWithRetries.mjs";
21
22
  const SENSITIVE_HEADERS = new Set([
22
23
  "authorization",
24
+ "www-authenticate",
23
25
  "x-api-key",
24
26
  "api-key",
27
+ "apikey",
28
+ "x-api-token",
25
29
  "x-auth-token",
30
+ "auth-token",
26
31
  "cookie",
27
32
  "set-cookie",
28
33
  "proxy-authorization",
34
+ "proxy-authenticate",
29
35
  "x-csrf-token",
30
36
  "x-xsrf-token",
37
+ "x-session-token",
38
+ "x-access-token",
31
39
  ]);
32
40
  function redactHeaders(headers) {
33
41
  const filtered = {};
34
- for (const [key, value] of Object.entries(headers)) {
42
+ for (const [key, value] of headers instanceof Headers ? headers.entries() : Object.entries(headers)) {
35
43
  if (SENSITIVE_HEADERS.has(key.toLowerCase())) {
36
44
  filtered[key] = "[REDACTED]";
37
45
  }
@@ -81,20 +89,26 @@ function redactUrl(url) {
81
89
  if (protocolIndex === -1)
82
90
  return url;
83
91
  const afterProtocol = protocolIndex + 3;
84
- const atIndex = url.indexOf("@", afterProtocol);
85
- if (atIndex !== -1) {
86
- const pathStart = url.indexOf("/", afterProtocol);
87
- const queryStart = url.indexOf("?", afterProtocol);
88
- const fragmentStart = url.indexOf("#", afterProtocol);
89
- const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
90
- if (atIndex < firstDelimiter) {
91
- url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
92
+ // Find the first delimiter that marks the end of the authority section
93
+ const pathStart = url.indexOf("/", afterProtocol);
94
+ let queryStart = url.indexOf("?", afterProtocol);
95
+ let fragmentStart = url.indexOf("#", afterProtocol);
96
+ const firstDelimiter = Math.min(pathStart === -1 ? url.length : pathStart, queryStart === -1 ? url.length : queryStart, fragmentStart === -1 ? url.length : fragmentStart);
97
+ // Find the LAST @ before the delimiter (handles multiple @ in credentials)
98
+ let atIndex = -1;
99
+ for (let i = afterProtocol; i < firstDelimiter; i++) {
100
+ if (url[i] === "@") {
101
+ atIndex = i;
92
102
  }
93
103
  }
94
- const queryStart = url.indexOf("?");
104
+ if (atIndex !== -1) {
105
+ url = `${url.slice(0, afterProtocol)}[REDACTED]@${url.slice(atIndex + 1)}`;
106
+ }
107
+ // Recalculate queryStart since url might have changed
108
+ queryStart = url.indexOf("?");
95
109
  if (queryStart === -1)
96
110
  return url;
97
- const fragmentStart = url.indexOf("#", queryStart);
111
+ fragmentStart = url.indexOf("#", queryStart);
98
112
  const queryEnd = fragmentStart !== -1 ? fragmentStart : url.length;
99
113
  const queryString = url.slice(queryStart + 1, queryEnd);
100
114
  if (queryString.length === 0)
@@ -102,15 +116,15 @@ function redactUrl(url) {
102
116
  // FAST PATH: Quick check if any sensitive keywords present
103
117
  // Using indexOf is faster than regex for simple substring matching
104
118
  const lower = queryString.toLowerCase();
105
- const hasSensitive = lower.includes("token") || // catches token, access_token, auth_token, etc.
106
- lower.includes("key") || // catches key, api_key, apikey, api-key, etc.
107
- lower.includes("password") || // catches password
108
- lower.includes("passwd") || // catches passwd
109
- lower.includes("secret") || // catches secret, api_secret, etc.
110
- lower.includes("session") || // catches session, session_id, session-id
111
- lower.includes("auth"); // catches auth_token, auth-token, etc.
119
+ const hasSensitive = lower.includes("token") ||
120
+ lower.includes("key") ||
121
+ lower.includes("password") ||
122
+ lower.includes("passwd") ||
123
+ lower.includes("secret") ||
124
+ lower.includes("session") ||
125
+ lower.includes("auth");
112
126
  if (!hasSensitive) {
113
- return url; // Early exit - no sensitive params
127
+ return url;
114
128
  }
115
129
  // SLOW PATH: Parse and redact
116
130
  const redactedParams = [];
@@ -137,9 +151,10 @@ function redactUrl(url) {
137
151
  function getHeaders(args) {
138
152
  return __awaiter(this, void 0, void 0, function* () {
139
153
  var _a;
140
- const newHeaders = {};
154
+ const newHeaders = new Headers();
155
+ newHeaders.set("Accept", args.responseType === "json" ? "application/json" : args.responseType === "text" ? "text/plain" : "*/*");
141
156
  if (args.body !== undefined && args.contentType != null) {
142
- newHeaders["Content-Type"] = args.contentType;
157
+ newHeaders.set("Content-Type", args.contentType);
143
158
  }
144
159
  if (args.headers == null) {
145
160
  return newHeaders;
@@ -147,13 +162,13 @@ function getHeaders(args) {
147
162
  for (const [key, value] of Object.entries(args.headers)) {
148
163
  const result = yield EndpointSupplier.get(value, { endpointMetadata: (_a = args.endpointMetadata) !== null && _a !== void 0 ? _a : {} });
149
164
  if (typeof result === "string") {
150
- newHeaders[key] = result;
165
+ newHeaders.set(key, result);
151
166
  continue;
152
167
  }
153
168
  if (result == null) {
154
169
  continue;
155
170
  }
156
- newHeaders[key] = `${result}`;
171
+ newHeaders.set(key, `${result}`);
157
172
  }
158
173
  return newHeaders;
159
174
  });
@@ -189,12 +204,14 @@ export function fetcherImpl(args) {
189
204
  method: args.method,
190
205
  url: redactUrl(url),
191
206
  statusCode: response.status,
207
+ responseHeaders: redactHeaders(response.headers),
192
208
  };
193
209
  logger.debug("HTTP request succeeded", metadata);
194
210
  }
211
+ const body = yield getResponseBody(response, args.responseType);
195
212
  return {
196
213
  ok: true,
197
- body: (yield getResponseBody(response, args.responseType)),
214
+ body: body,
198
215
  headers: response.headers,
199
216
  rawResponse: toRawResponse(response),
200
217
  };
@@ -205,6 +222,7 @@ export function fetcherImpl(args) {
205
222
  method: args.method,
206
223
  url: redactUrl(url),
207
224
  statusCode: response.status,
225
+ responseHeaders: redactHeaders(Object.fromEntries(response.headers.entries())),
208
226
  };
209
227
  logger.error("HTTP request failed with error status", metadata);
210
228
  }
@@ -9,12 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { fromJson } from "../json.mjs";
11
11
  import { getBinaryResponse } from "./BinaryResponse.mjs";
12
- import { isResponseWithBody } from "./ResponseWithBody.mjs";
13
12
  export function getResponseBody(response, responseType) {
14
13
  return __awaiter(this, void 0, void 0, function* () {
15
- if (!isResponseWithBody(response)) {
16
- return undefined;
17
- }
18
14
  switch (responseType) {
19
15
  case "binary-response":
20
16
  return getBinaryResponse(response);
@@ -23,8 +19,26 @@ export function getResponseBody(response, responseType) {
23
19
  case "arrayBuffer":
24
20
  return yield response.arrayBuffer();
25
21
  case "sse":
22
+ if (response.body == null) {
23
+ return {
24
+ ok: false,
25
+ error: {
26
+ reason: "body-is-null",
27
+ statusCode: response.status,
28
+ },
29
+ };
30
+ }
26
31
  return response.body;
27
32
  case "streaming":
33
+ if (response.body == null) {
34
+ return {
35
+ ok: false,
36
+ error: {
37
+ reason: "body-is-null",
38
+ statusCode: response.status,
39
+ },
40
+ };
41
+ }
28
42
  return response.body;
29
43
  case "text":
30
44
  return yield response.text();
@@ -1 +1 @@
1
- export declare const makeRequest: (fetchFn: (url: string, init: RequestInit) => Promise<Response>, url: string, method: string, headers: Record<string, string>, requestBody: BodyInit | undefined, timeoutMs?: number, abortSignal?: AbortSignal, withCredentials?: boolean, duplex?: "half") => Promise<Response>;
1
+ export declare const makeRequest: (fetchFn: (url: string, init: RequestInit) => Promise<Response>, url: string, method: string, headers: Headers | Record<string, string>, requestBody: BodyInit | undefined, timeoutMs?: number, abortSignal?: AbortSignal, withCredentials?: boolean, duplex?: "half") => Promise<Response>;
@@ -10,14 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { anySignal, getTimeoutSignal } from "./signals.mjs";
11
11
  export const makeRequest = (fetchFn, url, method, headers, requestBody, timeoutMs, abortSignal, withCredentials, duplex) => __awaiter(void 0, void 0, void 0, function* () {
12
12
  const signals = [];
13
- // Add timeout signal
14
13
  let timeoutAbortId;
15
14
  if (timeoutMs != null) {
16
15
  const { signal, abortId } = getTimeoutSignal(timeoutMs);
17
16
  timeoutAbortId = abortId;
18
17
  signals.push(signal);
19
18
  }
20
- // Add arbitrary signal
21
19
  if (abortSignal != null) {
22
20
  signals.push(abortSignal);
23
21
  }
@@ -12,25 +12,20 @@ const MAX_RETRY_DELAY = 60000; // in milliseconds
12
12
  const DEFAULT_MAX_RETRIES = 2;
13
13
  const JITTER_FACTOR = 0.2; // 20% random jitter
14
14
  function addPositiveJitter(delay) {
15
- // Generate a random value between 0 and +JITTER_FACTOR
16
15
  const jitterMultiplier = 1 + Math.random() * JITTER_FACTOR;
17
16
  return delay * jitterMultiplier;
18
17
  }
19
18
  function addSymmetricJitter(delay) {
20
- // Generate a random value in a JITTER_FACTOR-sized percentage range around delay
21
19
  const jitterMultiplier = 1 + (Math.random() - 0.5) * JITTER_FACTOR;
22
20
  return delay * jitterMultiplier;
23
21
  }
24
22
  function getRetryDelayFromHeaders(response, retryAttempt) {
25
- // Check for Retry-After header first (RFC 7231), with no jitter
26
23
  const retryAfter = response.headers.get("Retry-After");
27
24
  if (retryAfter) {
28
- // Parse as number of seconds...
29
25
  const retryAfterSeconds = parseInt(retryAfter, 10);
30
26
  if (!Number.isNaN(retryAfterSeconds) && retryAfterSeconds > 0) {
31
27
  return Math.min(retryAfterSeconds * 1000, MAX_RETRY_DELAY);
32
28
  }
33
- // ...or as an HTTP date; both are valid
34
29
  const retryAfterDate = new Date(retryAfter);
35
30
  if (!Number.isNaN(retryAfterDate.getTime())) {
36
31
  const delay = retryAfterDate.getTime() - Date.now();
@@ -39,19 +34,16 @@ function getRetryDelayFromHeaders(response, retryAttempt) {
39
34
  }
40
35
  }
41
36
  }
42
- // Then check for industry-standard X-RateLimit-Reset header, with positive jitter
43
37
  const rateLimitReset = response.headers.get("X-RateLimit-Reset");
44
38
  if (rateLimitReset) {
45
39
  const resetTime = parseInt(rateLimitReset, 10);
46
40
  if (!Number.isNaN(resetTime)) {
47
- // Assume Unix timestamp in epoch seconds
48
41
  const delay = resetTime * 1000 - Date.now();
49
42
  if (delay > 0) {
50
43
  return addPositiveJitter(Math.min(delay, MAX_RETRY_DELAY));
51
44
  }
52
45
  }
53
46
  }
54
- // Fall back to exponential backoff, with symmetric jitter
55
47
  return addSymmetricJitter(Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY));
56
48
  }
57
49
  export function requestWithRetries(requestFn_1) {
@@ -59,7 +51,6 @@ export function requestWithRetries(requestFn_1) {
59
51
  let response = yield requestFn();
60
52
  for (let i = 0; i < maxRetries; ++i) {
61
53
  if ([408, 429].includes(response.status) || response.status >= 500) {
62
- // Get delay with appropriate jitter applied
63
54
  const delay = getRetryDelayFromHeaders(response, i);
64
55
  yield new Promise((resolve) => setTimeout(resolve, delay));
65
56
  response = yield requestFn();
@@ -1,11 +1,5 @@
1
1
  export declare function getTimeoutSignal(timeoutMs: number): {
2
2
  signal: AbortSignal;
3
- abortId: NodeJS.Timeout;
3
+ abortId: ReturnType<typeof setTimeout>;
4
4
  };
5
- /**
6
- * Returns an abort signal that is getting aborted when
7
- * at least one of the specified abort signals is aborted.
8
- *
9
- * Requires at least node.js 18.
10
- */
11
5
  export declare function anySignal(...args: AbortSignal[] | [AbortSignal[]]): AbortSignal;
@@ -4,26 +4,14 @@ export function getTimeoutSignal(timeoutMs) {
4
4
  const abortId = setTimeout(() => controller.abort(TIMEOUT), timeoutMs);
5
5
  return { signal: controller.signal, abortId };
6
6
  }
7
- /**
8
- * Returns an abort signal that is getting aborted when
9
- * at least one of the specified abort signals is aborted.
10
- *
11
- * Requires at least node.js 18.
12
- */
13
7
  export function anySignal(...args) {
14
- // Allowing signals to be passed either as array
15
- // of signals or as multiple arguments.
16
8
  const signals = (args.length === 1 && Array.isArray(args[0]) ? args[0] : args);
17
9
  const controller = new AbortController();
18
10
  for (const signal of signals) {
19
11
  if (signal.aborted) {
20
- // Exiting early if one of the signals
21
- // is already aborted.
22
12
  controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason);
23
13
  break;
24
14
  }
25
- // Listening for signals and removing the listeners
26
- // when at least one symbol is aborted.
27
15
  signal.addEventListener("abort", () => controller.abort(signal === null || signal === void 0 ? void 0 : signal.reason), {
28
16
  signal: controller.signal,
29
17
  });
@@ -1,3 +1,5 @@
1
+ export * from "./auth/index.mjs";
2
+ export * from "./base64.mjs";
1
3
  export * from "./fetcher/index.mjs";
2
4
  export * as file from "./file/index.mjs";
3
5
  export * from "./form-data-utils/index.mjs";
@@ -1,3 +1,5 @@
1
+ export * from "./auth/index.mjs";
2
+ export * from "./base64.mjs";
1
3
  export * from "./fetcher/index.mjs";
2
4
  export * as file from "./file/index.mjs";
3
5
  export * from "./form-data-utils/index.mjs";
@@ -46,7 +46,7 @@ export class Logger {
46
46
  * @returns True if the level should be logged
47
47
  */
48
48
  shouldLog(level) {
49
- return !this.silent && this.level >= logLevelMap[level];
49
+ return !this.silent && this.level <= logLevelMap[level];
50
50
  }
51
51
  /**
52
52
  * Checks if debug logging is enabled.
@@ -68,6 +68,17 @@ function evaluateRuntime() {
68
68
  version: Bun.version,
69
69
  };
70
70
  }
71
+ /**
72
+ * A constant that indicates whether the environment the code is running is in React-Native.
73
+ * This check should come before Node.js detection since React Native may have a process polyfill.
74
+ * https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
75
+ */
76
+ const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
77
+ if (isReactNative) {
78
+ return {
79
+ type: "react-native",
80
+ };
81
+ }
71
82
  /**
72
83
  * A constant that indicates whether the environment the code is running is Node.JS.
73
84
  */
@@ -83,16 +94,6 @@ function evaluateRuntime() {
83
94
  parsedVersion: Number(process.versions.node.split(".")[0]),
84
95
  };
85
96
  }
86
- /**
87
- * A constant that indicates whether the environment the code is running is in React-Native.
88
- * https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Core/setUpNavigator.js
89
- */
90
- const isReactNative = typeof navigator !== "undefined" && (navigator === null || navigator === void 0 ? void 0 : navigator.product) === "ReactNative";
91
- if (isReactNative) {
92
- return {
93
- type: "react-native",
94
- };
95
- }
96
97
  return {
97
98
  type: "unknown",
98
99
  };
@@ -11,7 +11,6 @@ export function join(base, ...segments) {
11
11
  url = new URL(base);
12
12
  }
13
13
  catch (_a) {
14
- // Fallback to path joining if URL is malformed
15
14
  return joinPath(base, ...segments);
16
15
  }
17
16
  const lastSegment = segments[segments.length - 1];
@@ -0,0 +1,2 @@
1
+ import type * as core from "../core/index.mjs";
2
+ export declare function handleNonStatusCodeError(error: core.Fetcher.Error, rawResponse: core.RawResponse, method: string, path: string): never;
@@ -0,0 +1,29 @@
1
+ // This file was auto-generated by Fern from our API Definition.
2
+ import * as errors from "./index.mjs";
3
+ export function handleNonStatusCodeError(error, rawResponse, method, path) {
4
+ switch (error.reason) {
5
+ case "non-json":
6
+ throw new errors.PayabliError({
7
+ statusCode: error.statusCode,
8
+ body: error.rawBody,
9
+ rawResponse: rawResponse,
10
+ });
11
+ case "body-is-null":
12
+ throw new errors.PayabliError({
13
+ statusCode: error.statusCode,
14
+ rawResponse: rawResponse,
15
+ });
16
+ case "timeout":
17
+ throw new errors.PayabliTimeoutError(`Timeout exceeded when calling ${method} ${path}.`);
18
+ case "unknown":
19
+ throw new errors.PayabliError({
20
+ message: error.errorMessage,
21
+ rawResponse: rawResponse,
22
+ });
23
+ default:
24
+ throw new errors.PayabliError({
25
+ message: "Unknown error",
26
+ rawResponse: rawResponse,
27
+ });
28
+ }
29
+ }
package/package.json CHANGED
@@ -1,8 +1,5 @@
1
1
  {
2
2
  "name": "@payabli/sdk-node",
3
- "version": "0.0.116",
4
- "private": false,
5
- "repository": "github:payabli/sdk-node",
6
3
  "type": "commonjs",
7
4
  "main": "./dist/cjs/index.js",
8
5
  "module": "./dist/esm/index.mjs",
@@ -62,5 +59,8 @@
62
59
  "engines": {
63
60
  "node": ">=18.0.0"
64
61
  },
65
- "sideEffects": false
62
+ "sideEffects": false,
63
+ "version": "0.0.117",
64
+ "private": false,
65
+ "repository": "https://github.com/payabli/sdk-node"
66
66
  }