@kard-financial/sdk 12.3.0 → 12.4.0

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 (249) hide show
  1. package/README.md +106 -15
  2. package/dist/cjs/BaseClient.d.ts +7 -8
  3. package/dist/cjs/BaseClient.js +3 -3
  4. package/dist/cjs/Client.d.ts +13 -2
  5. package/dist/cjs/Client.js +67 -0
  6. package/dist/cjs/api/resources/auth/client/Client.d.ts +1 -2
  7. package/dist/cjs/api/resources/auth/client/Client.js +3 -23
  8. package/dist/cjs/api/resources/auth/exports.d.ts +2 -0
  9. package/dist/cjs/api/resources/auth/exports.js +21 -0
  10. package/dist/cjs/api/resources/commons/errors/ConflictError.js +5 -1
  11. package/dist/cjs/api/resources/commons/errors/DoesNotExistError.js +5 -1
  12. package/dist/cjs/api/resources/commons/errors/ForbiddenError.js +5 -1
  13. package/dist/cjs/api/resources/commons/errors/InternalServerError.js +5 -1
  14. package/dist/cjs/api/resources/commons/errors/InvalidRequest.js +5 -1
  15. package/dist/cjs/api/resources/commons/errors/UnauthorizedError.js +5 -1
  16. package/dist/cjs/api/resources/commons/exports.d.ts +1 -0
  17. package/dist/cjs/api/resources/commons/exports.js +18 -0
  18. package/dist/cjs/api/resources/commons/types/ErrorObject.d.ts +2 -2
  19. package/dist/cjs/api/resources/commons/types/ErrorSource.d.ts +3 -3
  20. package/dist/cjs/api/resources/commons/types/Links.d.ts +2 -2
  21. package/dist/cjs/api/resources/files/client/Client.d.ts +1 -2
  22. package/dist/cjs/api/resources/files/client/Client.js +11 -47
  23. package/dist/cjs/api/resources/files/exports.d.ts +2 -0
  24. package/dist/cjs/api/resources/files/exports.js +21 -0
  25. package/dist/cjs/api/resources/notifications/client/Client.d.ts +1 -2
  26. package/dist/cjs/api/resources/notifications/exports.d.ts +3 -0
  27. package/dist/cjs/api/resources/notifications/exports.js +22 -0
  28. package/dist/cjs/api/resources/notifications/resources/subscriptions/client/Client.d.ts +1 -2
  29. package/dist/cjs/api/resources/notifications/resources/subscriptions/client/Client.js +7 -64
  30. package/dist/cjs/api/resources/notifications/resources/subscriptions/exports.d.ts +2 -0
  31. package/dist/cjs/api/resources/notifications/resources/subscriptions/exports.js +21 -0
  32. package/dist/cjs/api/resources/notifications/resources/subscriptions/types/UpdateSubscriptionRequestAttributes.d.ts +3 -3
  33. package/dist/cjs/api/resources/notifications/types/AuditUpdateAttributes.d.ts +3 -3
  34. package/dist/cjs/api/resources/notifications/types/FailedTransactionAttributes.d.ts +1 -1
  35. package/dist/cjs/api/resources/notifications/types/NotificationPayload.d.ts +2 -2
  36. package/dist/cjs/api/resources/notifications/types/RewardNotificationAttributes.d.ts +2 -2
  37. package/dist/cjs/api/resources/ping/client/Client.d.ts +1 -2
  38. package/dist/cjs/api/resources/ping/client/Client.js +2 -20
  39. package/dist/cjs/api/resources/ping/errors/NetworkBlockedError.js +5 -1
  40. package/dist/cjs/api/resources/ping/exports.d.ts +2 -0
  41. package/dist/cjs/api/resources/ping/exports.js +21 -0
  42. package/dist/cjs/api/resources/transactions/client/Client.d.ts +1 -2
  43. package/dist/cjs/api/resources/transactions/client/Client.js +12 -113
  44. package/dist/cjs/api/resources/transactions/errors/CreateAuditMultiStatus.js +5 -1
  45. package/dist/cjs/api/resources/transactions/errors/CreateIncomingTransactionsMultiStatus.js +5 -1
  46. package/dist/cjs/api/resources/transactions/errors/FraudMultiStatus.js +5 -1
  47. package/dist/cjs/api/resources/transactions/exports.d.ts +2 -0
  48. package/dist/cjs/api/resources/transactions/exports.js +21 -0
  49. package/dist/cjs/api/resources/transactions/types/CoreTransactionAttributes.d.ts +3 -3
  50. package/dist/cjs/api/resources/transactions/types/CreateAuditMultiStatusResponse.d.ts +1 -1
  51. package/dist/cjs/api/resources/transactions/types/GetEarnedRewardsResponse.d.ts +1 -1
  52. package/dist/cjs/api/resources/transactions/types/MatchedTransactionsAttributes.d.ts +14 -14
  53. package/dist/cjs/api/resources/transactions/types/Merchant.d.ts +9 -9
  54. package/dist/cjs/api/resources/transactions/types/RewardedTransactionAttributes.d.ts +3 -3
  55. package/dist/cjs/api/resources/transactions/types/TransactionsAttributes.d.ts +18 -18
  56. package/dist/cjs/api/resources/users/client/Client.d.ts +1 -2
  57. package/dist/cjs/api/resources/users/client/Client.js +5 -80
  58. package/dist/cjs/api/resources/users/errors/MultiStatus.js +5 -1
  59. package/dist/cjs/api/resources/users/exports.d.ts +3 -0
  60. package/dist/cjs/api/resources/users/exports.js +22 -0
  61. package/dist/cjs/api/resources/users/resources/attributions/client/Client.d.ts +1 -2
  62. package/dist/cjs/api/resources/users/resources/attributions/client/Client.js +20 -94
  63. package/dist/cjs/api/resources/users/resources/attributions/exports.d.ts +2 -0
  64. package/dist/cjs/api/resources/users/resources/attributions/exports.js +21 -0
  65. package/dist/cjs/api/resources/users/resources/attributions/types/ActivateOfferResponse.d.ts +1 -1
  66. package/dist/cjs/api/resources/users/resources/attributions/types/AttributionState.d.ts +2 -2
  67. package/dist/cjs/api/resources/users/resources/attributions/types/BoostOfferResponse.d.ts +1 -1
  68. package/dist/cjs/api/resources/users/resources/attributions/types/NotificationAttributionAttributes.d.ts +1 -1
  69. package/dist/cjs/api/resources/users/resources/attributions/types/OfferAttributionAttributes.d.ts +1 -1
  70. package/dist/cjs/api/resources/users/resources/auth/client/Client.d.ts +1 -2
  71. package/dist/cjs/api/resources/users/resources/auth/client/Client.js +2 -20
  72. package/dist/cjs/api/resources/users/resources/auth/exports.d.ts +2 -0
  73. package/dist/cjs/api/resources/users/resources/auth/exports.js +21 -0
  74. package/dist/cjs/api/resources/users/resources/rewards/client/Client.d.ts +1 -2
  75. package/dist/cjs/api/resources/users/resources/rewards/client/Client.js +39 -144
  76. package/dist/cjs/api/resources/users/resources/rewards/exports.d.ts +2 -0
  77. package/dist/cjs/api/resources/users/resources/rewards/exports.js +21 -0
  78. package/dist/cjs/api/resources/users/resources/rewards/types/CtaComponent.d.ts +2 -2
  79. package/dist/cjs/api/resources/users/resources/rewards/types/LocationData.d.ts +1 -1
  80. package/dist/cjs/api/resources/users/resources/rewards/types/LocationsResponseObject.d.ts +1 -1
  81. package/dist/cjs/api/resources/users/resources/rewards/types/LogoFlare.d.ts +1 -1
  82. package/dist/cjs/api/resources/users/resources/rewards/types/OfferCommonFields.d.ts +8 -8
  83. package/dist/cjs/api/resources/users/resources/rewards/types/OfferComponents.d.ts +9 -9
  84. package/dist/cjs/api/resources/users/resources/rewards/types/OffersMeta.d.ts +1 -1
  85. package/dist/cjs/api/resources/users/resources/rewards/types/OffersResponseObject.d.ts +2 -2
  86. package/dist/cjs/api/resources/users/resources/rewards/types/ProgressBar.d.ts +1 -1
  87. package/dist/cjs/api/resources/users/resources/rewards/types/ProgressBarLabelPair.d.ts +2 -2
  88. package/dist/cjs/api/resources/users/resources/rewards/types/ProgressBarLabels.d.ts +1 -1
  89. package/dist/cjs/api/resources/users/resources/rewards/types/ProgressBarSegment.d.ts +1 -1
  90. package/dist/cjs/api/resources/users/resources/rewards/types/ProgressBarSegments.d.ts +1 -1
  91. package/dist/cjs/api/resources/users/resources/rewards/types/StandardOffer.d.ts +1 -1
  92. package/dist/cjs/api/resources/users/resources/uploads/client/Client.d.ts +1 -2
  93. package/dist/cjs/api/resources/users/resources/uploads/client/Client.js +4 -60
  94. package/dist/cjs/api/resources/users/resources/uploads/errors/UploadPartMultiStatus.js +5 -1
  95. package/dist/cjs/api/resources/users/resources/uploads/exports.d.ts +2 -0
  96. package/dist/cjs/api/resources/users/resources/uploads/exports.js +21 -0
  97. package/dist/cjs/api/resources/users/resources/uploads/types/CreateUploadPartMultiStatusResponse.d.ts +1 -1
  98. package/dist/cjs/api/resources/users/types/CreateUsersMultiStatusResponse.d.ts +1 -1
  99. package/dist/cjs/api/resources/users/types/UpdateUserRequestAttributes.d.ts +5 -5
  100. package/dist/cjs/api/resources/users/types/UserRequestAttributes.d.ts +6 -6
  101. package/dist/cjs/auth/OAuthAuthProvider.d.ts +36 -14
  102. package/dist/cjs/auth/OAuthAuthProvider.js +108 -40
  103. package/dist/cjs/core/auth/BasicAuth.d.ts +2 -2
  104. package/dist/cjs/core/auth/BasicAuth.js +7 -1
  105. package/dist/cjs/core/fetcher/BinaryResponse.d.ts +1 -1
  106. package/dist/cjs/core/fetcher/EndpointSupplier.d.ts +2 -2
  107. package/dist/cjs/core/fetcher/Fetcher.d.ts +3 -2
  108. package/dist/cjs/core/fetcher/Fetcher.js +12 -2
  109. package/dist/cjs/core/fetcher/index.d.ts +2 -0
  110. package/dist/cjs/core/fetcher/index.js +3 -1
  111. package/dist/cjs/core/fetcher/makePassthroughRequest.d.ts +49 -0
  112. package/dist/cjs/core/fetcher/makePassthroughRequest.js +135 -0
  113. package/dist/cjs/core/fetcher/makeRequest.d.ts +6 -1
  114. package/dist/cjs/core/fetcher/makeRequest.js +30 -9
  115. package/dist/cjs/core/headers.d.ts +2 -2
  116. package/dist/cjs/core/runtime/runtime.js +8 -7
  117. package/dist/cjs/errors/KardApiError.d.ts +3 -1
  118. package/dist/cjs/errors/KardApiError.js +9 -2
  119. package/dist/cjs/errors/KardApiTimeoutError.d.ts +4 -1
  120. package/dist/cjs/errors/KardApiTimeoutError.js +9 -2
  121. package/dist/cjs/errors/handleNonStatusCodeError.d.ts +2 -0
  122. package/dist/cjs/errors/handleNonStatusCodeError.js +68 -0
  123. package/dist/cjs/version.d.ts +1 -1
  124. package/dist/cjs/version.js +1 -1
  125. package/dist/esm/BaseClient.d.mts +7 -8
  126. package/dist/esm/BaseClient.mjs +3 -3
  127. package/dist/esm/Client.d.mts +13 -2
  128. package/dist/esm/Client.mjs +34 -0
  129. package/dist/esm/api/resources/auth/client/Client.d.mts +1 -2
  130. package/dist/esm/api/resources/auth/client/Client.mjs +3 -23
  131. package/dist/esm/api/resources/auth/exports.d.mts +2 -0
  132. package/dist/esm/api/resources/auth/exports.mjs +3 -0
  133. package/dist/esm/api/resources/commons/errors/ConflictError.mjs +5 -1
  134. package/dist/esm/api/resources/commons/errors/DoesNotExistError.mjs +5 -1
  135. package/dist/esm/api/resources/commons/errors/ForbiddenError.mjs +5 -1
  136. package/dist/esm/api/resources/commons/errors/InternalServerError.mjs +5 -1
  137. package/dist/esm/api/resources/commons/errors/InvalidRequest.mjs +5 -1
  138. package/dist/esm/api/resources/commons/errors/UnauthorizedError.mjs +5 -1
  139. package/dist/esm/api/resources/commons/exports.d.mts +1 -0
  140. package/dist/esm/api/resources/commons/exports.mjs +2 -0
  141. package/dist/esm/api/resources/commons/types/ErrorObject.d.mts +2 -2
  142. package/dist/esm/api/resources/commons/types/ErrorSource.d.mts +3 -3
  143. package/dist/esm/api/resources/commons/types/Links.d.mts +2 -2
  144. package/dist/esm/api/resources/files/client/Client.d.mts +1 -2
  145. package/dist/esm/api/resources/files/client/Client.mjs +11 -47
  146. package/dist/esm/api/resources/files/exports.d.mts +2 -0
  147. package/dist/esm/api/resources/files/exports.mjs +3 -0
  148. package/dist/esm/api/resources/notifications/client/Client.d.mts +1 -2
  149. package/dist/esm/api/resources/notifications/exports.d.mts +3 -0
  150. package/dist/esm/api/resources/notifications/exports.mjs +4 -0
  151. package/dist/esm/api/resources/notifications/resources/subscriptions/client/Client.d.mts +1 -2
  152. package/dist/esm/api/resources/notifications/resources/subscriptions/client/Client.mjs +7 -64
  153. package/dist/esm/api/resources/notifications/resources/subscriptions/exports.d.mts +2 -0
  154. package/dist/esm/api/resources/notifications/resources/subscriptions/exports.mjs +3 -0
  155. package/dist/esm/api/resources/notifications/resources/subscriptions/types/UpdateSubscriptionRequestAttributes.d.mts +3 -3
  156. package/dist/esm/api/resources/notifications/types/AuditUpdateAttributes.d.mts +3 -3
  157. package/dist/esm/api/resources/notifications/types/FailedTransactionAttributes.d.mts +1 -1
  158. package/dist/esm/api/resources/notifications/types/NotificationPayload.d.mts +2 -2
  159. package/dist/esm/api/resources/notifications/types/RewardNotificationAttributes.d.mts +2 -2
  160. package/dist/esm/api/resources/ping/client/Client.d.mts +1 -2
  161. package/dist/esm/api/resources/ping/client/Client.mjs +2 -20
  162. package/dist/esm/api/resources/ping/errors/NetworkBlockedError.mjs +5 -1
  163. package/dist/esm/api/resources/ping/exports.d.mts +2 -0
  164. package/dist/esm/api/resources/ping/exports.mjs +3 -0
  165. package/dist/esm/api/resources/transactions/client/Client.d.mts +1 -2
  166. package/dist/esm/api/resources/transactions/client/Client.mjs +12 -113
  167. package/dist/esm/api/resources/transactions/errors/CreateAuditMultiStatus.mjs +5 -1
  168. package/dist/esm/api/resources/transactions/errors/CreateIncomingTransactionsMultiStatus.mjs +5 -1
  169. package/dist/esm/api/resources/transactions/errors/FraudMultiStatus.mjs +5 -1
  170. package/dist/esm/api/resources/transactions/exports.d.mts +2 -0
  171. package/dist/esm/api/resources/transactions/exports.mjs +3 -0
  172. package/dist/esm/api/resources/transactions/types/CoreTransactionAttributes.d.mts +3 -3
  173. package/dist/esm/api/resources/transactions/types/CreateAuditMultiStatusResponse.d.mts +1 -1
  174. package/dist/esm/api/resources/transactions/types/GetEarnedRewardsResponse.d.mts +1 -1
  175. package/dist/esm/api/resources/transactions/types/MatchedTransactionsAttributes.d.mts +14 -14
  176. package/dist/esm/api/resources/transactions/types/Merchant.d.mts +9 -9
  177. package/dist/esm/api/resources/transactions/types/RewardedTransactionAttributes.d.mts +3 -3
  178. package/dist/esm/api/resources/transactions/types/TransactionsAttributes.d.mts +18 -18
  179. package/dist/esm/api/resources/users/client/Client.d.mts +1 -2
  180. package/dist/esm/api/resources/users/client/Client.mjs +5 -80
  181. package/dist/esm/api/resources/users/errors/MultiStatus.mjs +5 -1
  182. package/dist/esm/api/resources/users/exports.d.mts +3 -0
  183. package/dist/esm/api/resources/users/exports.mjs +4 -0
  184. package/dist/esm/api/resources/users/resources/attributions/client/Client.d.mts +1 -2
  185. package/dist/esm/api/resources/users/resources/attributions/client/Client.mjs +20 -94
  186. package/dist/esm/api/resources/users/resources/attributions/exports.d.mts +2 -0
  187. package/dist/esm/api/resources/users/resources/attributions/exports.mjs +3 -0
  188. package/dist/esm/api/resources/users/resources/attributions/types/ActivateOfferResponse.d.mts +1 -1
  189. package/dist/esm/api/resources/users/resources/attributions/types/AttributionState.d.mts +2 -2
  190. package/dist/esm/api/resources/users/resources/attributions/types/BoostOfferResponse.d.mts +1 -1
  191. package/dist/esm/api/resources/users/resources/attributions/types/NotificationAttributionAttributes.d.mts +1 -1
  192. package/dist/esm/api/resources/users/resources/attributions/types/OfferAttributionAttributes.d.mts +1 -1
  193. package/dist/esm/api/resources/users/resources/auth/client/Client.d.mts +1 -2
  194. package/dist/esm/api/resources/users/resources/auth/client/Client.mjs +2 -20
  195. package/dist/esm/api/resources/users/resources/auth/exports.d.mts +2 -0
  196. package/dist/esm/api/resources/users/resources/auth/exports.mjs +3 -0
  197. package/dist/esm/api/resources/users/resources/rewards/client/Client.d.mts +1 -2
  198. package/dist/esm/api/resources/users/resources/rewards/client/Client.mjs +39 -144
  199. package/dist/esm/api/resources/users/resources/rewards/exports.d.mts +2 -0
  200. package/dist/esm/api/resources/users/resources/rewards/exports.mjs +3 -0
  201. package/dist/esm/api/resources/users/resources/rewards/types/CtaComponent.d.mts +2 -2
  202. package/dist/esm/api/resources/users/resources/rewards/types/LocationData.d.mts +1 -1
  203. package/dist/esm/api/resources/users/resources/rewards/types/LocationsResponseObject.d.mts +1 -1
  204. package/dist/esm/api/resources/users/resources/rewards/types/LogoFlare.d.mts +1 -1
  205. package/dist/esm/api/resources/users/resources/rewards/types/OfferCommonFields.d.mts +8 -8
  206. package/dist/esm/api/resources/users/resources/rewards/types/OfferComponents.d.mts +9 -9
  207. package/dist/esm/api/resources/users/resources/rewards/types/OffersMeta.d.mts +1 -1
  208. package/dist/esm/api/resources/users/resources/rewards/types/OffersResponseObject.d.mts +2 -2
  209. package/dist/esm/api/resources/users/resources/rewards/types/ProgressBar.d.mts +1 -1
  210. package/dist/esm/api/resources/users/resources/rewards/types/ProgressBarLabelPair.d.mts +2 -2
  211. package/dist/esm/api/resources/users/resources/rewards/types/ProgressBarLabels.d.mts +1 -1
  212. package/dist/esm/api/resources/users/resources/rewards/types/ProgressBarSegment.d.mts +1 -1
  213. package/dist/esm/api/resources/users/resources/rewards/types/ProgressBarSegments.d.mts +1 -1
  214. package/dist/esm/api/resources/users/resources/rewards/types/StandardOffer.d.mts +1 -1
  215. package/dist/esm/api/resources/users/resources/uploads/client/Client.d.mts +1 -2
  216. package/dist/esm/api/resources/users/resources/uploads/client/Client.mjs +4 -60
  217. package/dist/esm/api/resources/users/resources/uploads/errors/UploadPartMultiStatus.mjs +5 -1
  218. package/dist/esm/api/resources/users/resources/uploads/exports.d.mts +2 -0
  219. package/dist/esm/api/resources/users/resources/uploads/exports.mjs +3 -0
  220. package/dist/esm/api/resources/users/resources/uploads/types/CreateUploadPartMultiStatusResponse.d.mts +1 -1
  221. package/dist/esm/api/resources/users/types/CreateUsersMultiStatusResponse.d.mts +1 -1
  222. package/dist/esm/api/resources/users/types/UpdateUserRequestAttributes.d.mts +5 -5
  223. package/dist/esm/api/resources/users/types/UserRequestAttributes.d.mts +6 -6
  224. package/dist/esm/auth/OAuthAuthProvider.d.mts +36 -14
  225. package/dist/esm/auth/OAuthAuthProvider.mjs +106 -39
  226. package/dist/esm/core/auth/BasicAuth.d.mts +2 -2
  227. package/dist/esm/core/auth/BasicAuth.mjs +7 -1
  228. package/dist/esm/core/fetcher/BinaryResponse.d.mts +1 -1
  229. package/dist/esm/core/fetcher/EndpointSupplier.d.mts +2 -2
  230. package/dist/esm/core/fetcher/Fetcher.d.mts +3 -2
  231. package/dist/esm/core/fetcher/Fetcher.mjs +12 -2
  232. package/dist/esm/core/fetcher/index.d.mts +2 -0
  233. package/dist/esm/core/fetcher/index.mjs +1 -0
  234. package/dist/esm/core/fetcher/makePassthroughRequest.d.mts +49 -0
  235. package/dist/esm/core/fetcher/makePassthroughRequest.mjs +132 -0
  236. package/dist/esm/core/fetcher/makeRequest.d.mts +6 -1
  237. package/dist/esm/core/fetcher/makeRequest.mjs +28 -9
  238. package/dist/esm/core/headers.d.mts +2 -2
  239. package/dist/esm/core/runtime/runtime.mjs +8 -7
  240. package/dist/esm/errors/KardApiError.d.mts +3 -1
  241. package/dist/esm/errors/KardApiError.mjs +9 -2
  242. package/dist/esm/errors/KardApiTimeoutError.d.mts +4 -1
  243. package/dist/esm/errors/KardApiTimeoutError.mjs +9 -2
  244. package/dist/esm/errors/handleNonStatusCodeError.d.mts +2 -0
  245. package/dist/esm/errors/handleNonStatusCodeError.mjs +32 -0
  246. package/dist/esm/version.d.mts +1 -1
  247. package/dist/esm/version.mjs +1 -1
  248. package/package.json +134 -10
  249. package/reference.md +1 -0
