@spritz-finance/service-client 0.33.0 → 0.34.1

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.
@@ -56,9 +56,12 @@ async function createBridgeBankAccount(userId, accountId, input) {
56
56
  .post(`${ONRAMP_ENDPOINT}/user/${userId}/bank-account/${accountId}`, input)
57
57
  .then((res) => res.data);
58
58
  }
59
+ // Unlike the legacy `/user/:id` route, `/api/users/:id` refreshes the user's
60
+ // outstanding provider terms when they have a Bridge customer (falling back to
61
+ // the stored record if that refresh fails), so it can be slower.
59
62
  async function getBridgeUser(userId) {
60
63
  return baseClient
61
- .get(`${ONRAMP_ENDPOINT}/user/${userId}`)
64
+ .get(`${ONRAMP_ROUTER_ENDPOINT}/users/${userId}`)
62
65
  .then((res) => res.data);
63
66
  }
64
67
  async function validateTransfer({ userId, transferId, amount, toAddress, }) {
@@ -41,9 +41,12 @@ exports.CheckbookClient = __importStar(require("./checkbookServiceClient"));
41
41
  const restClient_1 = require("../restClient");
42
42
  const baseClient = (0, restClient_1.getRestClient)(process.env.CHECKBOOK_SERVICE_API_IAM_URL, "/v2/liabilities/api");
43
43
  const CHECKBOOK_ENDPOINT = "/liabilities";
44
+ const CHECKBOOK_API_ENDPOINT = "/v2/liabilities/api";
44
45
  async function triggerBatch({ config, configs, reserve, currency, }) {
46
+ // Same enqueueRunBatch call as the legacy `/checkbook/batch` route; the
47
+ // route validates `currency` as USD | CAD and needs `config` or `configs`.
45
48
  return baseClient
46
- .post(`${CHECKBOOK_ENDPOINT}/checkbook/batch`, {
49
+ .post(`${CHECKBOOK_API_ENDPOINT}/checkbook/run-batch`, {
47
50
  config,
48
51
  currency,
49
52
  reserve,
@@ -9,6 +9,12 @@ export declare function createCheckbookUser(args: CreateCheckbookUserParams): Pr
9
9
  export declare function upsertCheckbookUser(args: CreateCheckbookUserParams): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<CheckbookUser>>;
10
10
  export declare function getCheckbookUser(userId: string): Promise<CheckbookUser | null>;
11
11
  export declare function createCheckbookVirtualCard(userId: string): Promise<CheckbookCardResponse>;
12
+ /**
13
+ * Served by the Hono ServiceApi's `/checkbook/debit-card/create` (the same
14
+ * service call the legacy `/debit-card/create` Lambda made). The legacy route
15
+ * returned the bare card and threw (404) on any failure; keep that contract by
16
+ * unwrapping the envelope and throwing on a failure or empty result.
17
+ */
12
18
  export declare function createCheckbookDebitCard(input: CreateDebitCardInput): Promise<CheckbookDebitCardResponse>;
13
19
  /**
14
20
  * Registers a debit card from a platform Evervault tokenization. Hits the same
@@ -21,6 +27,11 @@ export declare function createTokenizedDebitCard(input: CreateTokenizedDebitCard
21
27
  export declare function createCheckbookDigitalAccount(input: CreateDigitalAccountInput): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<CheckbookDigitalAccountResponse>>;
22
28
  export declare function createUSBillFromAccountNumber(userId: string, accountNumber: string, merchantId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<ExternalBillInput>>;
23
29
  export declare function getVirtualCardBalance(cardExternalId: string, userId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<number>>;
30
+ /**
31
+ * Projects the owner from the full record served by `/direct-payment/:id`.
32
+ * Same contract as the legacy `/direct-payments/:id/user` route: `null` when no
33
+ * such payment exists, a throw when the lookup itself fails.
34
+ */
24
35
  export declare function getUserIdForDirectPayment(directPaymentId: string): Promise<string | null>;
25
36
  export declare function updateCheckbookVirtualCard(userId: string, cardExternalId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<CheckbookUpdateCardResponse>>;
26
37
  export declare function addPromotionCredit(input: {
@@ -57,6 +57,7 @@ exports.LiabilitiesClient = __importStar(require("./liabilitiesServiceClient"));
57
57
  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
+ const LIABILITIES_V2_ENDPOINT = "/v2/liabilities/api";
60
61
  async function getRewardTransaction(transactionId) {
61
62
  return baseClient
62
63
  .get(`${LIABILITIES_ENDPOINT}/reward-transactions/${transactionId}`)
@@ -92,10 +93,22 @@ async function createCheckbookVirtualCard(userId) {
92
93
  .post(`${LIABILITIES_ENDPOINT}/virtual-card/create/${userId}`)
93
94
  .then((res) => res.data);
94
95
  }
96
+ /**
97
+ * Served by the Hono ServiceApi's `/checkbook/debit-card/create` (the same
98
+ * service call the legacy `/debit-card/create` Lambda made). The legacy route
99
+ * returned the bare card and threw (404) on any failure; keep that contract by
100
+ * unwrapping the envelope and throwing on a failure or empty result.
101
+ */
95
102
  async function createCheckbookDebitCard(input) {
96
- return baseClient
97
- .post(`${LIABILITIES_ENDPOINT}/debit-card/create`, input)
98
- .then((res) => res.data);
103
+ var _a, _b;
104
+ const res = await baseClient.post(`${LIABILITIES_V2_ENDPOINT}/checkbook/debit-card/create`, input);
105
+ const body = res.data;
106
+ if (body.status === "failure") {
107
+ throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "Debit card creation failed");
108
+ }
109
+ if (!body.data)
110
+ throw new Error("Debit card creation failed");
111
+ return body.data;
99
112
  }
100
113
  /**
101
114
  * Registers a debit card from a platform Evervault tokenization. Hits the same
@@ -138,10 +151,19 @@ async function getVirtualCardBalance(cardExternalId, userId) {
138
151
  .get(`${LIABILITIES_ENDPOINT}/virtual-card/card/${cardExternalId}/balance?userId=${userId}`)
139
152
  .then((res) => res.data);
140
153
  }
154
+ /**
155
+ * Projects the owner from the full record served by `/direct-payment/:id`.
156
+ * Same contract as the legacy `/direct-payments/:id/user` route: `null` when no
157
+ * such payment exists, a throw when the lookup itself fails.
158
+ */
141
159
  async function getUserIdForDirectPayment(directPaymentId) {
142
- return baseClient
143
- .get(`${LIABILITIES_ENDPOINT}/direct-payments/${directPaymentId}/user`)
144
- .then((res) => res.data);
160
+ var _a, _b, _c, _d;
161
+ const res = await baseClient.get(`${LIABILITIES_V2_ENDPOINT}/direct-payment/${directPaymentId}`);
162
+ const body = res.data;
163
+ if (body.status === "failure") {
164
+ throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "Failed to get direct payment");
165
+ }
166
+ return (_d = (_c = body.data) === null || _c === void 0 ? void 0 : _c.userId) !== null && _d !== void 0 ? _d : null;
145
167
  }
146
168
  async function updateCheckbookVirtualCard(userId, cardExternalId) {
147
169
  return baseClient
@@ -166,7 +188,6 @@ async function getRewardTransactionsFor(userId) {
166
188
  .get(`${LIABILITIES_ENDPOINT}/rewards/user/${userId}/transactions`)
167
189
  .then((res) => res.data);
168
190
  }
169
- const LIABILITIES_V2_ENDPOINT = "/v2/liabilities/api";
170
191
  async function getDirectPayment(directPaymentId) {
171
192
  return baseClient
172
193
  .get(`${LIABILITIES_V2_ENDPOINT}/direct-payment/${directPaymentId}`)
@@ -1,5 +1,6 @@
1
1
  export * as PaymentsClient from "./paymentsClient";
2
2
  import { DirectPayment, DirectPaymentStatus, PaymentDeliveryMethod } from "../lib/graphClient/generated";
3
+ import { ApiResponse } from "../types";
3
4
  import { CreateDirectPaymentArgs, ExternalPaymentInput, ExternalPaymentStatusInput, GetUserRewardFeeAmountBody, GetUsersTransactionVolumeBody, Payment, PaymentQueryFilter, PaymentSource } from "./types";
4
5
  export type DirectPaymentModel = {
5
6
  _id?: string;
@@ -46,8 +47,18 @@ export declare function getRewardFeeAmount(args: GetUserRewardFeeAmountBody): Pr
46
47
  export declare function initializeExternalPayment(args: ExternalPaymentInput): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<Payment | null>>;
47
48
  export declare function scheduleExternalPayment(args: ExternalPaymentInput): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<Payment | null>>;
48
49
  export declare function updateExternalPaymentStatus(paymentId: string, input: ExternalPaymentStatusInput): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<Payment | null>>;
50
+ /**
51
+ * The lowercased address of the token the payment was actually sent in — the
52
+ * first transaction reference's source token, not the record's quoted
53
+ * `tokenAddress` — or `null` when the payment or reference is missing. Throws
54
+ * when the lookup itself fails, like the legacy `/token` route.
55
+ */
49
56
  export declare function getDirectPaymentToken(directPaymentId: string): Promise<string | null>;
50
- export declare function getDirectPaymentDetails(directPaymentId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<{
57
+ /**
58
+ * A missing payment answers success with every field `""`, as the legacy
59
+ * `/details` route did; a failed lookup passes through as a failure.
60
+ */
61
+ export declare function getDirectPaymentDetails(directPaymentId: string): Promise<ApiResponse<{
51
62
  tokenAddress: string;
52
63
  network: string;
53
64
  source: string;
@@ -110,15 +110,46 @@ async function updateExternalPaymentStatus(paymentId, input) {
110
110
  .post(`${PAYMENTS_ROUTER_ENDPOINT}/external-payment/status/${paymentId}`, input)
111
111
  .then((res) => res.data);
112
112
  }
113
- async function getDirectPaymentToken(directPaymentId) {
113
+ // The full direct payment record (`null` when none exists), which the
114
+ // token/details wrappers below project to their legacy shapes.
115
+ async function getDirectPaymentRecord(directPaymentId) {
114
116
  return baseClient
115
- .get(`${PAYMENTS_ENDPOINT}/direct-payments/${directPaymentId}/token`)
117
+ .get(`${PAYMENTS_ROUTER_ENDPOINT}/direct-payment/${directPaymentId}`)
116
118
  .then((res) => res.data);
117
119
  }
120
+ /**
121
+ * The lowercased address of the token the payment was actually sent in — the
122
+ * first transaction reference's source token, not the record's quoted
123
+ * `tokenAddress` — or `null` when the payment or reference is missing. Throws
124
+ * when the lookup itself fails, like the legacy `/token` route.
125
+ */
126
+ async function getDirectPaymentToken(directPaymentId) {
127
+ var _a, _b, _c, _d, _e, _f, _g, _h;
128
+ const body = await getDirectPaymentRecord(directPaymentId);
129
+ if (body.status === "failure") {
130
+ throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "Failed to get direct payment");
131
+ }
132
+ return (_h = (_g = (_f = (_e = (_d = (_c = body.data) === null || _c === void 0 ? void 0 : _c.transactionReferences) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.sourceToken) === null || _f === void 0 ? void 0 : _f.address) === null || _g === void 0 ? void 0 : _g.toLowerCase()) !== null && _h !== void 0 ? _h : null;
133
+ }
134
+ /**
135
+ * A missing payment answers success with every field `""`, as the legacy
136
+ * `/details` route did; a failed lookup passes through as a failure.
137
+ */
118
138
  async function getDirectPaymentDetails(directPaymentId) {
119
- return baseClient
120
- .get(`${PAYMENTS_ENDPOINT}/direct-payments/${directPaymentId}/details`)
121
- .then((res) => res.data);
139
+ var _a, _b, _c, _d;
140
+ const body = await getDirectPaymentRecord(directPaymentId);
141
+ if (body.status === "failure")
142
+ return body;
143
+ const directPayment = body.data;
144
+ return {
145
+ status: "success",
146
+ data: {
147
+ tokenAddress: (_a = directPayment === null || directPayment === void 0 ? void 0 : directPayment.tokenAddress) !== null && _a !== void 0 ? _a : "",
148
+ network: (_b = directPayment === null || directPayment === void 0 ? void 0 : directPayment.network) !== null && _b !== void 0 ? _b : "",
149
+ source: (_c = directPayment === null || directPayment === void 0 ? void 0 : directPayment.source) !== null && _c !== void 0 ? _c : "",
150
+ accountId: (_d = directPayment === null || directPayment === void 0 ? void 0 : directPayment.accountId) !== null && _d !== void 0 ? _d : "",
151
+ },
152
+ };
122
153
  }
123
154
  async function getAllPaymentsForUser(userId) {
124
155
  return baseClient
@@ -126,8 +157,10 @@ async function getAllPaymentsForUser(userId) {
126
157
  .then((res) => res.data);
127
158
  }
128
159
  async function getUserPaymentById(userId, paymentId) {
160
+ // `-transaction` drops the default direct-payment join, leaving the same
161
+ // plain `findOne({ _id, userId })` document the legacy route returned.
129
162
  return baseClient
130
- .get(`${PAYMENTS_ENDPOINT}/payments/user/${userId}/payment/${paymentId}`)
163
+ .get(`${PAYMENTS_ROUTER_ENDPOINT}/payments/${paymentId}/users/${userId}`, { params: { include: "-transaction" } })
131
164
  .then((res) => res.data);
132
165
  }
133
166
  async function directPaymentsForRiskAnalysis(userId) {
@@ -44,9 +44,13 @@ exports.PayoutsClient = __importStar(require("./payoutsServiceClient"));
44
44
  const restClient_1 = require("../restClient");
45
45
  const baseClient = (0, restClient_1.getRestClient)(process.env.PAYOUTS_SERVICE_API_IAM_URL, "/v2/bridgebot/api");
46
46
  const PAYOUTS_ENDPOINT = "/bridgebot";
47
+ // Bridgebot's Hono /api surface, reached through the same gateway host via the
48
+ // /v2/bridgebot base path (the bare /bridgebot base path maps to bridgebot's
49
+ // legacy REST API).
50
+ const PAYOUTS_API_ENDPOINT = "/v2/bridgebot/api";
47
51
  async function requestCryptoPayout({ userId, type, network, amountFiat, referenceId, toAddress, tokenSymbol, currencyFiat = "USD", fromDispatchWallet = false, }) {
48
52
  return baseClient
49
- .post(`${PAYOUTS_ENDPOINT}/payouts/crypto`, {
53
+ .post(`${PAYOUTS_API_ENDPOINT}/payouts/crypto`, {
50
54
  userId,
51
55
  type,
52
56
  network,
@@ -82,11 +86,8 @@ async function executeRainAdminChange(input) {
82
86
  .post(`${PAYOUTS_ENDPOINT}/signers/rain-admin-change`, input)
83
87
  .then((res) => res.data);
84
88
  }
85
- // Served by bridgebot's Hono /api surface; reached through the same gateway
86
- // host via the /v2/bridgebot base path (the bare /bridgebot base path maps to
87
- // bridgebot's legacy REST API, which does not carry this route).
88
89
  async function getTreasuryBalances() {
89
90
  return baseClient
90
- .get(`/v2${PAYOUTS_ENDPOINT}/api/treasury/balances`)
91
+ .get(`${PAYOUTS_API_ENDPOINT}/treasury/balances`)
91
92
  .then((res) => res.data);
92
93
  }
@@ -1,8 +1,20 @@
1
1
  export * as VerificationClient from "./verificationServiceClient";
2
2
  import { BasicIdentityData, IdentityData, Verification } from "./types";
3
+ /**
4
+ * The bare verification document, as the legacy `/user/:id` route returned it:
5
+ * the `/api` envelope is unwrapped and a failure throws (the service creates
6
+ * the document on first read, so success always carries one).
7
+ */
3
8
  export declare function getUserVerification(userId: string): Promise<Verification>;
4
9
  export declare function getUserIdentity(userId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<IdentityData>>;
5
10
  export declare function getBasicUserIdentity(userId: string): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<BasicIdentityData>>;
11
+ /**
12
+ * Disables one user via `/api/user/:id/disable` (the same
13
+ * `identityService.disableUser` the legacy bulk `/users/disable` route looped
14
+ * over). The legacy route answered a failure with a non-2xx and so threw; this
15
+ * route answers 200 with a failure envelope, so throw on that to keep callers'
16
+ * error handling working. Resolves with the raw response, as before.
17
+ */
6
18
  export declare function disableUser(userId: string, note: string): Promise<import("axios").AxiosResponse<any, any>>;
7
19
  export declare function createUserVerification(input: {
8
20
  userId: string;
@@ -45,24 +45,49 @@ exports.VerificationClient = __importStar(require("./verificationServiceClient")
45
45
  const restClient_1 = require("../restClient");
46
46
  const baseClient = (0, restClient_1.getRestClient)(process.env.VERIFICATION_SERVICE_API_IAM_URL, "/v2/verification/api");
47
47
  const VERIFICATION_ENDPOINT = "/verification";
48
+ const VERIFICATION_API_ENDPOINT = "/v2/verification/api";
49
+ /**
50
+ * The bare verification document, as the legacy `/user/:id` route returned it:
51
+ * the `/api` envelope is unwrapped and a failure throws (the service creates
52
+ * the document on first read, so success always carries one).
53
+ */
48
54
  async function getUserVerification(userId) {
49
- return baseClient.get(`${VERIFICATION_ENDPOINT}/user/${userId}`).then((res) => res.data);
55
+ var _a, _b;
56
+ const res = await baseClient.get(`${VERIFICATION_API_ENDPOINT}/user/${userId}`);
57
+ const body = res.data;
58
+ if (body.status === "failure") {
59
+ throw new Error((_b = (_a = body.error) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : "Failed to get user verification");
60
+ }
61
+ return body.data;
50
62
  }
63
+ // Priority `operational` mirrors the legacy route's Persona behavior (never
64
+ // shed); the /api route gained it in verification#197 for exactly this switch.
51
65
  async function getUserIdentity(userId) {
52
66
  return baseClient
53
- .get(`${VERIFICATION_ENDPOINT}/user/${userId}/identity`)
67
+ .get(`${VERIFICATION_API_ENDPOINT}/user/${userId}/identity?priority=operational`)
54
68
  .then((res) => res.data);
55
69
  }
56
70
  async function getBasicUserIdentity(userId) {
57
71
  return baseClient
58
- .get(`${VERIFICATION_ENDPOINT}/user/${userId}/identity?sensitive=false`)
72
+ .get(`${VERIFICATION_API_ENDPOINT}/user/${userId}/identity?sensitive=false&priority=operational`)
59
73
  .then((res) => res.data);
60
74
  }
75
+ /**
76
+ * Disables one user via `/api/user/:id/disable` (the same
77
+ * `identityService.disableUser` the legacy bulk `/users/disable` route looped
78
+ * over). The legacy route answered a failure with a non-2xx and so threw; this
79
+ * route answers 200 with a failure envelope, so throw on that to keep callers'
80
+ * error handling working. Resolves with the raw response, as before.
81
+ */
61
82
  async function disableUser(userId, note) {
62
- return baseClient.post(`${VERIFICATION_ENDPOINT}/users/disable`, {
63
- userIds: [userId],
83
+ var _a, _b, _c;
84
+ const res = await baseClient.post(`${VERIFICATION_API_ENDPOINT}/user/${userId}/disable`, {
64
85
  note,
65
86
  });
87
+ if (((_a = res.data) === null || _a === void 0 ? void 0 : _a.status) === "failure") {
88
+ throw new Error((_c = (_b = res.data.error) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : "Failed to disable user");
89
+ }
90
+ return res;
66
91
  }
67
92
  async function createUserVerification(input) {
68
93
  return baseClient
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spritz-finance/service-client",
3
- "version": "0.33.0",
3
+ "version": "0.34.1",
4
4
  "gitHead": "06f8e96b7b38c34df26a38da329331940675e4f8",
5
5
  "description": "Service client",
6
6
  "license": "ISC",