@spritz-finance/service-client 0.39.0 → 0.40.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.
- package/lib/rain/rainServiceClient.d.ts +14 -13
- package/lib/rain/rainServiceClient.js +46 -3
- package/lib/sigv4.js +8 -2
- package/package.json +2 -2
|
@@ -1,57 +1,58 @@
|
|
|
1
1
|
export * as RainClient from "./rainServiceClient";
|
|
2
2
|
import { VirtualCardStatus } from "../payableAccounts/types";
|
|
3
|
+
import { ApiFailure, ApiResponse } from "../types";
|
|
3
4
|
import { ApplicationStatus, CardDetailsResponse, CardOrderStatus, CardType, CreateRainApplicationInput, OrderPhysicalCardInput, OrderPhysicalCardResponse, RainCard, RainContract, RainUser, ShippingDetails, WithdrawalSignature } from "./types";
|
|
4
5
|
export declare const CREATE_CARD_APPLICATION_TIMEOUT_MS = 28000;
|
|
5
|
-
export declare function createCardApplication(userId: string, input: CreateRainApplicationInput): Promise<
|
|
6
|
+
export declare function createCardApplication(userId: string, input: CreateRainApplicationInput): Promise<ApiFailure | import("../types").ApiSuccess<RainUser>>;
|
|
6
7
|
export declare function getUserDepositAddress({ userId, network, }: {
|
|
7
8
|
userId: string;
|
|
8
9
|
network: string;
|
|
9
|
-
}): Promise<
|
|
10
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<RainContract>>;
|
|
10
11
|
export declare function validateContractAddress(input: {
|
|
11
12
|
userId: string;
|
|
12
13
|
network: string;
|
|
13
14
|
contractAddress: string;
|
|
14
|
-
}): Promise<
|
|
15
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<boolean>>;
|
|
15
16
|
export declare function createRainCard({ userId, nickname, type, shipping, }: {
|
|
16
17
|
userId: string;
|
|
17
18
|
nickname?: string;
|
|
18
19
|
type?: CardType;
|
|
19
20
|
shipping?: ShippingDetails;
|
|
20
|
-
}): Promise<
|
|
21
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<RainCard>>;
|
|
21
22
|
export declare function updateCardStatus({ userId, status, cardExternalId, }: {
|
|
22
23
|
userId: string;
|
|
23
24
|
status: VirtualCardStatus;
|
|
24
25
|
cardExternalId: string;
|
|
25
|
-
}): Promise<
|
|
26
|
+
}): Promise<ApiResponse<RainCard>>;
|
|
26
27
|
export declare function activatePhysicalCard({ userId, accountId, expirationMonth, expirationYear, }: {
|
|
27
28
|
userId: string;
|
|
28
29
|
accountId: string;
|
|
29
30
|
expirationMonth: string;
|
|
30
31
|
expirationYear: string;
|
|
31
|
-
}): Promise<
|
|
32
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<RainCard>>;
|
|
32
33
|
export declare function getLiveBalance({ userId }: {
|
|
33
34
|
userId: string;
|
|
34
|
-
}): Promise<
|
|
35
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<{
|
|
35
36
|
balance: number;
|
|
36
37
|
}>>;
|
|
37
38
|
export declare function getCardDetails({ userId, cardId }: {
|
|
38
39
|
userId: string;
|
|
39
40
|
cardId: string;
|
|
40
|
-
}): Promise<
|
|
41
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<CardDetailsResponse>>;
|
|
41
42
|
export declare function requestWithdrawalSignature({ userId, network, amount, }: {
|
|
42
43
|
userId: string;
|
|
43
44
|
network: string;
|
|
44
45
|
amount: string;
|
|
45
|
-
}): Promise<
|
|
46
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<WithdrawalSignature>>;
|
|
46
47
|
export declare function adminGetUserInfo({ userId }: {
|
|
47
48
|
userId: string;
|
|
48
|
-
}): Promise<
|
|
49
|
+
}): Promise<ApiFailure | import("../types").ApiSuccess<{
|
|
49
50
|
id: string;
|
|
50
51
|
externalId: string;
|
|
51
52
|
applicationStatus: ApplicationStatus;
|
|
52
53
|
depositAddress: string;
|
|
53
54
|
}>>;
|
|
54
|
-
export declare function orderPhysicalCard(input: OrderPhysicalCardInput): Promise<
|
|
55
|
+
export declare function orderPhysicalCard(input: OrderPhysicalCardInput): Promise<ApiFailure | import("../types").ApiSuccess<OrderPhysicalCardResponse>>;
|
|
55
56
|
export interface PendingCardOrder {
|
|
56
57
|
id: string;
|
|
57
58
|
userId: string;
|
|
@@ -74,7 +75,7 @@ export interface PendingCardOrder {
|
|
|
74
75
|
replacementFor?: string;
|
|
75
76
|
replacementForCard?: string;
|
|
76
77
|
}
|
|
77
|
-
export declare function getPendingCardOrder(userId: string): Promise<
|
|
78
|
+
export declare function getPendingCardOrder(userId: string): Promise<ApiFailure | import("../types").ApiSuccess<PendingCardOrder | null>>;
|
|
78
79
|
type CashbackSummary = {
|
|
79
80
|
enabled: boolean;
|
|
80
81
|
activeSpree: {
|
|
@@ -90,7 +91,7 @@ type CashbackSummary = {
|
|
|
90
91
|
nextSpreeMinPayment: number | null;
|
|
91
92
|
};
|
|
92
93
|
};
|
|
93
|
-
export declare function getCardUser(userId: string): Promise<
|
|
94
|
+
export declare function getCardUser(userId: string): Promise<ApiFailure | import("../types").ApiSuccess<{
|
|
94
95
|
id: string | undefined;
|
|
95
96
|
status: ApplicationStatus;
|
|
96
97
|
applicationCompletionLink: string | undefined;
|
|
@@ -48,7 +48,9 @@ exports.orderPhysicalCard = orderPhysicalCard;
|
|
|
48
48
|
exports.getPendingCardOrder = getPendingCardOrder;
|
|
49
49
|
exports.getCardUser = getCardUser;
|
|
50
50
|
exports.RainClient = __importStar(require("./rainServiceClient"));
|
|
51
|
+
const types_1 = require("../payableAccounts/types");
|
|
51
52
|
const restClient_1 = require("../restClient");
|
|
53
|
+
const types_2 = require("./types");
|
|
52
54
|
const baseClient = (0, restClient_1.getRestClient)(process.env.RAIN_SERVICE_API_IAM_URL, "/rain-v2/api");
|
|
53
55
|
const RAIN_ENDPOINT = "/rain-v2";
|
|
54
56
|
// Rain's CreateRainApplication submits the application and uploads the ID
|
|
@@ -90,12 +92,53 @@ async function createRainCard({ userId, nickname, type, shipping, }) {
|
|
|
90
92
|
})
|
|
91
93
|
.then((res) => res.data);
|
|
92
94
|
}
|
|
95
|
+
// The statuses `PATCH /api/cards/:cardId/status` accepts. The legacy route
|
|
96
|
+
// also took NotActivated, which no caller sends and Rain cannot set.
|
|
97
|
+
const CARD_STATUS_BY_VIRTUAL_CARD_STATUS = {
|
|
98
|
+
[types_1.VirtualCardStatus.Active]: types_2.CardStatus.Active,
|
|
99
|
+
[types_1.VirtualCardStatus.Frozen]: types_2.CardStatus.Locked,
|
|
100
|
+
[types_1.VirtualCardStatus.Cancelled]: types_2.CardStatus.Canceled,
|
|
101
|
+
};
|
|
102
|
+
// `/api/cards/users/:userId` caps a page at 100 cards.
|
|
103
|
+
const USER_CARDS_PAGE_LIMIT = 100;
|
|
104
|
+
function failure(message) {
|
|
105
|
+
return { status: "failure", error: { message } };
|
|
106
|
+
}
|
|
107
|
+
// Rain's card list is the only `/api` route that maps a card's externalId to
|
|
108
|
+
// its accountId; walk its pages until the card turns up.
|
|
109
|
+
async function findCardAccountId(userId, cardExternalId) {
|
|
110
|
+
let cursor;
|
|
111
|
+
do {
|
|
112
|
+
const page = await baseClient
|
|
113
|
+
.get(`${RAIN_ENDPOINT}/api/cards/users/${userId}`, { params: { limit: USER_CARDS_PAGE_LIMIT, cursor } })
|
|
114
|
+
.then((res) => res.data);
|
|
115
|
+
if (page.status === "failure")
|
|
116
|
+
return page;
|
|
117
|
+
const card = page.data.data.find((c) => c.externalId === cardExternalId);
|
|
118
|
+
if (card) {
|
|
119
|
+
return card.accountId
|
|
120
|
+
? { status: "success", data: card.accountId }
|
|
121
|
+
: failure("Card has no payable account");
|
|
122
|
+
}
|
|
123
|
+
cursor = page.data.nextCursor;
|
|
124
|
+
} while (cursor);
|
|
125
|
+
return failure("Card not found");
|
|
126
|
+
}
|
|
127
|
+
// `/api/cards/:cardId/status` finds the card by its payable accountId, where
|
|
128
|
+
// the legacy `/card/status` took Rain's card externalId, and takes Rain's
|
|
129
|
+
// status values. Callers still pass the externalId and a VirtualCardStatus, so
|
|
130
|
+
// the wrapper resolves the accountId and maps the status first.
|
|
93
131
|
async function updateCardStatus({ userId, status, cardExternalId, }) {
|
|
132
|
+
const cardStatus = CARD_STATUS_BY_VIRTUAL_CARD_STATUS[status];
|
|
133
|
+
if (!cardStatus)
|
|
134
|
+
return failure(`Unsupported card status: ${status}`);
|
|
135
|
+
const accountId = await findCardAccountId(userId, cardExternalId);
|
|
136
|
+
if (accountId.status === "failure")
|
|
137
|
+
return accountId;
|
|
94
138
|
return baseClient
|
|
95
|
-
.
|
|
139
|
+
.patch(`${RAIN_ENDPOINT}/api/cards/${accountId.data}/status`, {
|
|
96
140
|
userId,
|
|
97
|
-
status,
|
|
98
|
-
cardExternalId,
|
|
141
|
+
status: cardStatus,
|
|
99
142
|
})
|
|
100
143
|
.then((res) => res.data);
|
|
101
144
|
}
|
package/lib/sigv4.js
CHANGED
|
@@ -4,13 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createSigV4Interceptor = createSigV4Interceptor;
|
|
7
|
-
const
|
|
7
|
+
const credential_provider_env_1 = require("@aws-sdk/credential-provider-env");
|
|
8
8
|
const hash_node_1 = require("@smithy/hash-node");
|
|
9
9
|
const signature_v4_1 = require("@smithy/signature-v4");
|
|
10
10
|
const axios_1 = __importDefault(require("axios"));
|
|
11
11
|
const config_1 = require("./config");
|
|
12
|
+
// Every consumer is a Lambda, where the runtime always injects the execution
|
|
13
|
+
// role's env credentials; fromEnv re-reads them per call so rotation is safe.
|
|
14
|
+
// The fromNodeProviderChain umbrella (@aws-sdk/credential-providers) drags in
|
|
15
|
+
// a credential-provider chain that esbuild cannot bundle in repos with older
|
|
16
|
+
// aws-sdk trees (nested @smithy/core exports) — that made deploy packaging
|
|
17
|
+
// hang silently (growth/verification, 2026-11-10).
|
|
12
18
|
// Cache the provider, not its result: the SDK owns credential refresh/expiry.
|
|
13
|
-
const credentials = (0,
|
|
19
|
+
const credentials = (0, credential_provider_env_1.fromEnv)();
|
|
14
20
|
const headerGroups = ["common", "delete", "get", "head", "post", "put", "patch"];
|
|
15
21
|
const signingHeaders = new Set([
|
|
16
22
|
"authorization",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spritz-finance/service-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.40.1",
|
|
4
4
|
"gitHead": "06f8e96b7b38c34df26a38da329331940675e4f8",
|
|
5
5
|
"description": "Service client",
|
|
6
6
|
"license": "ISC",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"gen:types": "graphql-codegen --config codegen.yml"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aws-sdk/credential-
|
|
28
|
+
"@aws-sdk/credential-provider-env": "^3.972.19",
|
|
29
29
|
"@smithy/hash-node": "^4.2.12",
|
|
30
30
|
"@smithy/signature-v4": "^5.3.12",
|
|
31
31
|
"@smithy/types": "^4.13.1",
|