@gala-chain/launchpad-sdk 3.5.3 → 3.6.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/CHANGELOG.md +70 -0
- package/README.md +23 -1
- package/dist/constants/endpoints.d.ts +38 -0
- package/dist/constants/endpoints.d.ts.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/schemas/validators.d.ts +130 -32
- package/dist/schemas/validators.d.ts.map +1 -1
- package/dist/services/BundleService.d.ts.map +1 -1
- package/dist/services/CommentService.d.ts +71 -0
- package/dist/services/CommentService.d.ts.map +1 -0
- package/dist/services/FaucetService.d.ts +55 -0
- package/dist/services/FaucetService.d.ts.map +1 -0
- package/dist/services/ImageService.d.ts +81 -0
- package/dist/services/ImageService.d.ts.map +1 -0
- package/dist/services/LaunchpadService.d.ts +57 -298
- package/dist/services/LaunchpadService.d.ts.map +1 -1
- package/dist/services/PoolService.d.ts +114 -0
- package/dist/services/PoolService.d.ts.map +1 -0
- package/dist/services/TradeService.d.ts +55 -0
- package/dist/services/TradeService.d.ts.map +1 -0
- package/dist/services/UserService.d.ts +121 -0
- package/dist/services/UserService.d.ts.map +1 -0
- package/dist/utils/error-factories.d.ts +95 -0
- package/dist/utils/error-factories.d.ts.map +1 -0
- package/dist/utils/query-params.d.ts +98 -0
- package/dist/utils/query-params.d.ts.map +1 -0
- package/dist/utils/response-handlers.d.ts +96 -0
- package/dist/utils/response-handlers.d.ts.map +1 -0
- package/dist/utils/response-normalizers.d.ts +133 -0
- package/dist/utils/response-normalizers.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trade Service
|
|
3
|
+
*
|
|
4
|
+
* Handles all trade-related operations including trade history queries.
|
|
5
|
+
*
|
|
6
|
+
* @category Services
|
|
7
|
+
* @since 3.6.0
|
|
8
|
+
*/
|
|
9
|
+
import { HttpClient } from '../utils/http';
|
|
10
|
+
import { TradesResult } from '../types/trade.dto';
|
|
11
|
+
import { FetchTradesOptions } from '../types/options.dto';
|
|
12
|
+
/**
|
|
13
|
+
* Trade Service Class
|
|
14
|
+
*
|
|
15
|
+
* Provides methods for:
|
|
16
|
+
* - Fetching trade history with pagination
|
|
17
|
+
* - Filtering trades by token, user, type, date range
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const tradeService = new TradeService(httpClient);
|
|
22
|
+
*
|
|
23
|
+
* // Get first page of trades for a token
|
|
24
|
+
* const trades = await tradeService.fetchTrades({ tokenName: "dragnrkti" });
|
|
25
|
+
*
|
|
26
|
+
* // Get specific page with custom limit
|
|
27
|
+
* const moreTrades = await tradeService.fetchTrades({
|
|
28
|
+
* tokenName: "dragnrkti",
|
|
29
|
+
* page: 2,
|
|
30
|
+
* limit: 20
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare class TradeService {
|
|
35
|
+
private readonly http;
|
|
36
|
+
constructor(http: HttpClient);
|
|
37
|
+
/**
|
|
38
|
+
* Gets trades for a token by its tokenName with pagination
|
|
39
|
+
*
|
|
40
|
+
* This method provides a clean, intuitive API for fetching token trades
|
|
41
|
+
* using the token name. Follows the same pattern as CommentAPI.
|
|
42
|
+
*
|
|
43
|
+
* @param options Trade fetching options
|
|
44
|
+
* @returns Promise<TradesResult> Clean trades with full pagination
|
|
45
|
+
* @throws ValidationError if token name is invalid or not found
|
|
46
|
+
*/
|
|
47
|
+
fetchTrades(options: FetchTradesOptions): Promise<TradesResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Validates pagination parameters
|
|
50
|
+
*
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
private validateTradePagination;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=TradeService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TradeService.d.ts","sourceRoot":"","sources":["../../src/services/TradeService.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,OAAO,EAEL,YAAY,EAEb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,kBAAkB,EAAwB,MAAM,sBAAsB,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,YAAY;IACX,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;;;;;;;;OASG;IACG,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IA2DrE;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CAyBhC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Service
|
|
3
|
+
*
|
|
4
|
+
* Handles all user-related operations including profile management,
|
|
5
|
+
* token lists, and user data queries.
|
|
6
|
+
*
|
|
7
|
+
* @category Services
|
|
8
|
+
* @since 3.6.0
|
|
9
|
+
*/
|
|
10
|
+
import { HttpClient } from '../utils/http';
|
|
11
|
+
import { GetTokenListOptions, UserTokenListResult, UpdateProfileData, UploadProfileImageOptions } from '../types/user.dto';
|
|
12
|
+
/**
|
|
13
|
+
* User Service Class
|
|
14
|
+
*
|
|
15
|
+
* Provides methods for:
|
|
16
|
+
* - Profile management (fetch, update)
|
|
17
|
+
* - Profile image uploads
|
|
18
|
+
* - Token list queries (created, held)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const userService = new UserService(httpClient);
|
|
23
|
+
*
|
|
24
|
+
* // Get user profile
|
|
25
|
+
* const profile = await userService.fetchProfile();
|
|
26
|
+
*
|
|
27
|
+
* // Update profile
|
|
28
|
+
* await userService.updateProfile({
|
|
29
|
+
* profileImage: "https://example.com/avatar.jpg",
|
|
30
|
+
* fullName: "John Doe",
|
|
31
|
+
* address: "eth|1234..."
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class UserService {
|
|
36
|
+
private readonly http;
|
|
37
|
+
constructor(http: HttpClient);
|
|
38
|
+
/**
|
|
39
|
+
* Fetches user profile information
|
|
40
|
+
*
|
|
41
|
+
* @param address Optional wallet address (defaults to SDK wallet address)
|
|
42
|
+
* @returns Promise<any> User profile information
|
|
43
|
+
* @throws ValidationError if input validation fails
|
|
44
|
+
*/
|
|
45
|
+
fetchProfile(address?: string): Promise<any>;
|
|
46
|
+
/**
|
|
47
|
+
* Updates user profile information
|
|
48
|
+
*
|
|
49
|
+
* **Smart Image Preservation**: If profileImage is empty or not provided,
|
|
50
|
+
* the method automatically fetches and preserves the existing profile image
|
|
51
|
+
* to prevent accidental image loss.
|
|
52
|
+
*
|
|
53
|
+
* @param data Profile update data
|
|
54
|
+
* @returns Promise<void> No return data - throws on failure
|
|
55
|
+
* @throws ValidationError if input validation fails
|
|
56
|
+
* @throws Error if profile update fails
|
|
57
|
+
*/
|
|
58
|
+
updateProfile(data: UpdateProfileData): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Uploads a profile image and returns the image URL
|
|
61
|
+
*
|
|
62
|
+
* @param options Profile image upload options
|
|
63
|
+
* @returns Promise<string> Clean image URL
|
|
64
|
+
* @throws ValidationError if input validation fails
|
|
65
|
+
* @throws Error if upload fails
|
|
66
|
+
*/
|
|
67
|
+
uploadProfileImage(options: UploadProfileImageOptions): Promise<string>;
|
|
68
|
+
/**
|
|
69
|
+
* Fetches user token list with optional filtering and pagination
|
|
70
|
+
*
|
|
71
|
+
* @param options Filtering and pagination options
|
|
72
|
+
* @returns Promise<UserTokenListResult> Clean token list with proper types
|
|
73
|
+
* @throws Error if request fails
|
|
74
|
+
*/
|
|
75
|
+
fetchTokenList(options: GetTokenListOptions): Promise<UserTokenListResult>;
|
|
76
|
+
/**
|
|
77
|
+
* Fetches tokens held by user (balances)
|
|
78
|
+
*
|
|
79
|
+
* @param options Token held filtering options (address is optional)
|
|
80
|
+
* @returns Promise<UserTokenListResult> Clean tokens held with full pagination
|
|
81
|
+
* @throws ValidationError if input validation fails
|
|
82
|
+
*/
|
|
83
|
+
fetchTokensHeld(options: GetTokenListOptions): Promise<UserTokenListResult>;
|
|
84
|
+
/**
|
|
85
|
+
* Fetches tokens created by user
|
|
86
|
+
*
|
|
87
|
+
* @param options Options including pagination
|
|
88
|
+
* @returns Promise<UserTokenListResult> Tokens created by the user
|
|
89
|
+
*/
|
|
90
|
+
fetchTokensCreated(options?: {
|
|
91
|
+
page?: number;
|
|
92
|
+
limit?: number;
|
|
93
|
+
search?: string;
|
|
94
|
+
tokenName?: string;
|
|
95
|
+
}): Promise<UserTokenListResult>;
|
|
96
|
+
/**
|
|
97
|
+
* Validates get token list options
|
|
98
|
+
*
|
|
99
|
+
* @private
|
|
100
|
+
*/
|
|
101
|
+
private validateGetTokenListOptions;
|
|
102
|
+
/**
|
|
103
|
+
* Validates user pagination parameters
|
|
104
|
+
*
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
private validateUserPagination;
|
|
108
|
+
/**
|
|
109
|
+
* Validates update profile data
|
|
110
|
+
*
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
113
|
+
private validateUpdateProfileData;
|
|
114
|
+
/**
|
|
115
|
+
* Validates upload profile image options
|
|
116
|
+
*
|
|
117
|
+
* @private
|
|
118
|
+
*/
|
|
119
|
+
private validateUploadProfileImageOptions;
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=UserService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UserService.d.ts","sourceRoot":"","sources":["../../src/services/UserService.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAM3C,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EAEjB,yBAAyB,EAO1B,MAAM,mBAAmB,CAAC;AAO3B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,UAAU;IAE7C;;;;;;OAMG;IACG,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAmBlD;;;;;;;;;;;OAWG;IACG,aAAa,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiD3D;;;;;;;OAOG;IACG,kBAAkB,CACtB,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,MAAM,CAAC;IAgElB;;;;;;OAMG;IACG,cAAc,CAClB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,mBAAmB,CAAC;IA0C/B;;;;;;OAMG;IACG,eAAe,CACnB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,mBAAmB,CAAC;IAyC/B;;;;;OAKG;IACG,kBAAkB,CACtB,OAAO,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAO,GACnF,OAAO,CAAC,mBAAmB,CAAC;IAsB/B;;;;OAIG;IACH,OAAO,CAAC,2BAA2B;IAuCnC;;;;OAIG;IACH,OAAO,CAAC,sBAAsB;IA0B9B;;;;OAIG;IACH,OAAO,CAAC,yBAAyB;IAkBjC;;;;OAIG;IACH,OAAO,CAAC,iCAAiC;CAW1C"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Factories
|
|
3
|
+
*
|
|
4
|
+
* Standardized error message generators for common validation failures.
|
|
5
|
+
* Eliminates duplicate error messages across services.
|
|
6
|
+
*
|
|
7
|
+
* @category Utilities
|
|
8
|
+
* @since 3.6.1
|
|
9
|
+
*/
|
|
10
|
+
import { ValidationError } from './validation';
|
|
11
|
+
/**
|
|
12
|
+
* Creates a standardized "token not found" validation error
|
|
13
|
+
*
|
|
14
|
+
* This factory eliminates duplicate token error messages found across
|
|
15
|
+
* multiple service files. It provides a single source of truth for
|
|
16
|
+
* token resolution failures.
|
|
17
|
+
*
|
|
18
|
+
* ## Replaces Patterns
|
|
19
|
+
*
|
|
20
|
+
* This function replaces 8+ instances of duplicate error creation:
|
|
21
|
+
*
|
|
22
|
+
* ### Before (Duplicate Pattern Across Services):
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // CommentService.ts (×2)
|
|
25
|
+
* throw new ValidationError(
|
|
26
|
+
* `Token "${tokenName}" not found. Please verify the token name is correct.`,
|
|
27
|
+
* 'tokenName',
|
|
28
|
+
* 'TOKEN_NOT_FOUND'
|
|
29
|
+
* );
|
|
30
|
+
*
|
|
31
|
+
* // BundleService.ts (×2)
|
|
32
|
+
* throw new ValidationError(
|
|
33
|
+
* `Token "${tokenName}" not found. Please verify the token name is correct.`,
|
|
34
|
+
* 'tokenName',
|
|
35
|
+
* 'TOKEN_NOT_FOUND'
|
|
36
|
+
* );
|
|
37
|
+
*
|
|
38
|
+
* // GalaChainService.ts
|
|
39
|
+
* throw new ValidationError(
|
|
40
|
+
* `Token '${tokenName}' not found or not available for transfer`,
|
|
41
|
+
* 'tokenName',
|
|
42
|
+
* 'TOKEN_NOT_FOUND'
|
|
43
|
+
* );
|
|
44
|
+
*
|
|
45
|
+
* // TokenResolverService.ts
|
|
46
|
+
* throw new ValidationError(
|
|
47
|
+
* `Token "${tokenName}" not found. Please verify the token name is correct.`,
|
|
48
|
+
* 'tokenName',
|
|
49
|
+
* 'TOKEN_NOT_FOUND'
|
|
50
|
+
* );
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* ### After (Single Source of Truth):
|
|
54
|
+
* ```typescript
|
|
55
|
+
* // CommentService.ts
|
|
56
|
+
* throw createTokenNotFoundError(tokenName);
|
|
57
|
+
*
|
|
58
|
+
* // BundleService.ts
|
|
59
|
+
* throw createTokenNotFoundError(tokenName);
|
|
60
|
+
*
|
|
61
|
+
* // GalaChainService.ts
|
|
62
|
+
* throw createTokenNotFoundError(tokenName, 'transfer');
|
|
63
|
+
*
|
|
64
|
+
* // TokenResolverService.ts
|
|
65
|
+
* throw createTokenNotFoundError(tokenName);
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* @param tokenName The token name that was not found
|
|
69
|
+
* @param context Optional context for error message customization
|
|
70
|
+
* @returns ValidationError with standardized message
|
|
71
|
+
*
|
|
72
|
+
* @example Basic usage
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const tokenName = 'mytoken';
|
|
75
|
+
* const vaultAddress = await resolveTokenName(tokenName);
|
|
76
|
+
* if (!vaultAddress) {
|
|
77
|
+
* throw createTokenNotFoundError(tokenName);
|
|
78
|
+
* }
|
|
79
|
+
* // Throws: ValidationError with message:
|
|
80
|
+
* // "Token "mytoken" not found. Please verify the token name is correct."
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @example With transfer context
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const tokenName = 'mytoken';
|
|
86
|
+
* const tokenInfo = await getTokenForTransfer(tokenName);
|
|
87
|
+
* if (!tokenInfo) {
|
|
88
|
+
* throw createTokenNotFoundError(tokenName, 'transfer');
|
|
89
|
+
* }
|
|
90
|
+
* // Throws: ValidationError with message:
|
|
91
|
+
* // "Token 'mytoken' not found or not available for transfer"
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function createTokenNotFoundError(tokenName: string, context?: 'transfer'): ValidationError;
|
|
95
|
+
//# sourceMappingURL=error-factories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-factories.d.ts","sourceRoot":"","sources":["../../src/utils/error-factories.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkFG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,UAAU,GACnB,eAAe,CAOjB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Parameter Building Utilities
|
|
3
|
+
*
|
|
4
|
+
* Unified utilities for building backend query parameters.
|
|
5
|
+
* Replaces multiple duplicate query building methods with a single,
|
|
6
|
+
* type-safe, reusable utility.
|
|
7
|
+
*
|
|
8
|
+
* @category Utilities
|
|
9
|
+
* @since 3.6.0
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for field transformations
|
|
13
|
+
*/
|
|
14
|
+
export interface QueryParamConfig<T> {
|
|
15
|
+
/** Fields that should be converted to strings */
|
|
16
|
+
stringifyFields?: (keyof T)[];
|
|
17
|
+
/** Fields that should be excluded if undefined/empty */
|
|
18
|
+
optionalFields?: (keyof T)[];
|
|
19
|
+
/** Custom field name mappings (source -> backend) */
|
|
20
|
+
fieldMappings?: Partial<Record<keyof T, string>>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Builds backend query parameters from typed options object
|
|
24
|
+
*
|
|
25
|
+
* This utility consolidates the logic from multiple query building methods:
|
|
26
|
+
* - buildGetCommentsQueryParams
|
|
27
|
+
* - buildTradeQueryParams
|
|
28
|
+
* - buildTokenListQueryParams
|
|
29
|
+
* - buildTokenHoldQueryParams
|
|
30
|
+
*
|
|
31
|
+
* @template T The type of the input options object
|
|
32
|
+
* @param options Input options to convert to query parameters
|
|
33
|
+
* @param config Configuration for field transformations
|
|
34
|
+
* @returns Query parameters ready for backend API
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // Simple pagination
|
|
39
|
+
* const params = buildBackendQueryParams(
|
|
40
|
+
* { page: 1, limit: 10 },
|
|
41
|
+
* { stringifyFields: ['page', 'limit'] }
|
|
42
|
+
* );
|
|
43
|
+
* // Result: { page: '1', limit: '10' }
|
|
44
|
+
*
|
|
45
|
+
* // With optional fields
|
|
46
|
+
* const params = buildBackendQueryParams(
|
|
47
|
+
* { page: 1, limit: 10, search: 'test', tokenName: undefined },
|
|
48
|
+
* {
|
|
49
|
+
* stringifyFields: ['page', 'limit'],
|
|
50
|
+
* optionalFields: ['search', 'tokenName']
|
|
51
|
+
* }
|
|
52
|
+
* );
|
|
53
|
+
* // Result: { page: '1', limit: '10', search: 'test' }
|
|
54
|
+
*
|
|
55
|
+
* // With field mappings
|
|
56
|
+
* const params = buildBackendQueryParams(
|
|
57
|
+
* { walletAddress: 'eth|123', amount: '100' },
|
|
58
|
+
* { fieldMappings: { walletAddress: 'userAddress' } }
|
|
59
|
+
* );
|
|
60
|
+
* // Result: { userAddress: 'eth|123', amount: '100' }
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function buildBackendQueryParams<T extends Record<string, any>>(options: T, config?: QueryParamConfig<T>): Record<string, any>;
|
|
64
|
+
/**
|
|
65
|
+
* Builds pagination query parameters (common pattern)
|
|
66
|
+
*
|
|
67
|
+
* Convenience function for the most common use case: pagination with page/limit.
|
|
68
|
+
*
|
|
69
|
+
* @param page Page number
|
|
70
|
+
* @param limit Items per page
|
|
71
|
+
* @returns Query parameters with stringified page and limit
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const params = buildPaginationParams(2, 20);
|
|
76
|
+
* // Result: { page: '2', limit: '20' }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function buildPaginationParams(page: number, limit: number): Record<string, string>;
|
|
80
|
+
/**
|
|
81
|
+
* Builds token query parameters with pagination
|
|
82
|
+
*
|
|
83
|
+
* Common pattern for token-related endpoints that support
|
|
84
|
+
* pagination plus optional filters.
|
|
85
|
+
*
|
|
86
|
+
* @param tokenName Token name to query
|
|
87
|
+
* @param page Page number
|
|
88
|
+
* @param limit Items per page
|
|
89
|
+
* @returns Query parameters ready for backend API
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const params = buildTokenQueryParams('mytoken', 1, 10);
|
|
94
|
+
* // Result: { tokenName: 'mytoken', page: '1', limit: '10' }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function buildTokenQueryParams(tokenName: string, page: number, limit: number): Record<string, any>;
|
|
98
|
+
//# sourceMappingURL=query-params.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-params.d.ts","sourceRoot":"","sources":["../../src/utils/query-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,iDAAiD;IACjD,eAAe,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;IAC9B,wDAAwD;IACxD,cAAc,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;IAC7B,qDAAqD;IACrD,aAAa,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;CAClD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnE,OAAO,EAAE,CAAC,EACV,MAAM,GAAE,gBAAgB,CAAC,CAAC,CAAM,GAC/B,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAyCrB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACZ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAKxB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,GACZ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAKrB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response Handlers
|
|
3
|
+
*
|
|
4
|
+
* Standardized response validation and error handling for API calls.
|
|
5
|
+
* Eliminates duplicate error checking patterns across services.
|
|
6
|
+
*
|
|
7
|
+
* @category Utilities
|
|
8
|
+
* @since 3.6.1
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Standard backend response structure
|
|
12
|
+
*/
|
|
13
|
+
interface BackendResponse<T = unknown> {
|
|
14
|
+
status: number;
|
|
15
|
+
error: boolean;
|
|
16
|
+
message?: string;
|
|
17
|
+
data?: T;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Asserts that a backend response is successful, throwing an error if not.
|
|
21
|
+
*
|
|
22
|
+
* This utility eliminates the duplicate error checking pattern found across
|
|
23
|
+
* all service files. It provides a single source of truth for response validation.
|
|
24
|
+
*
|
|
25
|
+
* ## Error Checking Logic
|
|
26
|
+
*
|
|
27
|
+
* A response is considered **failed** if any of these conditions are true:
|
|
28
|
+
* 1. `response.error === true` - Explicit error flag from backend
|
|
29
|
+
* 2. `response.status !== 200` - Non-success HTTP status code
|
|
30
|
+
* 3. `requireData === true && !response.data` - Data is required but missing
|
|
31
|
+
*
|
|
32
|
+
* ## Replaces Patterns
|
|
33
|
+
*
|
|
34
|
+
* This function replaces 18+ instances of duplicate error checking:
|
|
35
|
+
*
|
|
36
|
+
* ### Before (Duplicate Pattern in Every Service):
|
|
37
|
+
* ```typescript
|
|
38
|
+
* // PoolService.ts
|
|
39
|
+
* if (response.error === true || response.status !== 200 || !response.data) {
|
|
40
|
+
* throw new Error(response.message || 'Failed to fetch pools');
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* // CommentService.ts
|
|
44
|
+
* if (response.error) {
|
|
45
|
+
* throw new Error(response.message || 'Failed to post comment');
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* // FaucetService.ts
|
|
49
|
+
* if (response.error || response.status !== 200) {
|
|
50
|
+
* throw new Error(response.message || 'Faucet transfer failed');
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* // ... 15 more duplicate instances across different services
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* ### After (Single Source of Truth):
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // PoolService.ts
|
|
59
|
+
* assertResponseSuccess(response, 'Failed to fetch pools', true);
|
|
60
|
+
*
|
|
61
|
+
* // CommentService.ts
|
|
62
|
+
* assertResponseSuccess(response, 'Failed to post comment');
|
|
63
|
+
*
|
|
64
|
+
* // FaucetService.ts
|
|
65
|
+
* assertResponseSuccess(response, 'Faucet transfer failed');
|
|
66
|
+
*
|
|
67
|
+
* // All services use the same consistent error handling
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @template T The expected type of response.data
|
|
71
|
+
* @param response Backend response object to validate
|
|
72
|
+
* @param defaultErrorMessage Default error message if response.message is unavailable
|
|
73
|
+
* @param requireData Whether to require response.data to be present (default: false)
|
|
74
|
+
* @throws Error if the response indicates failure
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* // Basic usage - check status and error flag only
|
|
79
|
+
* const response = await http.post('/api/endpoint', data);
|
|
80
|
+
* assertResponseSuccess(response, 'Operation failed');
|
|
81
|
+
* // No return value - throws if response is invalid
|
|
82
|
+
*
|
|
83
|
+
* // Require data to be present
|
|
84
|
+
* const response = await http.get('/api/pools');
|
|
85
|
+
* assertResponseSuccess(response, 'Failed to fetch pools', true);
|
|
86
|
+
* // Throws if response.error, status !== 200, OR !response.data
|
|
87
|
+
*
|
|
88
|
+
* // Custom error message context
|
|
89
|
+
* assertResponseSuccess(response, 'Token creation failed');
|
|
90
|
+
* assertResponseSuccess(response, 'Profile update failed');
|
|
91
|
+
* assertResponseSuccess(response, 'Comment submission failed');
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function assertResponseSuccess<T = unknown>(response: BackendResponse<T>, defaultErrorMessage: string, requireData?: boolean): void;
|
|
95
|
+
export {};
|
|
96
|
+
//# sourceMappingURL=response-handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-handlers.d.ts","sourceRoot":"","sources":["../../src/utils/response-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,UAAU,eAAe,CAAC,CAAC,GAAG,OAAO;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;CACV;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,wBAAgB,qBAAqB,CAAC,CAAC,GAAG,OAAO,EAC/C,QAAQ,EAAE,eAAe,CAAC,CAAC,CAAC,EAC5B,mBAAmB,EAAE,MAAM,EAC3B,WAAW,GAAE,OAAe,GAC3B,IAAI,CAQN"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response Normalization Utilities
|
|
3
|
+
*
|
|
4
|
+
* Utilities for normalizing backend API responses into consistent formats.
|
|
5
|
+
* Handles the various response structure variations from the backend API,
|
|
6
|
+
* reducing complexity in service methods.
|
|
7
|
+
*
|
|
8
|
+
* @category Utilities
|
|
9
|
+
* @since 3.6.0
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Normalizes pool response data into consistent array format
|
|
13
|
+
*
|
|
14
|
+
* The backend API returns pools in different formats depending on the query:
|
|
15
|
+
* - Single token: { tokens: {pool data} }
|
|
16
|
+
* - Multiple tokens: { tokens: [{pool data}] }
|
|
17
|
+
* - Legacy format: { pools: [{pool data}] }
|
|
18
|
+
*
|
|
19
|
+
* This normalizer ensures we always get an array of pools with proper Date objects.
|
|
20
|
+
*
|
|
21
|
+
* @param data Raw response data from backend
|
|
22
|
+
* @returns Normalized array of pools with Date objects
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Single token response
|
|
27
|
+
* const normalized = normalizePoolResponse({
|
|
28
|
+
* tokens: { id: 1, created_at: '2024-01-01' }
|
|
29
|
+
* });
|
|
30
|
+
* // Result: [{ id: 1, createdAt: Date('2024-01-01') }]
|
|
31
|
+
*
|
|
32
|
+
* // Multiple tokens response
|
|
33
|
+
* const normalized = normalizePoolResponse({
|
|
34
|
+
* tokens: [{ id: 1, created_at: '2024-01-01' }, { id: 2, created_at: '2024-01-02' }]
|
|
35
|
+
* });
|
|
36
|
+
* // Result: [{ id: 1, createdAt: Date('2024-01-01') }, { id: 2, createdAt: Date('2024-01-02') }]
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function normalizePoolResponse(data: any): any[];
|
|
40
|
+
/**
|
|
41
|
+
* Normalizes trade response data into consistent array format
|
|
42
|
+
*
|
|
43
|
+
* The backend API returns trades in different formats:
|
|
44
|
+
* - Direct array: [trade1, trade2]
|
|
45
|
+
* - Wrapped object: { trades: [trade1, trade2] }
|
|
46
|
+
*
|
|
47
|
+
* This normalizer ensures we always get an array of trades with proper Date objects.
|
|
48
|
+
*
|
|
49
|
+
* @param data Raw response data from backend
|
|
50
|
+
* @returns Normalized array of trades with Date objects
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const normalized = normalizeTradeResponse({
|
|
55
|
+
* trades: [
|
|
56
|
+
* { id: 1, createdAt: '2024-01-01', updatedAt: '2024-01-01' }
|
|
57
|
+
* ]
|
|
58
|
+
* });
|
|
59
|
+
* // Result: [{ id: 1, createdAt: Date(...), updatedAt: Date(...) }]
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function normalizeTradeResponse(data: any): any[];
|
|
63
|
+
/**
|
|
64
|
+
* Normalizes token list response data into consistent array format
|
|
65
|
+
*
|
|
66
|
+
* The backend API returns token lists in different formats:
|
|
67
|
+
* - Direct array: [token1, token2]
|
|
68
|
+
* - Wrapped object: { token: [token1, token2] }
|
|
69
|
+
*
|
|
70
|
+
* This normalizer ensures we always get an array of tokens with proper Date objects.
|
|
71
|
+
*
|
|
72
|
+
* @param data Raw response data from backend
|
|
73
|
+
* @returns Normalized array of tokens with Date objects
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const normalized = normalizeTokenListResponse({
|
|
78
|
+
* token: [
|
|
79
|
+
* { id: 1, createdAt: '2024-01-01', updatedAt: '2024-01-01' }
|
|
80
|
+
* ]
|
|
81
|
+
* });
|
|
82
|
+
* // Result: [{ id: 1, createdAt: Date(...), updatedAt: Date(...) }]
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function normalizeTokenListResponse(data: any): any[];
|
|
86
|
+
/**
|
|
87
|
+
* Extracts pagination metadata from backend response
|
|
88
|
+
*
|
|
89
|
+
* Safely extracts page, limit, and total from various response formats,
|
|
90
|
+
* providing defaults when fields are missing.
|
|
91
|
+
*
|
|
92
|
+
* @param response Raw backend response
|
|
93
|
+
* @param defaults Default values for page and limit
|
|
94
|
+
* @returns Normalized pagination metadata
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const pagination = extractPaginationMetadata(
|
|
99
|
+
* { page: '2', limit: '10', total: '100' },
|
|
100
|
+
* { page: 1, limit: 10 }
|
|
101
|
+
* );
|
|
102
|
+
* // Result: { page: 2, limit: 10, total: 100, totalPages: 10 }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function extractPaginationMetadata(response: any, defaults: {
|
|
106
|
+
page: number;
|
|
107
|
+
limit: number;
|
|
108
|
+
}): {
|
|
109
|
+
page: number;
|
|
110
|
+
limit: number;
|
|
111
|
+
total: number;
|
|
112
|
+
totalPages: number;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Creates pagination helper flags
|
|
116
|
+
*
|
|
117
|
+
* Calculates hasNext and hasPrevious flags based on current page and total pages.
|
|
118
|
+
*
|
|
119
|
+
* @param page Current page number
|
|
120
|
+
* @param totalPages Total number of pages
|
|
121
|
+
* @returns Pagination navigation flags
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const flags = createPaginationFlags(2, 5);
|
|
126
|
+
* // Result: { hasNext: true, hasPrevious: true }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare function createPaginationFlags(page: number, totalPages: number): {
|
|
130
|
+
hasNext: boolean;
|
|
131
|
+
hasPrevious: boolean;
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=response-normalizers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-normalizers.d.ts","sourceRoot":"","sources":["../../src/utils/response-normalizers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,CAgCtD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,CAkBvD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,CAc3D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,GAAG,EACb,QAAQ,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACxC;IACD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB,CAOA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB,CAKA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gala-chain/launchpad-sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"description": "TypeScript SDK for Gala Launchpad Backend API - Production-ready DeFi token launchpad integration with wallet-based authentication, GalaChain trading, and comprehensive user operations. 100% tested (22/22 endpoints working).",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|