@gala-chain/launchpad-sdk 3.6.0 → 3.6.2
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/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.map +1 -1
- package/dist/services/FaucetService.d.ts.map +1 -1
- package/dist/services/ImageService.d.ts.map +1 -1
- package/dist/services/PoolService.d.ts.map +1 -1
- package/dist/services/TradeService.d.ts +0 -6
- package/dist/services/TradeService.d.ts.map +1 -1
- package/dist/services/UserService.d.ts +0 -6
- package/dist/services/UserService.d.ts.map +1 -1
- package/dist/utils/error-factories.d.ts +95 -0
- package/dist/utils/error-factories.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/validation-helpers.d.ts +116 -0
- package/dist/utils/validation-helpers.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation Helper Utilities
|
|
3
|
+
*
|
|
4
|
+
* Reusable validation functions for common patterns across services.
|
|
5
|
+
* Eliminates duplicate validation logic and provides consistent error messages.
|
|
6
|
+
*
|
|
7
|
+
* @category Utilities
|
|
8
|
+
* @since 3.6.2
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Pagination constraints structure
|
|
12
|
+
*
|
|
13
|
+
* This interface defines the expected structure for pagination constraint objects
|
|
14
|
+
* used across the SDK (e.g., USER_CONSTRAINTS, TRADE_CONSTRAINTS, COMMENT_CONSTRAINTS).
|
|
15
|
+
*/
|
|
16
|
+
export interface PaginationConstraints {
|
|
17
|
+
PAGINATION: {
|
|
18
|
+
MIN_PAGE: number;
|
|
19
|
+
MAX_PAGE: number;
|
|
20
|
+
MIN_LIMIT: number;
|
|
21
|
+
MAX_LIMIT: number;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validates pagination parameters against constraint bounds
|
|
26
|
+
*
|
|
27
|
+
* This utility consolidates the duplicate pagination validation logic found across
|
|
28
|
+
* multiple services (UserService, TradeService, CommentService).
|
|
29
|
+
*
|
|
30
|
+
* ## Replaces Patterns
|
|
31
|
+
*
|
|
32
|
+
* This function replaces 3 instances of duplicate pagination validation:
|
|
33
|
+
*
|
|
34
|
+
* ### Before (Duplicate Private Methods):
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // UserService.ts (lines 403-427)
|
|
37
|
+
* private validateUserPagination(options: { page: number; limit: number }): void {
|
|
38
|
+
* if (typeof options.page !== 'number' ||
|
|
39
|
+
* options.page < USER_CONSTRAINTS.PAGINATION.MIN_PAGE ||
|
|
40
|
+
* options.page > USER_CONSTRAINTS.PAGINATION.MAX_PAGE) {
|
|
41
|
+
* throw new ValidationError(...);
|
|
42
|
+
* }
|
|
43
|
+
* if (typeof options.limit !== 'number' ||
|
|
44
|
+
* options.limit < USER_CONSTRAINTS.PAGINATION.MIN_LIMIT ||
|
|
45
|
+
* options.limit > USER_CONSTRAINTS.PAGINATION.MAX_LIMIT) {
|
|
46
|
+
* throw new ValidationError(...);
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* // TradeService.ts (lines 121-145) - IDENTICAL STRUCTURE
|
|
51
|
+
* private validateTradePagination(options: { page: number; limit: number }): void {
|
|
52
|
+
* // Same pattern, different constraints
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* // CommentService.ts (inline validation with helper function)
|
|
56
|
+
* if (!isValidCommentPagination(page, limit)) {
|
|
57
|
+
* throw new ValidationError(...);
|
|
58
|
+
* }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* ### After (Single Source of Truth):
|
|
62
|
+
* ```typescript
|
|
63
|
+
* // UserService.ts
|
|
64
|
+
* import { assertValidPagination } from '../utils/validation-helpers';
|
|
65
|
+
* assertValidPagination(page, limit, USER_CONSTRAINTS);
|
|
66
|
+
*
|
|
67
|
+
* // TradeService.ts
|
|
68
|
+
* import { assertValidPagination } from '../utils/validation-helpers';
|
|
69
|
+
* assertValidPagination(page, limit, TRADE_CONSTRAINTS);
|
|
70
|
+
*
|
|
71
|
+
* // CommentService.ts
|
|
72
|
+
* import { assertValidPagination } from '../utils/validation-helpers';
|
|
73
|
+
* assertValidPagination(page, limit, COMMENT_CONSTRAINTS);
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @param page - Page number to validate (1-based)
|
|
77
|
+
* @param limit - Results per page limit to validate
|
|
78
|
+
* @param constraints - Constraint object with PAGINATION bounds
|
|
79
|
+
* @throws ValidationError if page or limit is invalid
|
|
80
|
+
*
|
|
81
|
+
* @example Basic usage with USER_CONSTRAINTS
|
|
82
|
+
* ```typescript
|
|
83
|
+
* import { assertValidPagination } from '../utils/validation-helpers';
|
|
84
|
+
* import { USER_CONSTRAINTS } from '../types/user.dto';
|
|
85
|
+
*
|
|
86
|
+
* function fetchUsers(page: number, limit: number) {
|
|
87
|
+
* assertValidPagination(page, limit, USER_CONSTRAINTS);
|
|
88
|
+
* // Validation passed - proceed with fetch
|
|
89
|
+
* }
|
|
90
|
+
* ```
|
|
91
|
+
*
|
|
92
|
+
* @example With TRADE_CONSTRAINTS
|
|
93
|
+
* ```typescript
|
|
94
|
+
* import { assertValidPagination } from '../utils/validation-helpers';
|
|
95
|
+
* import { TRADE_CONSTRAINTS } from '../types/trade.dto';
|
|
96
|
+
*
|
|
97
|
+
* function fetchTrades(page: number, limit: number) {
|
|
98
|
+
* assertValidPagination(page, limit, TRADE_CONSTRAINTS);
|
|
99
|
+
* // Validation passed - proceed with fetch
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example Error handling
|
|
104
|
+
* ```typescript
|
|
105
|
+
* try {
|
|
106
|
+
* assertValidPagination(0, 100, USER_CONSTRAINTS);
|
|
107
|
+
* } catch (error) {
|
|
108
|
+
* if (error instanceof ValidationError) {
|
|
109
|
+
* console.log(error.code); // 'INVALID_PAGE'
|
|
110
|
+
* console.log(error.message); // 'Page must be a number between 1 and 1000'
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare function assertValidPagination(page: number, limit: number, constraints: PaginationConstraints): void;
|
|
116
|
+
//# sourceMappingURL=validation-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation-helpers.d.ts","sourceRoot":"","sources":["../../src/utils/validation-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE;QACV,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0FG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,qBAAqB,GACjC,IAAI,CAoBN"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gala-chain/launchpad-sdk",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.2",
|
|
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",
|