@spritz-finance/service-client 0.3.12 → 0.3.14

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/index.d.ts CHANGED
@@ -21,3 +21,4 @@ export * from './unblock/types';
21
21
  export { LiabilitiesClient } from './liabilities/liabilitiesServiceClient';
22
22
  export * from './liabilities/types';
23
23
  export * from './utils';
24
+ export * from './types';
package/lib/index.js CHANGED
@@ -49,3 +49,4 @@ var liabilitiesServiceClient_1 = require("./liabilities/liabilitiesServiceClient
49
49
  Object.defineProperty(exports, "LiabilitiesClient", { enumerable: true, get: function () { return liabilitiesServiceClient_1.LiabilitiesClient; } });
50
50
  __exportStar(require("./liabilities/types"), exports);
51
51
  __exportStar(require("./utils"), exports);
52
+ __exportStar(require("./types"), exports);
package/lib/types.d.ts CHANGED
@@ -1,3 +1,19 @@
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> = (event: APIGatewayProxyEventWithDeserializedBody<U>) => Promise<T>;
16
+ export type ServiceClientResponse<Result, Body = unknown> = Handler<APIGatewayProxyEventWithDeserializedBody<Body>, ServiceClientResult<Result>>;
1
17
  export interface ApiError {
2
18
  message: string;
3
19
  code?: string;
package/lib/utils.d.ts CHANGED
@@ -1,3 +1,6 @@
1
- import { ApiFailure, ApiResponse, ApiSuccess } from './types';
1
+ import { ApiFailure, ApiResponse, ApiSuccess, ServiceClientResponse, ServiceClientResult } from './types';
2
2
  export declare function isApiSuccess<T>(response: ApiResponse<T>): response is ApiSuccess<T>;
3
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 CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isApiError = exports.isApiSuccess = void 0;
3
+ exports.parseApiError = exports.parseApiSuccess = exports.withServiceClientResponse = exports.isApiError = exports.isApiSuccess = void 0;
4
4
  function isApiSuccess(response) {
5
5
  return response.status === 'success';
6
6
  }
@@ -9,3 +9,39 @@ function isApiError(response) {
9
9
  return response.status === 'failure';
10
10
  }
11
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;
@@ -11,3 +11,20 @@ export type ExactInQuoteResponse = {
11
11
  swapData: string;
12
12
  paymentTokenDecimals: number;
13
13
  };
14
+ export type WalletTokenBalanceInput = {
15
+ network: string;
16
+ address: string;
17
+ };
18
+ export type TokenBalance = {
19
+ address: string;
20
+ walletAddress: string;
21
+ network: string;
22
+ decimals: number;
23
+ name: string;
24
+ symbol: string;
25
+ balance: number;
26
+ balanceRaw: string;
27
+ price: number;
28
+ balanceUSD: number;
29
+ tokenImageUrl: string;
30
+ };
@@ -1,3 +1,4 @@
1
1
  export * as Web3Client from './web3ServiceClient';
2
- import { ExactInQuoteInput, ExactInQuoteResponse } from './types';
2
+ import { ExactInQuoteInput, ExactInQuoteResponse, TokenBalance, WalletTokenBalanceInput } from './types';
3
3
  export declare function getExactInQuote(input: ExactInQuoteInput): Promise<ExactInQuoteResponse>;
4
+ export declare function getTokenBalances(input: WalletTokenBalanceInput): Promise<import("../types").ApiFailure | import("../types").ApiSuccess<TokenBalance[]>>;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getExactInQuote = exports.Web3Client = void 0;
26
+ exports.getTokenBalances = exports.getExactInQuote = exports.Web3Client = void 0;
27
27
  exports.Web3Client = __importStar(require("./web3ServiceClient"));
28
28
  const serviceClient_1 = require("../serviceClient");
29
29
  const WEB3_ENDPOINT = '/web3';
@@ -33,3 +33,9 @@ async function getExactInQuote(input) {
33
33
  .then((res) => res.data);
34
34
  }
35
35
  exports.getExactInQuote = getExactInQuote;
36
+ async function getTokenBalances(input) {
37
+ return serviceClient_1.baseClient
38
+ .post(`${WEB3_ENDPOINT}/token-balances`, input)
39
+ .then((res) => res.data);
40
+ }
41
+ exports.getTokenBalances = getTokenBalances;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spritz-finance/service-client",
3
- "version": "0.3.12",
3
+ "version": "0.3.14",
4
4
  "description": "Service client",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -32,6 +32,7 @@
32
32
  "@graphql-codegen/typescript": "^4.0.0",
33
33
  "@spritz-finance/config": "^0.1.6",
34
34
  "@spritz-finance/logger": "^0.2.1",
35
+ "aws-lambda": "^1.0.7",
35
36
  "jest": "^29.6.4",
36
37
  "ts-jest": "29.1.1",
37
38
  "typescript": "^5.2.2"