@spritz-finance/service-client 0.2.93 → 0.2.95
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/config.js +13 -13
- package/lib/liabilitiesServiceClient.d.ts +1 -0
- package/lib/liabilitiesServiceClient.js +5 -0
- package/lib/onrampServiceClient.d.ts +3 -0
- package/lib/onrampServiceClient.js +8 -0
- package/lib/types.d.ts +29 -0
- package/lib/types.js +2 -0
- package/lib/utils.d.ts +6 -0
- package/lib/utils.js +47 -0
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -5,19 +5,19 @@ exports.config = void 0;
|
|
|
5
5
|
const config_1 = require("@spritz-finance/config");
|
|
6
6
|
const envConfigs = {
|
|
7
7
|
base: {
|
|
8
|
-
env: (_b = (_a = process.env.STAGE) !== null && _a !== void 0 ? _a : process.env.NODE_ENV) !== null && _b !== void 0 ? _b : '
|
|
9
|
-
authEndpoint: 'https://auth-
|
|
10
|
-
graphEndpoint: 'https://api-
|
|
11
|
-
verificationServiceEndpoint: 'https://api-
|
|
12
|
-
transactionsServiceEndpoint: 'https://api-
|
|
13
|
-
usersServiceEndpoint: 'https://api-
|
|
14
|
-
liabilitiesServiceEndpoint: 'https://api-
|
|
15
|
-
payableAccountsServiceEndpoint: 'https://api-
|
|
16
|
-
growthServiceEndpoint: 'https://api-
|
|
17
|
-
exchangeRatesServiceEndpoint: 'https://api-
|
|
18
|
-
web3ServiceEndpoint: 'https://api-
|
|
19
|
-
unblockServiceEndpoint: 'https://api-
|
|
20
|
-
onrampServiceEndpoint: 'https://api-
|
|
8
|
+
env: (_b = (_a = process.env.STAGE) !== null && _a !== void 0 ? _a : process.env.NODE_ENV) !== null && _b !== void 0 ? _b : 'dev',
|
|
9
|
+
authEndpoint: 'https://auth-dev.spritz.finance/oauth2/token',
|
|
10
|
+
graphEndpoint: 'https://api-dev.spritz.finance/graphql',
|
|
11
|
+
verificationServiceEndpoint: 'https://api-dev.spritz.finance/verification',
|
|
12
|
+
transactionsServiceEndpoint: 'https://api-dev.spritz.finance/transactions',
|
|
13
|
+
usersServiceEndpoint: 'https://api-dev.spritz.finance/users',
|
|
14
|
+
liabilitiesServiceEndpoint: 'https://api-dev.spritz.finance/liabilities',
|
|
15
|
+
payableAccountsServiceEndpoint: 'https://api-dev.spritz.finance/payable-accounts',
|
|
16
|
+
growthServiceEndpoint: 'https://api-dev.spritz.finance/growth',
|
|
17
|
+
exchangeRatesServiceEndpoint: 'https://api-dev.spritz.finance/exchange-rates',
|
|
18
|
+
web3ServiceEndpoint: 'https://api-dev.spritz.finance/web3',
|
|
19
|
+
unblockServiceEndpoint: 'https://api-dev.spritz.finance/unblock',
|
|
20
|
+
onrampServiceEndpoint: 'https://api-dev.spritz.finance/bridge',
|
|
21
21
|
},
|
|
22
22
|
test: {
|
|
23
23
|
env: 'staging',
|
|
@@ -238,6 +238,7 @@ export declare class LiabilitiesServiceClient {
|
|
|
238
238
|
createMethodFiEntity(args: CreateEntityParams): Promise<MethodFiEntity>;
|
|
239
239
|
getMethodFiEntity(userId: string): Promise<MethodFiEntity>;
|
|
240
240
|
createCheckbookUser(args: CreateCheckbookUserParams): Promise<CheckbookUser>;
|
|
241
|
+
upsertCheckbookUser(args: CreateCheckbookUserParams): Promise<import("./types").ApiFailure | import("./types").ApiSuccess<CheckbookUser>>;
|
|
241
242
|
getCheckbookUser(userId: string): Promise<CheckbookUser>;
|
|
242
243
|
createCheckbookVirtualCard(userId: string): Promise<CheckbookCardResponse>;
|
|
243
244
|
createCheckbookDebitCard(input: CreateDebitCardInput): Promise<CheckbookDebitCardResponse>;
|
|
@@ -58,6 +58,11 @@ class LiabilitiesServiceClient {
|
|
|
58
58
|
.post(`/checkbook/user`, args)
|
|
59
59
|
.then((res) => res.data);
|
|
60
60
|
}
|
|
61
|
+
async upsertCheckbookUser(args) {
|
|
62
|
+
return this.client
|
|
63
|
+
.post(`/checkbook/user/upsert`, args)
|
|
64
|
+
.then((res) => res.data);
|
|
65
|
+
}
|
|
61
66
|
async getCheckbookUser(userId) {
|
|
62
67
|
return this.client
|
|
63
68
|
.get(`/checkbook/user/${userId}`)
|
|
@@ -22,4 +22,7 @@ export declare class OnrampServiceClient {
|
|
|
22
22
|
constructor();
|
|
23
23
|
syncTransfer(input: SyncOnrampTransferInput): Promise<OnRampPayment>;
|
|
24
24
|
getUserCompletedPayments(userId: string): Promise<OnRampPayment[]>;
|
|
25
|
+
createBusinessUser(userId: string, businessName: string): Promise<{
|
|
26
|
+
success: boolean;
|
|
27
|
+
}>;
|
|
25
28
|
}
|
|
@@ -19,5 +19,13 @@ class OnrampServiceClient {
|
|
|
19
19
|
.get(`/payments/user/${userId}/completed`)
|
|
20
20
|
.then((res) => res.data);
|
|
21
21
|
}
|
|
22
|
+
async createBusinessUser(userId, businessName) {
|
|
23
|
+
return this.client
|
|
24
|
+
.post(`/business-user`, {
|
|
25
|
+
userId,
|
|
26
|
+
businessName,
|
|
27
|
+
})
|
|
28
|
+
.then((res) => res.data);
|
|
29
|
+
}
|
|
22
30
|
}
|
|
23
31
|
exports.OnrampServiceClient = OnrampServiceClient;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { APIGatewayProxyEvent, APIGatewayProxyResult, Handler } from 'aws-lambda';
|
|
2
|
+
export interface PaginationResult<T> {
|
|
3
|
+
items: T[];
|
|
4
|
+
totalCount: number;
|
|
5
|
+
currentPage: number;
|
|
6
|
+
pages: number;
|
|
7
|
+
}
|
|
8
|
+
export interface APIGatewayProxyEventWithDeserializedBody<B = unknown, P = unknown> extends Omit<APIGatewayProxyEvent, 'body' | 'pathParameters'> {
|
|
9
|
+
body: B;
|
|
10
|
+
pathParameters: P;
|
|
11
|
+
}
|
|
12
|
+
export interface ServiceClientResult<Result> extends Omit<APIGatewayProxyResult, 'body'> {
|
|
13
|
+
body: ApiResponse<Result>;
|
|
14
|
+
}
|
|
15
|
+
export type ServiceClientHandler<T, U = {}, P = {}> = (event: APIGatewayProxyEventWithDeserializedBody<U, P>) => Promise<T>;
|
|
16
|
+
export type ServiceClientResponse<Result, Body = unknown> = Handler<APIGatewayProxyEventWithDeserializedBody<Body>, ServiceClientResult<Result>>;
|
|
17
|
+
export interface ApiError {
|
|
18
|
+
message: string;
|
|
19
|
+
code?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ApiSuccess<T> {
|
|
22
|
+
status: 'success';
|
|
23
|
+
data: T;
|
|
24
|
+
}
|
|
25
|
+
export interface ApiFailure {
|
|
26
|
+
status: 'failure';
|
|
27
|
+
error: ApiError;
|
|
28
|
+
}
|
|
29
|
+
export type ApiResponse<T> = ApiSuccess<T> | ApiFailure;
|
package/lib/types.js
ADDED
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ApiFailure, ApiResponse, ApiSuccess, ServiceClientResponse, ServiceClientResult } from './types';
|
|
2
|
+
export declare function isApiSuccess<T>(response: ApiResponse<T>): response is ApiSuccess<T>;
|
|
3
|
+
export declare function isApiError<T>(response: ApiResponse<T>): response is ApiFailure;
|
|
4
|
+
export declare function withServiceClientResponse<T>(handler: (event: any) => Promise<T>, fallbackErrorMessage?: string): ServiceClientResponse<T>;
|
|
5
|
+
export declare function parseApiSuccess<Result>(data: Result): ServiceClientResult<Result>;
|
|
6
|
+
export declare function parseApiError(error: unknown, fallbackMessage?: string): ServiceClientResult<never>;
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseApiError = exports.parseApiSuccess = exports.withServiceClientResponse = exports.isApiError = exports.isApiSuccess = void 0;
|
|
4
|
+
function isApiSuccess(response) {
|
|
5
|
+
return response.status === 'success';
|
|
6
|
+
}
|
|
7
|
+
exports.isApiSuccess = isApiSuccess;
|
|
8
|
+
function isApiError(response) {
|
|
9
|
+
return response.status === 'failure';
|
|
10
|
+
}
|
|
11
|
+
exports.isApiError = isApiError;
|
|
12
|
+
function withServiceClientResponse(handler, fallbackErrorMessage) {
|
|
13
|
+
return async (event) => {
|
|
14
|
+
try {
|
|
15
|
+
const result = await handler(event);
|
|
16
|
+
return parseApiSuccess(result);
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
return parseApiError(e, fallbackErrorMessage);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.withServiceClientResponse = withServiceClientResponse;
|
|
24
|
+
function parseApiSuccess(data) {
|
|
25
|
+
return {
|
|
26
|
+
statusCode: 200,
|
|
27
|
+
body: {
|
|
28
|
+
status: 'success',
|
|
29
|
+
data,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.parseApiSuccess = parseApiSuccess;
|
|
34
|
+
function parseApiError(error, fallbackMessage) {
|
|
35
|
+
return {
|
|
36
|
+
statusCode: 200,
|
|
37
|
+
body: {
|
|
38
|
+
status: 'failure',
|
|
39
|
+
error: {
|
|
40
|
+
message: error instanceof Error
|
|
41
|
+
? error.message
|
|
42
|
+
: fallbackMessage !== null && fallbackMessage !== void 0 ? fallbackMessage : 'An unknown error occurred',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.parseApiError = parseApiError;
|