@spritz-finance/service-client 0.34.2 → 0.36.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.
@@ -44,7 +44,6 @@ exports.getExternalPayments = getExternalPayments;
44
44
  exports.BridgeClient = __importStar(require("./bridgeServiceClient"));
45
45
  const restClient_1 = require("../restClient");
46
46
  const baseClient = (0, restClient_1.getRestClient)(process.env.BRIDGE_SERVICE_API_IAM_URL, "/v2/bridge/api");
47
- const ONRAMP_ENDPOINT = "/bridge";
48
47
  const ONRAMP_ROUTER_ENDPOINT = "/v2/bridge/api";
49
48
  async function getTransferHashes(externalPaymentIds) {
50
49
  return baseClient
@@ -53,7 +52,7 @@ async function getTransferHashes(externalPaymentIds) {
53
52
  }
54
53
  async function createBridgeBankAccount(userId, accountId, input) {
55
54
  return baseClient
56
- .post(`${ONRAMP_ENDPOINT}/user/${userId}/bank-account/${accountId}`, input)
55
+ .post(`${ONRAMP_ROUTER_ENDPOINT}/users/${userId}/bank-accounts/${accountId}`, input)
57
56
  .then((res) => res.data);
58
57
  }
59
58
  // Unlike the legacy `/user/:id` route, `/api/users/:id` refreshes the user's
@@ -66,7 +65,7 @@ async function getBridgeUser(userId) {
66
65
  }
67
66
  async function validateTransfer({ userId, transferId, amount, toAddress, }) {
68
67
  return baseClient
69
- .post(`${ONRAMP_ENDPOINT}/transfer/validate`, {
68
+ .post(`${ONRAMP_ROUTER_ENDPOINT}/off-ramps/transfers/validate`, {
70
69
  userId,
71
70
  transferId,
72
71
  amount,
@@ -88,6 +87,6 @@ async function getExchangeRates(from, to) {
88
87
  }
89
88
  async function getExternalPayments(paymentIds) {
90
89
  return baseClient
91
- .get(`${ONRAMP_ENDPOINT}/external-payments?paymentIds=${paymentIds.join(",")}`)
90
+ .get(`${ONRAMP_ROUTER_ENDPOINT}/external-payments?paymentIds=${paymentIds.join(",")}`)
92
91
  .then((res) => res.data);
93
92
  }
@@ -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) {
@@ -2,6 +2,11 @@ export * as OnrampClient from "./onrampServiceClient";
2
2
  import { OnRampPayment } from "../lib/graphClient/generated";
3
3
  import { BridgeUser, CreateBridgeUserParams, SyncOnrampTransferInput } from "./types";
4
4
  export declare function syncTransfer(input: SyncOnrampTransferInput): Promise<OnRampPayment>;
5
+ /**
6
+ * Every completed on-ramp, unpaginated, as the legacy
7
+ * `/payments/user/:id/completed` route returned it (`/api/on-ramps/users/:id`
8
+ * is the paginated list).
9
+ */
5
10
  export declare function getUserCompletedPayments(userId: string): Promise<OnRampPayment[]>;
6
11
  export declare function upsertBridgeUser(input: CreateBridgeUserParams): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<BridgeUser | null>>;
7
12
  export declare function createBusinessUser(userId: string, businessName: string): Promise<{
@@ -42,26 +42,41 @@ exports.OnrampClient = __importStar(require("./onrampServiceClient"));
42
42
  const restClient_1 = require("../restClient");
43
43
  const baseClient = (0, restClient_1.getRestClient)(process.env.ONRAMP_SERVICE_API_IAM_URL, "/v2/bridge/api");
44
44
  const ONRAMP_ENDPOINT = "/bridge";
45
+ const ONRAMP_ROUTER_ENDPOINT = "/v2/bridge/api";
46
+ /**
47
+ * Awaits an `/api` request and returns the bare body its legacy route answered
48
+ * with. The `/api` routes answer every failure as a 200 failure envelope;
49
+ * throw on it, as the legacy route's non-2xx did.
50
+ */
51
+ async function legacyBareBody(request, failureMessage) {
52
+ var _a, _b;
53
+ const body = (await request).data;
54
+ if (body.status === "failure") {
55
+ throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : failureMessage);
56
+ }
57
+ return body.data;
58
+ }
45
59
  async function syncTransfer(input) {
46
60
  return baseClient
47
61
  .post(`${ONRAMP_ENDPOINT}/external-transfer`, input)
48
62
  .then((res) => res.data);
49
63
  }
64
+ /**
65
+ * Every completed on-ramp, unpaginated, as the legacy
66
+ * `/payments/user/:id/completed` route returned it (`/api/on-ramps/users/:id`
67
+ * is the paginated list).
68
+ */
50
69
  async function getUserCompletedPayments(userId) {
51
- return baseClient
52
- .get(`${ONRAMP_ENDPOINT}/payments/user/${userId}/completed`)
53
- .then((res) => res.data);
70
+ return legacyBareBody(baseClient.get(`${ONRAMP_ROUTER_ENDPOINT}/on-ramps/users/${userId}/completed`), "Failed to get completed payments");
54
71
  }
55
72
  async function upsertBridgeUser(input) {
56
73
  return baseClient
57
- .post(`${ONRAMP_ENDPOINT}/user`, input)
74
+ .post(`${ONRAMP_ROUTER_ENDPOINT}/users`, input)
58
75
  .then((res) => res.data);
59
76
  }
60
77
  async function createBusinessUser(userId, businessName) {
61
- return baseClient
62
- .post(`${ONRAMP_ENDPOINT}/business-user`, {
78
+ return legacyBareBody(baseClient.post(`${ONRAMP_ROUTER_ENDPOINT}/users/business`, {
63
79
  userId,
64
80
  businessName,
65
- })
66
- .then((res) => res.data);
81
+ }), "Failed to create business user");
67
82
  }
@@ -1,107 +1,14 @@
1
1
  export * as PayableAccountsClient from "./payableAccountsServiceClient";
2
+ import { ApiResponse } from "../types";
2
3
  import { BankAccountPayoutRail, BankAccountUnpayableCode, DebitCardDetails, DebitCardUnpayableCode, ExternalBillInput, PayableAccount, PayableAccountInstitution, SimpleCardTransaction, UpsertVirtualCardInput } from "./types";
3
- export declare function getAccount(accountId: string): Promise<(Omit<import("../lib/graphClient/generated").Bill, "type" | "institution"> & {
4
- __t: import("../lib/graphClient/generated").PayableAccountType;
5
- externalId?: string | null;
6
- institutionId?: string | null;
7
- nickname?: string | null;
8
- payable: boolean;
9
- testPaymentAvailable: boolean;
10
- provider: import("../lib/graphClient/generated").AccountProvider;
11
- }) | (Omit<import("../lib/graphClient/generated").BankAccount, "type" | "institution"> & {
12
- __t: import("../lib/graphClient/generated").PayableAccountType;
13
- externalId?: string | null;
14
- institutionId?: string | null;
15
- nickname?: string | null;
16
- payable: boolean;
17
- testPaymentAvailable: boolean;
18
- provider: import("../lib/graphClient/generated").AccountProvider;
19
- } & {
20
- disabledPayoutRails?: import("./types").DisabledPayoutRail[] | null;
21
- unpayableCode?: BankAccountUnpayableCode | null;
22
- unpayableReason?: string | null;
23
- unpayableAt?: string | null;
24
- }) | (Omit<import("../lib/graphClient/generated").VirtualCard, "type" | "institution"> & {
25
- __t: import("../lib/graphClient/generated").PayableAccountType;
26
- externalId?: string | null;
27
- institutionId?: string | null;
28
- nickname?: string | null;
29
- payable: boolean;
30
- testPaymentAvailable: boolean;
31
- provider: import("../lib/graphClient/generated").AccountProvider;
32
- }) | (Omit<import("../lib/graphClient/generated").DebitCard, "type" | "institution"> & {
33
- __t: import("../lib/graphClient/generated").PayableAccountType;
34
- externalId?: string | null;
35
- institutionId?: string | null;
36
- nickname?: string | null;
37
- payable: boolean;
38
- testPaymentAvailable: boolean;
39
- provider: import("../lib/graphClient/generated").AccountProvider;
40
- } & {
41
- providerRegistrations?: import("./types").ProviderRegistration[];
42
- unpayableCode?: DebitCardUnpayableCode | null;
43
- unpayableReason?: string | null;
44
- unpayableAt?: string | null;
45
- }) | (Omit<import("../lib/graphClient/generated").OneTimePayment, "type" | "institution"> & {
46
- __t: import("../lib/graphClient/generated").PayableAccountType;
47
- externalId?: string | null;
48
- institutionId?: string | null;
49
- nickname?: string | null;
50
- payable: boolean;
51
- testPaymentAvailable: boolean;
52
- provider: import("../lib/graphClient/generated").AccountProvider;
53
- })>;
54
- export declare function getAccountByExternalId(externalId: string): Promise<(Omit<import("../lib/graphClient/generated").Bill, "type" | "institution"> & {
55
- __t: import("../lib/graphClient/generated").PayableAccountType;
56
- externalId?: string | null;
57
- institutionId?: string | null;
58
- nickname?: string | null;
59
- payable: boolean;
60
- testPaymentAvailable: boolean;
61
- provider: import("../lib/graphClient/generated").AccountProvider;
62
- }) | (Omit<import("../lib/graphClient/generated").BankAccount, "type" | "institution"> & {
63
- __t: import("../lib/graphClient/generated").PayableAccountType;
64
- externalId?: string | null;
65
- institutionId?: string | null;
66
- nickname?: string | null;
67
- payable: boolean;
68
- testPaymentAvailable: boolean;
69
- provider: import("../lib/graphClient/generated").AccountProvider;
70
- } & {
71
- disabledPayoutRails?: import("./types").DisabledPayoutRail[] | null;
72
- unpayableCode?: BankAccountUnpayableCode | null;
73
- unpayableReason?: string | null;
74
- unpayableAt?: string | null;
75
- }) | (Omit<import("../lib/graphClient/generated").VirtualCard, "type" | "institution"> & {
76
- __t: import("../lib/graphClient/generated").PayableAccountType;
77
- externalId?: string | null;
78
- institutionId?: string | null;
79
- nickname?: string | null;
80
- payable: boolean;
81
- testPaymentAvailable: boolean;
82
- provider: import("../lib/graphClient/generated").AccountProvider;
83
- }) | (Omit<import("../lib/graphClient/generated").DebitCard, "type" | "institution"> & {
84
- __t: import("../lib/graphClient/generated").PayableAccountType;
85
- externalId?: string | null;
86
- institutionId?: string | null;
87
- nickname?: string | null;
88
- payable: boolean;
89
- testPaymentAvailable: boolean;
90
- provider: import("../lib/graphClient/generated").AccountProvider;
91
- } & {
92
- providerRegistrations?: import("./types").ProviderRegistration[];
93
- unpayableCode?: DebitCardUnpayableCode | null;
94
- unpayableReason?: string | null;
95
- unpayableAt?: string | null;
96
- }) | (Omit<import("../lib/graphClient/generated").OneTimePayment, "type" | "institution"> & {
97
- __t: import("../lib/graphClient/generated").PayableAccountType;
98
- externalId?: string | null;
99
- institutionId?: string | null;
100
- nickname?: string | null;
101
- payable: boolean;
102
- testPaymentAvailable: boolean;
103
- provider: import("../lib/graphClient/generated").AccountProvider;
104
- })>;
4
+ /**
5
+ * The bare account, as the legacy `/payable-account/id/:id` route returned it,
6
+ * and `null` when there is none (as that route answered, whatever the declared
7
+ * type says). Its `/api` replacement also serves the v2 lookup, so it adds a
8
+ * debit card's `providerRegistrations`; drop them to keep the v1 shape.
9
+ */
10
+ export declare function getAccount(accountId: string): Promise<PayableAccount>;
11
+ export declare function getAccountByExternalId(externalId: string): Promise<PayableAccount>;
105
12
  export declare function getAccountsForUser(userId: string): Promise<PayableAccount[]>;
106
13
  export declare function getAccounts(accountIds: string[]): Promise<PayableAccount[]>;
107
14
  export declare function getAccountInstitution(institutionId: string): Promise<PayableAccountInstitution>;
@@ -114,7 +21,12 @@ export declare function upsertBillFromExternalAccount(input: ExternalBillInput):
114
21
  testPaymentAvailable: boolean;
115
22
  provider: import("../lib/graphClient/generated").AccountProvider;
116
23
  }>;
117
- export declare function getAccountById(accountId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<PayableAccount>>;
24
+ /**
25
+ * Same `/api` route as `getAccount`, envelope kept. That route answers a
26
+ * missing account with `data: null`; the legacy v2 route failed with "Account
27
+ * not found", so keep that failure.
28
+ */
29
+ export declare function getAccountById(accountId: string): Promise<ApiResponse<PayableAccount>>;
118
30
  export declare function createUSVirtualCardNoKyc(userId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<PayableAccount>>;
119
31
  export declare function upsertVirtualCard(input: UpsertVirtualCardInput): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<PayableAccount>>;
120
32
  export declare function getRecentCardSpendTransactions(userId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<SimpleCardTransaction[]>>;
@@ -55,40 +55,63 @@ const PAYABLE_ACCOUNTS_ENDPOINT = "/payable-accounts";
55
55
  // The Hono ServiceApi (`/api/{proxy+}`) is mapped on the shared gateway domain
56
56
  // under the `payable-accounts-v2` key (serverless.yaml HTTPAPIMapping).
57
57
  const PAYABLE_ACCOUNTS_ROUTER_ENDPOINT = "/payable-accounts-v2/api";
58
+ /**
59
+ * Awaits an `/api` request and returns the bare body its legacy route answered
60
+ * with. The `/api` routes answer every failure as a 200 failure envelope;
61
+ * throw on it, as the legacy route's non-2xx did.
62
+ */
63
+ async function legacyBareBody(request, failureMessage) {
64
+ var _a, _b;
65
+ const body = (await request).data;
66
+ if (body.status === "failure") {
67
+ throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : failureMessage);
68
+ }
69
+ return body.data;
70
+ }
71
+ /**
72
+ * The bare account, as the legacy `/payable-account/id/:id` route returned it,
73
+ * and `null` when there is none (as that route answered, whatever the declared
74
+ * type says). Its `/api` replacement also serves the v2 lookup, so it adds a
75
+ * debit card's `providerRegistrations`; drop them to keep the v1 shape.
76
+ */
58
77
  async function getAccount(accountId) {
59
- return baseClient
60
- .get(`${PAYABLE_ACCOUNTS_ENDPOINT}/payable-account/id/${accountId}`)
61
- .then((res) => res.data);
78
+ const account = await legacyBareBody(baseClient.get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/payable-accounts/${accountId}`), "Failed to get payable account");
79
+ if (!account || !("providerRegistrations" in account))
80
+ return account;
81
+ const { providerRegistrations: _registrations, ...v1Account } = account;
82
+ return v1Account;
62
83
  }
63
84
  async function getAccountByExternalId(externalId) {
64
- return baseClient
65
- .get(`${PAYABLE_ACCOUNTS_ENDPOINT}/payable-account/externalId/${externalId}`)
66
- .then((res) => res.data);
85
+ return legacyBareBody(baseClient.get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/payable-accounts/external-id/${externalId}`), "Failed to get payable account by external id");
67
86
  }
68
87
  async function getAccountsForUser(userId) {
69
- return baseClient
70
- .get(`${PAYABLE_ACCOUNTS_ENDPOINT}/payable-accounts/user/${userId}`)
71
- .then((res) => res.data);
88
+ return legacyBareBody(baseClient.get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/payable-accounts/user/${userId}`), "Failed to get payable accounts for user");
72
89
  }
73
90
  async function getAccounts(accountIds) {
74
- return baseClient
75
- .get(`${PAYABLE_ACCOUNTS_ENDPOINT}/payable-accounts?accountIds=${accountIds.join(",")}`)
76
- .then((res) => res.data);
91
+ return legacyBareBody(baseClient.get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/payable-accounts?accountIds=${accountIds.join(",")}`), "Failed to get payable accounts");
77
92
  }
78
93
  async function getAccountInstitution(institutionId) {
79
- return baseClient
80
- .get(`${PAYABLE_ACCOUNTS_ENDPOINT}/account-institution/id/${institutionId}`)
81
- .then((res) => res.data);
94
+ return legacyBareBody(baseClient.get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/account-institutions/${institutionId}`), "Failed to get account institution");
82
95
  }
83
96
  async function upsertBillFromExternalAccount(input) {
84
97
  return baseClient
85
98
  .post(`${PAYABLE_ACCOUNTS_ENDPOINT}/bills/upsert-external-account`, input)
86
99
  .then((res) => res.data);
87
100
  }
101
+ /**
102
+ * Same `/api` route as `getAccount`, envelope kept. That route answers a
103
+ * missing account with `data: null`; the legacy v2 route failed with "Account
104
+ * not found", so keep that failure.
105
+ */
88
106
  async function getAccountById(accountId) {
89
- return baseClient
90
- .get(`${PAYABLE_ACCOUNTS_ENDPOINT}/v2/payable-account/id/${accountId}`)
107
+ const body = await baseClient
108
+ .get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/payable-accounts/${accountId}`)
91
109
  .then((res) => res.data);
110
+ if (body.status === "failure")
111
+ return body;
112
+ if (!body.data)
113
+ return { status: "failure", error: { message: "Account not found" } };
114
+ return { status: "success", data: body.data };
92
115
  }
93
116
  async function createUSVirtualCardNoKyc(userId) {
94
117
  return baseClient
@@ -97,12 +120,12 @@ async function createUSVirtualCardNoKyc(userId) {
97
120
  }
98
121
  async function upsertVirtualCard(input) {
99
122
  return baseClient
100
- .post(`${PAYABLE_ACCOUNTS_ENDPOINT}/virtual-card/upsert-external-card`, input)
123
+ .post(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/cards/upsert`, input)
101
124
  .then((res) => res.data);
102
125
  }
103
126
  async function getRecentCardSpendTransactions(userId) {
104
127
  return baseClient
105
- .get(`${PAYABLE_ACCOUNTS_ENDPOINT}/virtual-card/recent-transactions/user/${userId}`)
128
+ .get(`${PAYABLE_ACCOUNTS_ROUTER_ENDPOINT}/cards/user/${userId}/recent-transactions`)
106
129
  .then((res) => res.data);
107
130
  }
108
131
  /**
@@ -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() {
@@ -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) {
@@ -1,19 +1,29 @@
1
1
  export * as Web3Client from "./web3ServiceClient";
2
+ import { ApiFailure, ApiResponse } from "../types";
2
3
  import { ExactInQuoteInput, ExactInQuoteResponse, ListListedKaminoVaultIdsInput, ListListedKaminoVaultIdsResponse, OpsSignerMigrationState, OpsSignerReplacement, OpsSignerType, Portfolio, SignerUsageType, SolanaPaymentBuildInput, SolanaPaymentBuildResult, TokenBalance, UserOpsSigner, WalletTokenBalanceInput } from "./types";
4
+ /**
5
+ * The bare quote, as the legacy `/quote/swap/exactIn` route returned it. A
6
+ * failed quote still throws on the route's 400, as before.
7
+ */
3
8
  export declare function getExactInQuote(input: ExactInQuoteInput): Promise<ExactInQuoteResponse>;
4
- export declare function getTokenBalances(input: WalletTokenBalanceInput): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<TokenBalance[]>>;
5
- export declare function getPortfolio(address: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<Portfolio>>;
9
+ /**
10
+ * Balances on `input.network` only, dust filtered as on the legacy
11
+ * `/token-balances` route: `/api/token-balances` runs the same service.
12
+ * (`/api/wallet-balances` is multichain with dust and is NOT a substitute.)
13
+ */
14
+ export declare function getTokenBalances(input: WalletTokenBalanceInput): Promise<ApiResponse<TokenBalance[]>>;
15
+ export declare function getPortfolio(address: string): Promise<ApiFailure | import("../types").ApiSuccess<Portfolio>>;
6
16
  export declare function getUserOpsSigner(input: {
7
17
  userId: string;
8
18
  signerType: OpsSignerType;
9
- }): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<UserOpsSigner>>;
19
+ }): Promise<ApiResponse<UserOpsSigner>>;
10
20
  export declare function getUserOpsSignerByAddress(input: {
11
21
  address: `0x${string}`;
12
- }): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<UserOpsSigner>>;
22
+ }): Promise<ApiResponse<UserOpsSigner>>;
13
23
  export declare function getSmartAccountAddress(input: {
14
24
  userId: string;
15
25
  usageType: SignerUsageType;
16
- }): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<`0x${string}`>>;
26
+ }): Promise<ApiResponse<`0x${string}`>>;
17
27
  /**
18
28
  * Provisions the user's signer for `signerType` if they do not already have one
19
29
  * and returns it. Turnkey bills per derived address, so signers are minted
@@ -23,7 +33,7 @@ export declare function getSmartAccountAddress(input: {
23
33
  export declare function ensureUserOpsSigner(input: {
24
34
  userId: string;
25
35
  signerType: OpsSignerType;
26
- }): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<UserOpsSigner>>;
36
+ }): Promise<ApiResponse<UserOpsSigner>>;
27
37
  /**
28
38
  * Creates an inactive signer in the current ops wallet for a legacy user. The
29
39
  * existing signer remains active until its consumer completes the external
@@ -32,10 +42,10 @@ export declare function ensureUserOpsSigner(input: {
32
42
  export declare function stageUserOpsSignerReplacement(input: {
33
43
  userId: string;
34
44
  signerType: OpsSignerType;
35
- }): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<OpsSignerReplacement>>;
45
+ }): Promise<ApiFailure | import("../types").ApiSuccess<OpsSignerReplacement>>;
36
46
  export declare function getUserOpsSignerReplacement(input: {
37
47
  userId: string;
38
48
  signerType: OpsSignerType;
39
- }): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<OpsSignerMigrationState>>;
40
- export declare function buildSolanaPayment(input: SolanaPaymentBuildInput): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<SolanaPaymentBuildResult>>;
41
- export declare function listListedKaminoVaultIds(input?: ListListedKaminoVaultIdsInput): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<ListListedKaminoVaultIdsResponse>>;
49
+ }): Promise<ApiFailure | import("../types").ApiSuccess<OpsSignerMigrationState>>;
50
+ export declare function buildSolanaPayment(input: SolanaPaymentBuildInput): Promise<ApiFailure | import("../types").ApiSuccess<SolanaPaymentBuildResult>>;
51
+ export declare function listListedKaminoVaultIds(input?: ListListedKaminoVaultIdsInput): Promise<ApiFailure | import("../types").ApiSuccess<ListListedKaminoVaultIdsResponse>>;
@@ -32,6 +32,9 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
39
  exports.Web3Client = void 0;
37
40
  exports.getExactInQuote = getExactInQuote;
@@ -46,19 +49,57 @@ exports.getUserOpsSignerReplacement = getUserOpsSignerReplacement;
46
49
  exports.buildSolanaPayment = buildSolanaPayment;
47
50
  exports.listListedKaminoVaultIds = listListedKaminoVaultIds;
48
51
  exports.Web3Client = __importStar(require("./web3ServiceClient"));
52
+ const axios_1 = __importDefault(require("axios"));
49
53
  const restClient_1 = require("../restClient");
50
54
  const baseClient = (0, restClient_1.getRestClient)(process.env.WEB3_SERVICE_API_IAM_URL, "/v2/web3/api");
51
55
  const WEB3_ENDPOINT = "/web3";
52
56
  const WEB3_V2_ENDPOINT = "/v2/web3/api";
57
+ /**
58
+ * Resolves with the `/api` envelope, success or failure. web3's `/api` routes
59
+ * answer a failure with a 4xx/5xx carrying the failure envelope, where the
60
+ * legacy routes answered 200; resolve with that envelope, as before. Anything
61
+ * else (a transport error, a body that is not an envelope) still throws.
62
+ */
63
+ async function legacyEnvelope(request) {
64
+ var _a;
65
+ try {
66
+ return (await request).data;
67
+ }
68
+ catch (error) {
69
+ const body = axios_1.default.isAxiosError(error) ? (_a = error.response) === null || _a === void 0 ? void 0 : _a.data : undefined;
70
+ if (isFailureEnvelope(body))
71
+ return body;
72
+ throw error;
73
+ }
74
+ }
75
+ function isFailureEnvelope(body) {
76
+ var _a;
77
+ return (typeof body === "object" &&
78
+ body !== null &&
79
+ body.status === "failure" &&
80
+ typeof ((_a = body.error) === null || _a === void 0 ? void 0 : _a.message) === "string");
81
+ }
82
+ /**
83
+ * The bare quote, as the legacy `/quote/swap/exactIn` route returned it. A
84
+ * failed quote still throws on the route's 400, as before.
85
+ */
53
86
  async function getExactInQuote(input) {
54
- return baseClient
55
- .post(`${WEB3_ENDPOINT}/quote/swap/exactIn`, input)
87
+ var _a, _b;
88
+ const body = await baseClient
89
+ .post(`${WEB3_V2_ENDPOINT}/quote/swap/exactIn`, input)
56
90
  .then((res) => res.data);
91
+ if (body.status === "failure") {
92
+ throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "Failed to get ExactIn swap quote");
93
+ }
94
+ return body.data;
57
95
  }
96
+ /**
97
+ * Balances on `input.network` only, dust filtered as on the legacy
98
+ * `/token-balances` route: `/api/token-balances` runs the same service.
99
+ * (`/api/wallet-balances` is multichain with dust and is NOT a substitute.)
100
+ */
58
101
  async function getTokenBalances(input) {
59
- return baseClient
60
- .post(`${WEB3_ENDPOINT}/token-balances`, input)
61
- .then((res) => res.data);
102
+ return legacyEnvelope(baseClient.post(`${WEB3_V2_ENDPOINT}/token-balances`, input));
62
103
  }
63
104
  async function getPortfolio(address) {
64
105
  return baseClient
@@ -66,19 +107,13 @@ async function getPortfolio(address) {
66
107
  .then((res) => res.data);
67
108
  }
68
109
  async function getUserOpsSigner(input) {
69
- return baseClient
70
- .get(`${WEB3_ENDPOINT}/ops-signer/user/${input.userId}?signerType=${input.signerType}`)
71
- .then((res) => res.data);
110
+ return legacyEnvelope(baseClient.get(`${WEB3_V2_ENDPOINT}/ops-signer/user/${input.userId}?signerType=${input.signerType}`));
72
111
  }
73
112
  async function getUserOpsSignerByAddress(input) {
74
- return baseClient
75
- .get(`${WEB3_ENDPOINT}/ops-signer/address?address=${input.address}`)
76
- .then((res) => res.data);
113
+ return legacyEnvelope(baseClient.get(`${WEB3_V2_ENDPOINT}/ops-signer/address?address=${input.address}`));
77
114
  }
78
115
  async function getSmartAccountAddress(input) {
79
- return baseClient
80
- .get(`${WEB3_ENDPOINT}/ops-signer/smart-account/${input.userId}?usageType=${input.usageType}`)
81
- .then((res) => res.data);
116
+ return legacyEnvelope(baseClient.get(`${WEB3_V2_ENDPOINT}/ops-signer/smart-account/${input.userId}?usageType=${input.usageType}`));
82
117
  }
83
118
  /**
84
119
  * Provisions the user's signer for `signerType` if they do not already have one
@@ -87,9 +122,7 @@ async function getSmartAccountAddress(input) {
87
122
  * instead of `getUserOpsSigner` anywhere a missing signer should be created.
88
123
  */
89
124
  async function ensureUserOpsSigner(input) {
90
- return baseClient
91
- .post(`${WEB3_ENDPOINT}/ops-signer/user/${input.userId}?signerType=${input.signerType}`)
92
- .then((res) => res.data);
125
+ return legacyEnvelope(baseClient.post(`${WEB3_V2_ENDPOINT}/ops-signer/user/${input.userId}?signerType=${input.signerType}`));
93
126
  }
94
127
  /**
95
128
  * Creates an inactive signer in the current ops wallet for a legacy user. The
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spritz-finance/service-client",
3
- "version": "0.34.2",
3
+ "version": "0.36.0",
4
4
  "gitHead": "06f8e96b7b38c34df26a38da329331940675e4f8",
5
5
  "description": "Service client",
6
6
  "license": "ISC",