@spritz-finance/service-client 0.34.1 → 0.35.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.
@@ -59,8 +59,9 @@ async function getBatchBalances() {
59
59
  .get(`${CHECKBOOK_ENDPOINT}/checkbook/batch/balances`)
60
60
  .then((res) => res.data);
61
61
  }
62
+ // No `currency`: the route defaults to USD, as the legacy route did.
62
63
  async function getFundingBatchBalances() {
63
64
  return baseClient
64
- .get(`${CHECKBOOK_ENDPOINT}/checkbook/batch/funding-balances`)
65
+ .get(`${CHECKBOOK_API_ENDPOINT}/checkbook/batch/funding-balances`)
65
66
  .then((res) => res.data);
66
67
  }
@@ -65,21 +65,21 @@ async function getUserReferrerAccount(userId) {
65
65
  }
66
66
  async function initializePointsRedemption(input) {
67
67
  return baseClient
68
- .post(`${GROWTH_ENDPOINT}/v2/points/redemption/initialize`, input)
68
+ .post(`${GROWTH_SERVICE_API_ENDPOINT}/points/redemption/initialize`, input)
69
69
  .then((res) => res.data);
70
70
  }
71
71
  async function getPointsRedemptionOption(input) {
72
72
  return baseClient
73
- .post(`${GROWTH_ENDPOINT}/v2/points/redemption/option`, input)
73
+ .post(`${GROWTH_SERVICE_API_ENDPOINT}/points/redemption/option`, input)
74
74
  .then((res) => res.data);
75
75
  }
76
76
  async function validatePointsRedemption(input) {
77
77
  return baseClient
78
- .post(`${GROWTH_ENDPOINT}/v2/points/redemption/validate`, input)
78
+ .post(`${GROWTH_SERVICE_API_ENDPOINT}/points/redemption/validate`, input)
79
79
  .then((res) => res.data);
80
80
  }
81
81
  async function confirmPointsRedemption(input) {
82
82
  return baseClient
83
- .post(`${GROWTH_ENDPOINT}/v2/points/redemption/confirm`, input)
83
+ .post(`${GROWTH_SERVICE_API_ENDPOINT}/points/redemption/confirm`, input)
84
84
  .then((res) => res.data);
85
85
  }
@@ -2,6 +2,11 @@ export * as LiabilitiesClient from "./liabilitiesServiceClient";
2
2
  import { CheckbookUser } from "../lib/graphClient/generated";
3
3
  import { ExternalBillInput } from "../payableAccounts/types";
4
4
  import { CheckbookCardResponse, CheckbookDebitCardResponse, CheckbookDigitalAccountResponse, CheckbookUpdateCardResponse, CreateCheckbookUserParams, CreateDebitCardInput, CreateDigitalAccountInput, CreateEntityParams, CreateTokenizedDebitCardInput, DirectPaymentResponse, IssueRefundCreditInput, IssueRefundCreditResult, MethodFiEntity, RewardTransaction, TokenizedDebitCardResponse } from "./types";
5
+ /**
6
+ * The bare transaction, as the legacy `/reward-transactions/:id` route returned
7
+ * it. That route answered a missing transaction with a 404, so throw on a
8
+ * failure envelope or an empty result.
9
+ */
5
10
  export declare function getRewardTransaction(transactionId: string): Promise<RewardTransaction>;
6
11
  export declare function createMethodFiEntity(args: CreateEntityParams): Promise<MethodFiEntity>;
7
12
  export declare function getMethodFiEntity(userId: string): Promise<MethodFiEntity | null>;
@@ -58,10 +58,21 @@ const restClient_1 = require("../restClient");
58
58
  const baseClient = (0, restClient_1.getRestClient)(process.env.LIABILITIES_SERVICE_API_IAM_URL, "/v2/liabilities/api");
59
59
  const LIABILITIES_ENDPOINT = "/liabilities";
60
60
  const LIABILITIES_V2_ENDPOINT = "/v2/liabilities/api";
61
+ /**
62
+ * The bare transaction, as the legacy `/reward-transactions/:id` route returned
63
+ * it. That route answered a missing transaction with a 404, so throw on a
64
+ * failure envelope or an empty result.
65
+ */
61
66
  async function getRewardTransaction(transactionId) {
62
- return baseClient
63
- .get(`${LIABILITIES_ENDPOINT}/reward-transactions/${transactionId}`)
64
- .then((res) => res.data);
67
+ var _a, _b;
68
+ const res = await baseClient.get(`${LIABILITIES_V2_ENDPOINT}/rewards/transactions/${transactionId}`);
69
+ const body = res.data;
70
+ if (body.status === "failure") {
71
+ throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "Failed to get reward transaction");
72
+ }
73
+ if (!body.data)
74
+ throw new Error("Reward transaction not found");
75
+ return body.data;
65
76
  }