@@ -3,15 +3,15 @@ export interface UserRequestAttributes {
3
3
  /** Rewards programs to enroll the user in. If an empty array is supplied, the user will not be enrolled in any programs. */
4
4
  enrolledRewards: KardApi.EnrolledRewardsType[];
5
5
  /** Zipcode of user */
6
- zipCode?: string;
6
+ zipCode?: string | undefined;
7
7
  /** Email address of user */
8
- email?: string;
8
+ email?: string | undefined;
9
9
  /** Hashed email address of user (using SHA-256) */
10
- hashedEmail?: string;
10
+ hashedEmail?: string | undefined;
11
11
  /** Phone number of user in E.164 format */
12
- phoneNumber?: string;
12
+ phoneNumber?: string | undefined;
13
13
  /** Birth year of user */
14
- birthYear?: string;
14
+ birthYear?: string | undefined;
15
15
  /** Indicates whether historical transactions have been sent for this user */
16
- historicalTransactionsSent?: boolean;
16
+ historicalTransactionsSent?: boolean | undefined;
17
17
  }
@@ -1,23 +1,45 @@
1
1
  import type { BaseClientOptions } from "../BaseClient.js";
2
2
  import * as core from "../core/index.js";
3
- export declare namespace OAuthAuthProvider {
4
- interface Options extends BaseClientOptions {
5
- }
6
- }
3
+ declare const CLIENT_ID_PARAM: "clientId";
4
+ declare const CLIENT_SECRET_PARAM: "clientSecret";
5
+ declare const TOKEN_PARAM: "token";
7
6
  export declare class OAuthAuthProvider implements core.AuthProvider {
8
- private readonly BUFFER_IN_MINUTES;
9
- private readonly _clientId;
10
- private readonly _clientSecret;
11
- private readonly _authClient;
12
- private _accessToken;
13
- private _expiresAt;
14
- private _refreshPromise;
15
- constructor(options: OAuthAuthProvider.Options);
16
- static canCreate(options: OAuthAuthProvider.Options): boolean;
17
- getAuthRequest(arg?: {
7
+ private readonly options;
8
+ private readonly authClient;
9
+ private accessToken;
10
+ private expiresAt;
11
+ private refreshPromise;
12
+ constructor(options: OAuthAuthProvider.Options & OAuthAuthProvider.ClientCredentials);
13
+ static canCreate(options?: Partial<OAuthAuthProvider.ClientCredentials & BaseClientOptions>): boolean;
14
+ private clientIdSupplier;
15
+ private clientSecretSupplier;
16
+ getAuthRequest({ endpointMetadata, }?: {
18
17
  endpointMetadata?: core.EndpointMetadata;
19
18
  }): Promise<core.AuthRequest>;
20
19
  private getToken;
21
20
  private refresh;
22
21
  private getExpiresAt;
23
22
  }
23
+ export declare class OAuthTokenOverrideAuthProvider implements core.AuthProvider {
24
+ private readonly options;
25
+ constructor(options: OAuthAuthProvider.TokenOverride);
26
+ static canCreate(options?: Partial<OAuthAuthProvider.TokenOverride & BaseClientOptions>): options is OAuthAuthProvider.TokenOverride;
27
+ getAuthRequest({ endpointMetadata, }?: {
28
+ endpointMetadata?: core.EndpointMetadata;
29
+ }): Promise<core.AuthRequest>;
30
+ }
31
+ export declare namespace OAuthAuthProvider {
32
+ const AUTH_SCHEME: "OAuthScheme";
33
+ const AUTH_CONFIG_ERROR_MESSAGE: string;
34
+ type ClientCredentials = {
35
+ [CLIENT_ID_PARAM]?: core.Supplier<string> | undefined;
36
+ [CLIENT_SECRET_PARAM]?: core.Supplier<string> | undefined;
37
+ };
38
+ type TokenOverride = {
39
+ [TOKEN_PARAM]: core.Supplier<string>;
40
+ };
41
+ type AuthOptions = ClientCredentials | TokenOverride;
42
+ type Options = BaseClientOptions & AuthOptions;
43
+ function createInstance(options: Options): core.AuthProvider;
44
+ }
45
+ export {};
@@ -43,26 +43,65 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
43
43
  });