66
77
  async function createMethodFiEntity(args) {
67
78
  return baseClient
@@ -135,12 +146,12 @@ async function createTokenizedDebitCard(input) {
135
146
  }
136
147
  async function createCheckbookDigitalAccount(input) {
137
148
  return baseClient
138
- .post(`${LIABILITIES_ENDPOINT}/digital-account/create`, input)
149
+ .post(`${LIABILITIES_V2_ENDPOINT}/checkbook/digital-account/create`, input)
139
150
  .then((res) => res.data);
140
151
  }
141
152
  async function createUSBillFromAccountNumber(userId, accountNumber, merchantId) {
142
153
  return baseClient
143
- .post(`${LIABILITIES_ENDPOINT}/methodFi/bill/user/${userId}`, {
154
+ .post(`${LIABILITIES_V2_ENDPOINT}/methodfi/users/${userId}/bills`, {
144
155
  accountNumber,
145
156
  merchantId,
146
157
  })
@@ -174,18 +185,20 @@ async function updateCheckbookVirtualCard(userId, cardExternalId) {
174
185
  .then((res) => res.data);
175
186
  }
176
187
  async function addPromotionCredit(input) {
188
+ const { userId, amount, code } = input;
177
189
  return baseClient
178
- .post(`${LIABILITIES_ENDPOINT}/rewards/promotion`, input)
190
+ .post(`${LIABILITIES_V2_ENDPOINT}/rewards/users/${userId}/promotion-credits`, { amount, code })
179
191
  .then((res) => res.data);
180
192
  }
181
193
  async function addCashbackCredit(input) {
194
+ const { userId, amount, rewardId } = input;
182
195
  return baseClient
183
- .post(`${LIABILITIES_ENDPOINT}/rewards/cashback`, input)
196
+ .post(`${LIABILITIES_V2_ENDPOINT}/rewards/users/${userId}/cashback-credits`, { amount, rewardId })
184
197
  .then((res) => res.data);
185
198
  }
186
199
  async function getRewardTransactionsFor(userId) {
187
200
  return baseClient
188
- .get(`${LIABILITIES_ENDPOINT}/rewards/user/${userId}/transactions`)
201
+ .get(`${LIABILITIES_V2_ENDPOINT}/rewards/users/${userId}/transactions`)
189
202
  .then((res) => res.data);
190
203
  }
191
204
  async function getDirectPayment(directPaymentId) {
@@ -57,14 +57,29 @@ const restClient_1 = require("../restClient");
57
57
  const baseClient = (0, restClient_1.getRestClient)(process.env.PAYMENTS_SERVICE_API_IAM_URL, "/v2/liabilities/api");
58
58
  const PAYMENTS_ENDPOINT = "/liabilities";
59
59
  const PAYMENTS_ROUTER_ENDPOINT = "/v2/liabilities/api";
60
+ /**
61
+ * GETs or POSTs an `/api` route and returns the bare body its legacy route
62
+ * answered with. The `/api` routes answer every failure as a 200 failure
63
+ * envelope; throw on it, as the legacy route's non-2xx did.
64
+ */
65
+ async function legacyBareBody(request, failureMessage) {
66
+ var _a, _b;
67
+ const body = (await request).data;
68
+ if (body.status === "failure") {
69
+ throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : failureMessage);
70
+ }
71
+ return body.data;
72
+ }
60
73
  async function createDirectPayment(args) {
61
74
  return baseClient
62
75
  .post(`${PAYMENTS_ENDPOINT}/direct-payments`, args)
63
76
  .then((res) => res.data);
64
77
  }
65
78
  async function validatePaymentAmount(args) {
79
+ // Same success body and failure message as the legacy route; a refusal's
80
+ // `error.code` is now its error type.
66
81
  return baseClient
67
- .post(`${PAYMENTS_ENDPOINT}/v2/direct-payments/validate`, args)
82
+ .post(`${PAYMENTS_ROUTER_ENDPOINT}/direct-payment/validate`, args)
68
83
  .then((res) => res.data);
69
84
  }
70
85
  async function validateDirectPayment(args) {
@@ -76,24 +91,16 @@ async function validateDirectPayment(args) {
76
91
  .then((res) => res.data);
77
92
  }
78
93
  async function getValidPaymentsForAccount(accountId) {
79
- return baseClient
80
- .get(`${PAYMENTS_ENDPOINT}/payments/valid-payments/account/${accountId}`)
81
- .then((res) => res.data);
94
+ return legacyBareBody(baseClient.get(`${PAYMENTS_ROUTER_ENDPOINT}/payments/accounts/${accountId}/valid`), "Failed to get valid payments for account");
82
95
  }
83
96
  async function getValidPaymentsForUser(userId) {
84
- return baseClient
85
- .get(`${PAYMENTS_ENDPOINT}/payments/valid-payments/user/${userId}`)
86
- .then((res) => res.data);
97
+ return legacyBareBody(baseClient.get(`${PAYMENTS_ROUTER_ENDPOINT}/payments/users/${userId}/valid`), "Failed to get valid payments for user");
87
98
  }
88
99
  async function getRewardTransactionVolume(args) {
89
- return baseClient
90
- .post(`${PAYMENTS_ENDPOINT}/payments/rewards/volume`, args)
91
- .then((res) => res.data);
100
+ return legacyBareBody(baseClient.post(`${PAYMENTS_ROUTER_ENDPOINT}/payments/rewards/volume`, args), "Failed to get reward transaction volume");
92
101
  }
93
102
  async function getRewardFeeAmount(args) {
94
- return baseClient
95
- .post(`${PAYMENTS_ENDPOINT}/payments/rewards/fees`, args)
96
- .then((res) => res.data);
103
+ return legacyBareBody(baseClient.post(`${PAYMENTS_ROUTER_ENDPOINT}/payments/rewards/fees`, args), "Failed to get reward fee amount");
97
104
  }
98
105
  async function initializeExternalPayment(args) {
99
106
  return baseClient
@@ -153,7 +160,7 @@ async function getDirectPaymentDetails(directPaymentId) {
153
160
  }
154
161
  async function getAllPaymentsForUser(userId) {
155
162
  return baseClient
156
- .get(`${PAYMENTS_ENDPOINT}/payments/user/${userId}/all`)
163
+ .get(`${PAYMENTS_ROUTER_ENDPOINT}/payments/users/${userId}/all`)
157
164
  .then((res) => res.data);
158
165
  }
159
166
  async function getUserPaymentById(userId, paymentId) {
@@ -165,12 +172,12 @@ async function getUserPaymentById(userId, paymentId) {
165
172
  }
166
173
  async function directPaymentsForRiskAnalysis(userId) {
167
174
  return baseClient
168
- .get(`${PAYMENTS_ENDPOINT}/direct-payments/user/${userId}/risk-analysis`)
175
+ .get(`${PAYMENTS_ROUTER_ENDPOINT}/direct-payment/users/${userId}/risk-analysis`)
169
176
  .then((res) => res.data);
170
177
  }
171
178
  async function queryUserPayments(userId, input = {}) {
172
179
  return baseClient
173
- .post(`${PAYMENTS_ENDPOINT}/payments/query?userId=${userId}`, input)
180
+ .post(`${PAYMENTS_ROUTER_ENDPOINT}/payments/users/${userId}/query`, input)
174
181
  .then((res) => res.data);
175
182
  }
176
183
  async function getVoidedLiabilities() {
@@ -1,9 +1,18 @@
1
1
  export * as PlatformClient from "./platformServiceClient";
2
- import { CreateTokenizationData, CreateTokenizationRequest, IssueCardPayoutData, IssueCardPayoutRequest, IssuePayoutData, IssuePayoutRequest, IntegratorUsageKey, IntegratorUsageOperation, IntegratorUsageSummary, MTBalancesData, PersonByUserData, PlaidTreasuryBalancesData, RelayCheckbookCardData, RelayCheckbookCardRequest, ReleaseIntegratorUsageRequest, ReserveIntegratorUsageRequest, SendPaymentData, SendPaymentRequest, TabapayBalancesResponse, TabapayFundingRequirementResponse, ValidateBillData, ValidateBillRequest } from "./types";
2
+ import { ApiResponse } from "../types";
3
+ import { CreateTokenizationData, CreateTokenizationRequest, IssueCardPayoutData, IssueCardPayoutRequest, IssuePayoutByReferenceData, IssuePayoutByReferenceRequest, IssuePayoutData, IssuePayoutRequest, IntegratorUsageKey, IntegratorUsageOperation, IntegratorUsageSummary, MTBalancesData, PersonByUserData, PlaidTreasuryBalancesData, RelayCheckbookCardData, RelayCheckbookCardRequest, ReleaseIntegratorUsageRequest, ReserveIntegratorUsageRequest, SendPaymentData, SendPaymentRequest, TabapayBalancesResponse, TabapayFundingRequirementResponse, ValidateBillData, ValidateBillRequest } from "./types";
3
4
  export declare function validateBill(request: ValidateBillRequest): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<ValidateBillData>>;
4
5
  export declare function tabapayBalances(): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<TabapayBalancesResponse>>;
5
6
  export declare function tabapayFundingRequirement(currency?: string): Promise<TabapayFundingRequirementResponse>;
6
7
  export declare function issuePayout(request: IssuePayoutRequest): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<IssuePayoutData>>;
8
+ /**
9
+ * Platform answers a reference-shape refusal (payment not payable, amount
10
+ * unverified, destination unsafe) with 422 `{ error, code }`. It is returned as
11
+ * an `ApiFailure` so callers can fail the payment; any other non-2xx still
12
+ * rejects, because it means platform was unavailable and the payout must stay
13
+ * retryable.
14
+ */
15
+ export declare function issuePayoutByReference(request: IssuePayoutByReferenceRequest): Promise<ApiResponse<IssuePayoutByReferenceData>>;
7
16
  /**
8
17
  * Push-to-debit payout via Modern Treasury. Platform lazily materializes the
9
18
  * MT external account + Card from the Evervault tokenization on first payout,
@@ -41,6 +41,7 @@ exports.validateBill = validateBill;
41
41
  exports.tabapayBalances = tabapayBalances;
42
42
  exports.tabapayFundingRequirement = tabapayFundingRequirement;
43
43
  exports.issuePayout = issuePayout;
44
+ exports.issuePayoutByReference = issuePayoutByReference;
44
45
  exports.issueCardPayout = issueCardPayout;
45
46
  exports.sendPayment = sendPayment;
46
47
  exports.modernTreasuryBalances = modernTreasuryBalances;
@@ -98,6 +99,29 @@ async function issuePayout(request) {
98
99
  .post(`${MT_ENDPOINT}/issue-payout`, request)
99
100
  .then((res) => res.data);
100
101
  }
102
+ /**
103
+ * Platform answers a reference-shape refusal (payment not payable, amount
104
+ * unverified, destination unsafe) with 422 `{ error, code }`. It is returned as
105
+ * an `ApiFailure` so callers can fail the payment; any other non-2xx still
106
+ * rejects, because it means platform was unavailable and the payout must stay
107
+ * retryable.
108
+ */
109
+ async function issuePayoutByReference(request) {
110
+ var _a;
111
+ const res = await platformClient.post(`${MT_ENDPOINT}/issue-payout`, request, {
112
+ validateStatus: (status) => (status >= 200 && status < 300) || status === 422,
113
+ });
114
+ if (res.status !== 422)
115
+ return res.data;
116
+ const refusal = res.data;
117
+ return {
118
+ status: "failure",
119
+ error: {
120
+ message: (_a = refusal.error) !== null && _a !== void 0 ? _a : "Payout refused",
121
+ ...(refusal.code ? { code: refusal.code } : {}),
122
+ },
123
+ };
124
+ }
101
125
  /**
102
126
  * Push-to-debit payout via Modern Treasury. Platform lazily materializes the
103
127
  * MT external account + Card from the Evervault tokenization on first payout,
@@ -62,6 +62,19 @@ export interface IssuePayoutRequest {
62
62
  statementDescriptor?: string;
63
63
  metadata?: Record<string, string>;
64
64
  }
65
+ /**
66
+ * Reference-shape payout: platform resolves the destination, amount, rail and
67
+ * recipient from the liabilities Payment and payable-accounts itself, so the
68
+ * caller cannot redirect or resize it.
69
+ */
70
+ export interface IssuePayoutByReferenceRequest {
71
+ paymentId: string;
72
+ userId: string;
73
+ }
74
+ /** `payment_order_id` is absent while platform holds the payout in its funding queue. */
75
+ export type IssuePayoutByReferenceData = Omit<IssuePayoutData, "payment_order_id"> & {
76
+ payment_order_id?: string;
77
+ };
65
78
  export interface IssuePayoutData {
66
79
  payment_order_id: string;
67
80
  status: string;
@@ -91,12 +91,12 @@ async function disableUser(userId, note) {
91
91
  }
92
92
  async function createUserVerification(input) {
93
93
  return baseClient
94
- .post(`${VERIFICATION_ENDPOINT}/v2/users`, input)
94
+ .post(`${VERIFICATION_API_ENDPOINT}/users`, input)
95
95
  .then((res) => res.data);
96
96
  }
97
97
  async function activateVirtualCardModule(userId) {
98
98
  return baseClient
99
- .post(`${VERIFICATION_ENDPOINT}/v2/users/${userId}/activate-virtual-card`)
99
+ .post(`${VERIFICATION_API_ENDPOINT}/user/${userId}/activate-virtual-card`)
100
100
  .then((res) => res.data);
101
101
  }
102
102
  async function deactivateBillsModule(userId) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spritz-finance/service-client",
3
- "version": "0.34.1",
3
+ "version": "0.35.0",
4
4
  "gitHead": "06f8e96b7b38c34df26a38da329331940675e4f8",
5
5
  "description": "Service client",
6
6
  "license": "ISC",