44
44
  };
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
- exports.OAuthAuthProvider = void 0;
46
+ exports.OAuthTokenOverrideAuthProvider = exports.OAuthAuthProvider = void 0;
47
47
  const Client_js_1 = require("../api/resources/auth/client/Client.js");
48
48
  const core = __importStar(require("../core/index.js"));
49
49
  const errors = __importStar(require("../errors/index.js"));
50
+ const CLIENT_ID_PARAM = "clientId";
51
+ const CLIENT_SECRET_PARAM = "clientSecret";
52
+ const TOKEN_PARAM = "token";
53
+ const ENV_CLIENT_ID = "KARD_CLIENT_ID";
54
+ const ENV_CLIENT_SECRET = "KARD_CLIENT_SECRET";
55
+ const CLIENT_ID_REQUIRED_ERROR_MESSAGE = `${CLIENT_ID_PARAM} is required; either pass it as an argument or set the ${ENV_CLIENT_ID} environment variable`;
56
+ const CLIENT_SECRET_REQUIRED_ERROR_MESSAGE = `${CLIENT_SECRET_PARAM} is required; either pass it as an argument or set the ${ENV_CLIENT_SECRET} environment variable`;
57
+ const TOKEN_PARAM_REQUIRED_ERROR_MESSAGE = `${TOKEN_PARAM} is required. Please provide it in options.`;
58
+ const BUFFER_IN_MINUTES = 2;
50
59
  class OAuthAuthProvider {
51
60
  constructor(options) {
52
- this.BUFFER_IN_MINUTES = 2;
53
- this._clientId = options.clientId;
54
- this._clientSecret = options.clientSecret;
55
- this._authClient = new Client_js_1.AuthClient(options);
56
- this._expiresAt = new Date();
61
+ this.options = options;
62
+ this.authClient = new Client_js_1.AuthClient(options);
63
+ this.expiresAt = new Date();
57
64
  }
58
65
  static canCreate(options) {
59
66
  var _a, _b;
60
- return ((options.clientId != null || ((_a = process.env) === null || _a === void 0 ? void 0 : _a.KARD_CLIENT_ID) != null) &&
61
- (options.clientSecret != null || ((_b = process.env) === null || _b === void 0 ? void 0 : _b.KARD_CLIENT_SECRET) != null));
67
+ return (((options === null || options === void 0 ? void 0 : options[CLIENT_ID_PARAM]) != null || ((_a = process.env) === null || _a === void 0 ? void 0 : _a[ENV_CLIENT_ID]) != null) &&
68
+ ((options === null || options === void 0 ? void 0 : options[CLIENT_SECRET_PARAM]) != null || ((_b = process.env) === null || _b === void 0 ? void 0 : _b[ENV_CLIENT_SECRET]) != null));
62
69
  }
63
- getAuthRequest(arg) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- const token = yield this.getToken(arg);
70
+ clientIdSupplier() {
71
+ return __awaiter(this, arguments, void 0, function* ({ endpointMetadata, } = {}) {
72
+ var _a;
73
+ const supplier = this.options[CLIENT_ID_PARAM];
74
+ if (supplier != null) {
75
+ return core.EndpointSupplier.get(supplier, { endpointMetadata });
76
+ }
77
+ const envClientId = (_a = process.env) === null || _a === void 0 ? void 0 : _a[ENV_CLIENT_ID];
78
+ if (envClientId != null) {
79
+ return envClientId;
80
+ }
81
+ throw new errors.KardApiError({
82
+ message: CLIENT_ID_REQUIRED_ERROR_MESSAGE,
83
+ });
84
+ });
85
+ }
86
+ clientSecretSupplier() {
87
+ return __awaiter(this, arguments, void 0, function* ({ endpointMetadata, } = {}) {
88
+ var _a;
89
+ const supplier = this.options[CLIENT_SECRET_PARAM];
90
+ if (supplier != null) {
91
+ return core.EndpointSupplier.get(supplier, { endpointMetadata });
92
+ }
93
+ const envClientSecret = (_a = process.env) === null || _a === void 0 ? void 0 : _a[ENV_CLIENT_SECRET];
94
+ if (envClientSecret != null) {
95
+ return envClientSecret;
96
+ }
97
+ throw new errors.KardApiError({
98
+ message: CLIENT_SECRET_REQUIRED_ERROR_MESSAGE,
99
+ });
100
+ });
101
+ }
102
+ getAuthRequest() {
103
+ return __awaiter(this, arguments, void 0, function* ({ endpointMetadata, } = {}) {
104
+ const token = yield this.getToken({ endpointMetadata });
66
105
  return {
67
106
  headers: {
68
107
  Authorization: `Bearer ${token}`,
@@ -70,48 +109,37 @@ class OAuthAuthProvider {
70
109
  };
71
110
  });
72
111
  }
73
- getToken(arg) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- if (this._accessToken && this._expiresAt > new Date()) {
76
- return this._accessToken;
112
+ getToken() {
113
+ return __awaiter(this, arguments, void 0, function* ({ endpointMetadata } = {}) {
114
+ if (this.accessToken && this.expiresAt > new Date()) {
115
+ return this.accessToken;
77
116
  }
78
117
  // If a refresh is already in progress, return the existing promise
79
- if (this._refreshPromise != null) {
80
- return this._refreshPromise;
118
+ if (this.refreshPromise != null) {
119
+ return this.refreshPromise;
81
120
  }
82
- return this.refresh(arg);
121
+ return this.refresh({ endpointMetadata });
83
122
  });
84
123
  }
85
- refresh(_arg) {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- this._refreshPromise = (() => __awaiter(this, void 0, void 0, function* () {
88
- var _a, _b, _c, _d;
124
+ refresh() {
125
+ return __awaiter(this, arguments, void 0, function* ({ endpointMetadata } = {}) {
126
+ this.refreshPromise = (() => __awaiter(this, void 0, void 0, function* () {
89
127
  try {
90
- const clientId = (_a = (yield core.Supplier.get(this._clientId))) !== null && _a !== void 0 ? _a : (_b = process.env) === null || _b === void 0 ? void 0 : _b.KARD_CLIENT_ID;
91
- if (clientId == null) {
92
- throw new errors.KardApiError({
93
- message: "clientId is required; either pass it as an argument or set the KARD_CLIENT_ID environment variable",
94
- });
95
- }
96
- const clientSecret = (_c = (yield core.Supplier.get(this._clientSecret))) !== null && _c !== void 0 ? _c : (_d = process.env) === null || _d === void 0 ? void 0 : _d.KARD_CLIENT_SECRET;
97
- if (clientSecret == null) {
98
- throw new errors.KardApiError({
99
- message: "clientSecret is required; either pass it as an argument or set the KARD_CLIENT_SECRET environment variable",
100
- });
101
- }
102
- const tokenResponse = yield this._authClient.getToken({
128
+ const clientId = yield this.clientIdSupplier({ endpointMetadata });
129
+ const clientSecret = yield this.clientSecretSupplier({ endpointMetadata });
130
+ const tokenResponse = yield this.authClient.getToken({
103
131
  client_id: clientId,
104
132
  client_secret: clientSecret,
105
133
  });
106
- this._accessToken = tokenResponse.access_token;
107
- this._expiresAt = this.getExpiresAt(tokenResponse.expires_in, this.BUFFER_IN_MINUTES);
108
- return this._accessToken;
134
+ this.accessToken = tokenResponse.access_token;
135
+ this.expiresAt = this.getExpiresAt(tokenResponse.expires_in, BUFFER_IN_MINUTES);
136
+ return this.accessToken;
109
137
  }
110
138
  finally {
111
- this._refreshPromise = undefined;
139
+ this.refreshPromise = undefined;
112
140
  }
113
141
  }))();
114
- return this._refreshPromise;
142
+ return this.refreshPromise;
115
143
  });
116
144
  }
117
145
  getExpiresAt(expiresInSeconds, bufferInMinutes) {
@@ -120,3 +148,43 @@ class OAuthAuthProvider {
120
148
  }
121
149
  }
122
150
  exports.OAuthAuthProvider = OAuthAuthProvider;
151
+ class OAuthTokenOverrideAuthProvider {
152
+ constructor(options) {
153
+ this.options = options;
154
+ }
155
+ static canCreate(options) {
156
+ return (options === null || options === void 0 ? void 0 : options[TOKEN_PARAM]) != null;
157
+ }
158
+ getAuthRequest() {
159
+ return __awaiter(this, arguments, void 0, function* ({ endpointMetadata, } = {}) {
160
+ const token = this.options[TOKEN_PARAM];
161
+ if (token == null) {
162
+ throw new errors.KardApiError({
163
+ message: TOKEN_PARAM_REQUIRED_ERROR_MESSAGE,
164
+ });
165
+ }
166
+ return {
167
+ headers: {
168
+ Authorization: `Bearer ${yield core.EndpointSupplier.get(token, { endpointMetadata })}`,
169
+ },
170
+ };
171
+ });
172
+ }
173
+ }
174
+ exports.OAuthTokenOverrideAuthProvider = OAuthTokenOverrideAuthProvider;
175
+ (function (OAuthAuthProvider) {
176
+ OAuthAuthProvider.AUTH_SCHEME = "OAuthScheme";
177
+ OAuthAuthProvider.AUTH_CONFIG_ERROR_MESSAGE = `Insufficient options to create OAuthAuthProvider. Please provide either '${CLIENT_ID_PARAM}' or '${ENV_CLIENT_ID}' env var and '${CLIENT_SECRET_PARAM}' or '${ENV_CLIENT_SECRET}' env var, or ${TOKEN_PARAM}.`;
178
+ function createInstance(options) {
179
+ if (OAuthTokenOverrideAuthProvider.canCreate(options)) {
180
+ return new OAuthTokenOverrideAuthProvider(options);
181
+ }
182
+ else if (OAuthAuthProvider.canCreate(options)) {
183
+ return new OAuthAuthProvider(options);
184
+ }
185
+ throw new errors.KardApiError({
186
+ message: OAuthAuthProvider.AUTH_CONFIG_ERROR_MESSAGE,
187
+ });
188
+ }
189
+ OAuthAuthProvider.createInstance = createInstance;
190
+ })(OAuthAuthProvider || (exports.OAuthAuthProvider = OAuthAuthProvider = {}));
@@ -1,6 +1,6 @@
1
1
  export interface BasicAuth {
2
- username: string;
3
- password: string;
2
+ username?: string;
3
+ password?: string;
4
4
  }
5
5
  export declare const BasicAuth: {
6
6
  toAuthorizationHeader: (basicAuth: BasicAuth | undefined) => string | undefined;
@@ -5,10 +5,16 @@ const base64_js_1 = require("../base64.js");
5
5
  const BASIC_AUTH_HEADER_PREFIX = /^Basic /i;
6
6
  exports.BasicAuth = {
7
7
  toAuthorizationHeader: (basicAuth) => {
8
+ var _a, _b;
8
9
  if (basicAuth == null) {
9
10
  return undefined;
10
11
  }
11
- const token = (0, base64_js_1.base64Encode)(`${basicAuth.username}:${basicAuth.password}`);
12
+ const username = (_a = basicAuth.username) !== null && _a !== void 0 ? _a : "";
13
+ const password = (_b = basicAuth.password) !== null && _b !== void 0 ? _b : "";
14
+ if (username === "" && password === "") {
15
+ return undefined;
16
+ }
17
+ const token = (0, base64_js_1.base64Encode)(`${username}:${password}`);
12
18
  return `Basic ${token}`;
13
19
  },
14
20
  fromAuthorizationHeader: (header) => {
@@ -14,6 +14,6 @@ export type BinaryResponse = {
14
14
  * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Request/bytes)
15
15
  * Some versions of the Fetch API may not support this method.
16
16
  */
17
- bytes?(): ReturnType<Response["bytes"]>;
17
+ bytes?(): Promise<Uint8Array>;
18
18
  };
19
19
  export declare function getBinaryResponse(response: Response): BinaryResponse;
@@ -1,12 +1,12 @@
1
1
  import type { EndpointMetadata } from "./EndpointMetadata.js";
2
2
  import type { Supplier } from "./Supplier.js";
3
3
  type EndpointSupplierFn<T> = (arg: {
4
- endpointMetadata: EndpointMetadata;
4
+ endpointMetadata?: EndpointMetadata;
5
5
  }) => T | Promise<T>;
6
6
  export type EndpointSupplier<T> = Supplier<T> | EndpointSupplierFn<T>;
7
7
  export declare const EndpointSupplier: {
8
8
  get: <T>(supplier: EndpointSupplier<T>, arg: {
9
- endpointMetadata: EndpointMetadata;
9
+ endpointMetadata?: EndpointMetadata;
10
10
  }) => Promise<T>;
11
11
  };
12
12
  export {};
@@ -1,14 +1,13 @@
1
1
  import { type LogConfig, type Logger } from "../logging/logger.js";
2
2
  import type { APIResponse } from "./APIResponse.js";
3
3
  import type { EndpointMetadata } from "./EndpointMetadata.js";
4
- import { EndpointSupplier } from "./EndpointSupplier.js";
5
4
  export type FetchFunction = <R = unknown>(args: Fetcher.Args) => Promise<APIResponse<R, Fetcher.Error>>;
6
5
  export declare namespace Fetcher {
7
6
  interface Args {
8
7
  url: string;
9
8
  method: string;
10
9
  contentType?: string;
11
- headers?: Record<string, string | EndpointSupplier<string | null | undefined> | null | undefined>;
10
+ headers?: Record<string, unknown>;
12
11
  queryParameters?: Record<string, unknown>;
13
12
  body?: unknown;
14
13
  timeoutMs?: number;
@@ -39,10 +38,12 @@ export declare namespace Fetcher {
39
38
  }
40
39
  interface TimeoutError {
41
40
  reason: "timeout";
41
+ cause?: unknown;
42
42
  }
43
43
  interface UnknownError {
44
44
  reason: "unknown";
45
45
  errorMessage: string;
46
+ cause?: unknown;
46
47
  }
47
48
  }
48
49
  export declare function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse<R, Fetcher.Error>>;
@@ -156,7 +156,13 @@ function getHeaders(args) {
156
156
  return __awaiter(this, void 0, void 0, function* () {
157
157
  var _a;
158
158
  const newHeaders = new Headers_js_1.Headers();
159
- newHeaders.set("Accept", args.responseType === "json" ? "application/json" : args.responseType === "text" ? "text/plain" : "*/*");
159
+ newHeaders.set("Accept", args.responseType === "json"
160
+ ? "application/json"
161
+ : args.responseType === "text"
162
+ ? "text/plain"
163
+ : args.responseType === "sse"
164
+ ? "text/event-stream"
165
+ : "*/*");
160
166
  if (args.body !== undefined && args.contentType != null) {
161
167
  newHeaders.set("Content-Type", args.contentType);
162
168
  }
@@ -200,7 +206,7 @@ function fetcherImpl(args) {
200
206
  }
201
207
  try {
202
208
  const response = yield (0, requestWithRetries_js_1.requestWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
203
- return (0, makeRequest_js_1.makeRequest)(fetchFn, url, args.method, headers, requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex);
209
+ return (0, makeRequest_js_1.makeRequest)(fetchFn, url, args.method, headers, requestBody, args.timeoutMs, args.abortSignal, args.withCredentials, args.duplex, args.responseType === "streaming" || args.responseType === "sse");
204
210
  }), args.maxRetries);
205
211
  if (response.status >= 200 && response.status < 400) {
206
212
  if (logger.isDebug()) {
@@ -255,6 +261,7 @@ function fetcherImpl(args) {
255
261
  error: {
256
262
  reason: "unknown",
257
263
  errorMessage: "The user aborted a request",
264
+ cause: error,
258
265
  },
259
266
  rawResponse: RawResponse_js_1.abortRawResponse,
260
267
  };
@@ -272,6 +279,7 @@ function fetcherImpl(args) {
272
279
  ok: false,
273
280
  error: {
274
281
  reason: "timeout",
282
+ cause: error,
275
283
  },
276
284
  rawResponse: RawResponse_js_1.abortRawResponse,
277
285
  };
@@ -290,6 +298,7 @@ function fetcherImpl(args) {
290
298
  error: {
291
299
  reason: "unknown",
292
300
  errorMessage: error.message,
301
+ cause: error,
293
302
  },
294
303
  rawResponse: RawResponse_js_1.unknownRawResponse,
295
304
  };
@@ -307,6 +316,7 @@ function fetcherImpl(args) {
307
316
  error: {
308
317
  reason: "unknown",
309
318
  errorMessage: (0, json_js_1.toJson)(error),
319
+ cause: error,
310
320
  },
311
321
  rawResponse: RawResponse_js_1.unknownRawResponse,
312
322
  };
@@ -6,6 +6,8 @@ export type { Fetcher, FetchFunction } from "./Fetcher.js";
6
6
  export { fetcher } from "./Fetcher.js";
7
7
  export { getHeader } from "./getHeader.js";
8
8
  export { HttpResponsePromise } from "./HttpResponsePromise.js";
9
+ export type { PassthroughRequest } from "./makePassthroughRequest.js";
10
+ export { makePassthroughRequest } from "./makePassthroughRequest.js";
9
11
  export type { RawResponse, WithRawResponse } from "./RawResponse.js";
10
12
  export { abortRawResponse, toRawResponse, unknownRawResponse } from "./RawResponse.js";
11
13
  export { Supplier } from "./Supplier.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Supplier = exports.unknownRawResponse = exports.toRawResponse = exports.abortRawResponse = exports.HttpResponsePromise = exports.getHeader = exports.fetcher = exports.EndpointSupplier = void 0;
3
+ exports.Supplier = exports.unknownRawResponse = exports.toRawResponse = exports.abortRawResponse = exports.makePassthroughRequest = exports.HttpResponsePromise = exports.getHeader = exports.fetcher = exports.EndpointSupplier = void 0;
4
4
  var EndpointSupplier_js_1 = require("./EndpointSupplier.js");
5
5
  Object.defineProperty(exports, "EndpointSupplier", { enumerable: true, get: function () { return EndpointSupplier_js_1.EndpointSupplier; } });
6
6
  var Fetcher_js_1 = require("./Fetcher.js");
@@ -9,6 +9,8 @@ var getHeader_js_1 = require("./getHeader.js");
9
9
  Object.defineProperty(exports, "getHeader", { enumerable: true, get: function () { return getHeader_js_1.getHeader; } });
10
10
  var HttpResponsePromise_js_1 = require("./HttpResponsePromise.js");
11
11
  Object.defineProperty(exports, "HttpResponsePromise", { enumerable: true, get: function () { return HttpResponsePromise_js_1.HttpResponsePromise; } });
12
+ var makePassthroughRequest_js_1 = require("./makePassthroughRequest.js");
13
+ Object.defineProperty(exports, "makePassthroughRequest", { enumerable: true, get: function () { return makePassthroughRequest_js_1.makePassthroughRequest; } });
12
14
  var RawResponse_js_1 = require("./RawResponse.js");
13
15
  Object.defineProperty(exports, "abortRawResponse", { enumerable: true, get: function () { return RawResponse_js_1.abortRawResponse; } });
14
16
  Object.defineProperty(exports, "toRawResponse", { enumerable: true, get: function () { return RawResponse_js_1.toRawResponse; } });
@@ -0,0 +1,49 @@
1
+ import { type LogConfig, type Logger } from "../logging/logger.js";
2
+ import { Supplier } from "./Supplier.js";
3
+ export declare namespace PassthroughRequest {
4
+ /**
5
+ * Per-request options that can override the SDK client defaults.
6
+ */
7
+ interface RequestOptions {
8
+ /** Override the default timeout for this request (in seconds). */
9
+ timeoutInSeconds?: number;
10
+ /** Override the default number of retries for this request. */
11
+ maxRetries?: number;
12
+ /** Additional headers to include in this request. */
13
+ headers?: Record<string, string>;
14
+ /** Abort signal for this request. */
15
+ abortSignal?: AbortSignal;
16
+ }
17
+ /**
18
+ * SDK client configuration used by the passthrough fetch method.
19
+ */
20
+ interface ClientOptions {
21
+ /** The base URL or environment for the client. */
22
+ environment?: Supplier<string>;
23
+ /** Override the base URL. */
24
+ baseUrl?: Supplier<string>;
25
+ /** Default headers to include in requests. */
26
+ headers?: Record<string, unknown>;
27
+ /** Default maximum time to wait for a response in seconds. */
28
+ timeoutInSeconds?: number;
29
+ /** Default number of times to retry the request. Defaults to 2. */
30
+ maxRetries?: number;
31
+ /** A custom fetch function. */
32
+ fetch?: typeof fetch;
33
+ /** Logging configuration. */
34
+ logging?: LogConfig | Logger;
35
+ /** A function that returns auth headers. */
36
+ getAuthHeaders?: () => Promise<Record<string, string>>;
37
+ }
38
+ }
39
+ /**
40
+ * Makes a passthrough HTTP request using the SDK's configuration (auth, retry, logging, etc.)
41
+ * while mimicking the standard `fetch` API.
42
+ *
43
+ * @param input - The URL, path, or Request object. If a relative path, it will be resolved against the configured base URL.
44
+ * @param init - Standard RequestInit options (method, headers, body, signal, etc.)
45
+ * @param clientOptions - SDK client options (auth, default headers, logging, etc.)
46
+ * @param requestOptions - Per-request overrides (timeout, retries, extra headers, abort signal).
47
+ * @returns A standard Response object.
48
+ */
49
+ export declare function makePassthroughRequest(input: Request | string | URL, init: RequestInit | undefined, clientOptions: PassthroughRequest.ClientOptions, requestOptions?: PassthroughRequest.RequestOptions): Promise<Response>;
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.makePassthroughRequest = makePassthroughRequest;
13
+ const logger_js_1 = require("../logging/logger.js");
14
+ const join_js_1 = require("../url/join.js");
15
+ const EndpointSupplier_js_1 = require("./EndpointSupplier.js");
16
+ const getFetchFn_js_1 = require("./getFetchFn.js");
17
+ const makeRequest_js_1 = require("./makeRequest.js");
18
+ const requestWithRetries_js_1 = require("./requestWithRetries.js");
19
+ const Supplier_js_1 = require("./Supplier.js");
20
+ /**
21
+ * Makes a passthrough HTTP request using the SDK's configuration (auth, retry, logging, etc.)
22
+ * while mimicking the standard `fetch` API.
23
+ *
24
+ * @param input - The URL, path, or Request object. If a relative path, it will be resolved against the configured base URL.
25
+ * @param init - Standard RequestInit options (method, headers, body, signal, etc.)
26
+ * @param clientOptions - SDK client options (auth, default headers, logging, etc.)
27
+ * @param requestOptions - Per-request overrides (timeout, retries, extra headers, abort signal).
28
+ * @returns A standard Response object.
29
+ */
30
+ function makePassthroughRequest(input, init, clientOptions, requestOptions) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ var _a, _b, _c, _d, _e, _f, _g;
33
+ const logger = (0, logger_js_1.createLogger)(clientOptions.logging);
34
+ // Extract URL and default init properties from Request object if provided
35
+ let url;
36
+ let effectiveInit = init;
37
+ if (input instanceof Request) {
38
+ url = input.url;
39
+ // If no explicit init provided, extract properties from the Request object
40
+ if (init == null) {
41
+ effectiveInit = {
42
+ method: input.method,
43
+ headers: Object.fromEntries(input.headers.entries()),
44
+ body: input.body,
45
+ signal: input.signal,
46
+ credentials: input.credentials,
47
+ cache: input.cache,
48
+ redirect: input.redirect,
49
+ referrer: input.referrer,
50
+ integrity: input.integrity,
51
+ mode: input.mode,
52
+ };
53
+ }
54
+ }
55
+ else {
56
+ url = input instanceof URL ? input.toString() : input;
57
+ }
58
+ // Resolve the base URL
59
+ const baseUrl = (_a = (clientOptions.baseUrl != null ? yield Supplier_js_1.Supplier.get(clientOptions.baseUrl) : undefined)) !== null && _a !== void 0 ? _a : (clientOptions.environment != null ? yield Supplier_js_1.Supplier.get(clientOptions.environment) : undefined);
60
+ // Determine the full URL
61
+ let fullUrl;
62
+ if (url.startsWith("http://") || url.startsWith("https://")) {
63
+ fullUrl = url;
64
+ }
65
+ else if (baseUrl != null) {
66
+ fullUrl = (0, join_js_1.join)(baseUrl, url);
67
+ }
68
+ else {
69
+ fullUrl = url;
70
+ }
71
+ // Merge headers: SDK default headers -> auth headers -> user-provided headers
72
+ const mergedHeaders = {};
73
+ // Apply SDK default headers (resolve suppliers)
74
+ if (clientOptions.headers != null) {
75
+ for (const [key, value] of Object.entries(clientOptions.headers)) {
76
+ const resolved = yield EndpointSupplier_js_1.EndpointSupplier.get(value, { endpointMetadata: {} });
77
+ if (resolved != null) {
78
+ mergedHeaders[key.toLowerCase()] = `${resolved}`;
79
+ }
80
+ }
81
+ }
82
+ // Apply auth headers
83
+ if (clientOptions.getAuthHeaders != null) {
84
+ const authHeaders = yield clientOptions.getAuthHeaders();
85
+ for (const [key, value] of Object.entries(authHeaders)) {
86
+ mergedHeaders[key.toLowerCase()] = value;
87
+ }
88
+ }
89
+ // Apply user-provided headers from init
90
+ if ((effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.headers) != null) {
91
+ const initHeaders = effectiveInit.headers instanceof Headers
92
+ ? Object.fromEntries(effectiveInit.headers.entries())
93
+ : Array.isArray(effectiveInit.headers)
94
+ ? Object.fromEntries(effectiveInit.headers)
95
+ : effectiveInit.headers;
96
+ for (const [key, value] of Object.entries(initHeaders)) {
97
+ if (value != null) {
98
+ mergedHeaders[key.toLowerCase()] = value;
99
+ }
100
+ }
101
+ }
102
+ // Apply per-request option headers (highest priority)
103
+ if ((requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers) != null) {
104
+ for (const [key, value] of Object.entries(requestOptions.headers)) {
105
+ mergedHeaders[key.toLowerCase()] = value;
106
+ }
107
+ }
108
+ const method = (_b = effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.method) !== null && _b !== void 0 ? _b : "GET";
109
+ const body = effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.body;
110
+ const timeoutInSeconds = (_c = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) !== null && _c !== void 0 ? _c : clientOptions.timeoutInSeconds;
111
+ const timeoutMs = timeoutInSeconds != null ? timeoutInSeconds * 1000 : undefined;
112
+ const maxRetries = (_d = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.maxRetries) !== null && _d !== void 0 ? _d : clientOptions.maxRetries;
113
+ const abortSignal = (_f = (_e = requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.abortSignal) !== null && _e !== void 0 ? _e : effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.signal) !== null && _f !== void 0 ? _f : undefined;
114
+ const fetchFn = (_g = clientOptions.fetch) !== null && _g !== void 0 ? _g : (yield (0, getFetchFn_js_1.getFetchFn)());
115
+ if (logger.isDebug()) {
116
+ logger.debug("Making passthrough HTTP request", {
117
+ method,
118
+ url: fullUrl,
119
+ hasBody: body != null,
120
+ });
121
+ }
122
+ const response = yield (0, requestWithRetries_js_1.requestWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
123
+ return (0, makeRequest_js_1.makeRequest)(fetchFn, fullUrl, method, mergedHeaders, body !== null && body !== void 0 ? body : undefined, timeoutMs, abortSignal, (effectiveInit === null || effectiveInit === void 0 ? void 0 : effectiveInit.credentials) === "include", undefined, // duplex
124
+ false);
125
+ }), maxRetries);
126
+ if (logger.isDebug()) {
127
+ logger.debug("Passthrough HTTP request completed", {
128
+ method,
129
+ url: fullUrl,
130
+ statusCode: response.status,
131
+ });
132
+ }
133
+ return response;
134
+ });
135
+ }
@@ -1 +1,6 @@
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>;
1
+ export declare function isCacheNoStoreSupported(): boolean;
2
+ /**
3
+ * Reset the cached result of `isCacheNoStoreSupported`. Exposed for testing only.
4
+ */
5
+ export declare function resetCacheNoStoreSupported(): void;
6
+ 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", disableCache?: boolean) => Promise<Response>;