@sudobility/types 1.9.55 → 1.9.57
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/README.md +44 -280
- package/dist/index.d.ts +50 -50
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -201
- package/dist/index.js.map +1 -1
- package/dist/types/blockchain/common.d.ts +3 -3
- package/dist/types/blockchain/common.d.ts.map +1 -1
- package/dist/types/blockchain/common.js +9 -16
- package/dist/types/blockchain/common.js.map +1 -1
- package/dist/types/blockchain/index.d.ts +4 -4
- package/dist/types/blockchain/index.d.ts.map +1 -1
- package/dist/types/blockchain/index.js +3 -17
- package/dist/types/blockchain/index.js.map +1 -1
- package/dist/types/blockchain/validation.d.ts +1 -1
- package/dist/types/blockchain/validation.d.ts.map +1 -1
- package/dist/types/blockchain/validation.js +6 -12
- package/dist/types/blockchain/validation.js.map +1 -1
- package/dist/types/business/enums.js +46 -49
- package/dist/types/business/enums.js.map +1 -1
- package/dist/types/business/wallet-status.d.ts +2 -2
- package/dist/types/business/wallet-status.d.ts.map +1 -1
- package/dist/types/business/wallet-status.js +10 -16
- package/dist/types/business/wallet-status.js.map +1 -1
- package/dist/types/common.d.ts +1 -1
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +1 -2
- package/dist/types/common.js.map +1 -1
- package/dist/types/config/app-config.d.ts +1 -1
- package/dist/types/config/app-config.d.ts.map +1 -1
- package/dist/types/config/app-config.js +1 -2
- package/dist/types/config/app-config.js.map +1 -1
- package/dist/types/config/environment.d.ts +1 -1
- package/dist/types/config/environment.d.ts.map +1 -1
- package/dist/types/config/environment.js +2 -5
- package/dist/types/config/environment.js.map +1 -1
- package/dist/types/consumables/index.js +1 -2
- package/dist/types/consumables/index.js.map +1 -1
- package/dist/types/entity/entity.js +6 -9
- package/dist/types/entity/entity.js.map +1 -1
- package/dist/types/entity/permissions.d.ts +1 -1
- package/dist/types/entity/permissions.d.ts.map +1 -1
- package/dist/types/entity/permissions.js +12 -17
- package/dist/types/entity/permissions.js.map +1 -1
- package/dist/types/entity/requests.d.ts +1 -1
- package/dist/types/entity/requests.d.ts.map +1 -1
- package/dist/types/entity/requests.js +1 -2
- package/dist/types/entity/requests.js.map +1 -1
- package/dist/types/entity/responses.d.ts +2 -2
- package/dist/types/entity/responses.d.ts.map +1 -1
- package/dist/types/entity/responses.js +1 -2
- package/dist/types/entity/responses.js.map +1 -1
- package/dist/types/infrastructure/analytics.d.ts +1 -1
- package/dist/types/infrastructure/analytics.d.ts.map +1 -1
- package/dist/types/infrastructure/analytics.js +3 -7
- package/dist/types/infrastructure/analytics.js.map +1 -1
- package/dist/types/infrastructure/api.d.ts +2 -2
- package/dist/types/infrastructure/api.d.ts.map +1 -1
- package/dist/types/infrastructure/api.js +5 -9
- package/dist/types/infrastructure/api.js.map +1 -1
- package/dist/types/infrastructure/firebase-user.js +1 -2
- package/dist/types/infrastructure/firebase-user.js.map +1 -1
- package/dist/types/infrastructure/navigation.d.ts +1 -1
- package/dist/types/infrastructure/navigation.d.ts.map +1 -1
- package/dist/types/infrastructure/navigation.js +1 -2
- package/dist/types/infrastructure/network.d.ts +1 -1
- package/dist/types/infrastructure/network.d.ts.map +1 -1
- package/dist/types/infrastructure/network.js +1 -4
- package/dist/types/infrastructure/network.js.map +1 -1
- package/dist/types/infrastructure/wallet.js +2 -5
- package/dist/types/infrastructure/wallet.js.map +1 -1
- package/dist/types/subscription/entitlements.js +1 -4
- package/dist/types/subscription/entitlements.js.map +1 -1
- package/dist/types/subscription/period.js +2 -5
- package/dist/types/subscription/period.js.map +1 -1
- package/dist/types/subscription/rate-limits.js +2 -5
- package/dist/types/subscription/rate-limits.js.map +1 -1
- package/dist/utils/async-helpers.d.ts +1 -1
- package/dist/utils/async-helpers.d.ts.map +1 -1
- package/dist/utils/async-helpers.js +7 -16
- package/dist/utils/async-helpers.js.map +1 -1
- package/dist/utils/auth/admin-emails.js +3 -8
- package/dist/utils/auth/admin-emails.js.map +1 -1
- package/dist/utils/auth/auth.d.ts +2 -2
- package/dist/utils/auth/auth.d.ts.map +1 -1
- package/dist/utils/auth/auth.js +14 -24
- package/dist/utils/auth/auth.js.map +1 -1
- package/dist/utils/blockchain/address.d.ts +2 -2
- package/dist/utils/blockchain/address.d.ts.map +1 -1
- package/dist/utils/blockchain/address.js +21 -32
- package/dist/utils/blockchain/address.js.map +1 -1
- package/dist/utils/blockchain/event-helpers.js +9 -20
- package/dist/utils/blockchain/event-helpers.js.map +1 -1
- package/dist/utils/constants/application.js +2 -20
- package/dist/utils/constants/application.js.map +1 -1
- package/dist/utils/constants/status-values.js +1 -4
- package/dist/utils/constants/status-values.js.map +1 -1
- package/dist/utils/formatting/currency.js +6 -11
- package/dist/utils/formatting/currency.js.map +1 -1
- package/dist/utils/formatting/date.d.ts +1 -1
- package/dist/utils/formatting/date.d.ts.map +1 -1
- package/dist/utils/formatting/date.js +7 -16
- package/dist/utils/formatting/date.js.map +1 -1
- package/dist/utils/formatting/string.d.ts +1 -1
- package/dist/utils/formatting/string.d.ts.map +1 -1
- package/dist/utils/formatting/string.js +16 -34
- package/dist/utils/formatting/string.js.map +1 -1
- package/dist/utils/logging/logger.d.ts +1 -1
- package/dist/utils/logging/logger.d.ts.map +1 -1
- package/dist/utils/logging/logger.js +2 -10
- package/dist/utils/logging/logger.js.map +1 -1
- package/dist/utils/url/url-params.d.ts +1 -1
- package/dist/utils/url/url-params.d.ts.map +1 -1
- package/dist/utils/url/url-params.js +1 -6
- package/dist/utils/url/url-params.js.map +1 -1
- package/dist/utils/validation/type-validation.d.ts +1 -1
- package/dist/utils/validation/type-validation.d.ts.map +1 -1
- package/dist/utils/validation/type-validation.js +27 -48
- package/dist/utils/validation/type-validation.js.map +1 -1
- package/dist/utils/validation/web3-username-validator.d.ts +2 -2
- package/dist/utils/validation/web3-username-validator.d.ts.map +1 -1
- package/dist/utils/validation/web3-username-validator.js +6 -10
- package/dist/utils/validation/web3-username-validator.js.map +1 -1
- package/package.json +4 -11
- package/dist/index.cjs +0 -243
- package/dist/types/blockchain/common.cjs +0 -127
- package/dist/types/blockchain/index.cjs +0 -30
- package/dist/types/blockchain/validation.cjs +0 -144
- package/dist/types/business/enums.cjs +0 -367
- package/dist/types/business/wallet-status.cjs +0 -38
- package/dist/types/common.cjs +0 -12
- package/dist/types/config/app-config.cjs +0 -6
- package/dist/types/config/environment.cjs +0 -24
- package/dist/types/consumables/index.cjs +0 -8
- package/dist/types/entity/entity.cjs +0 -51
- package/dist/types/entity/permissions.cjs +0 -93
- package/dist/types/entity/requests.cjs +0 -7
- package/dist/types/entity/responses.cjs +0 -7
- package/dist/types/infrastructure/analytics.cjs +0 -212
- package/dist/types/infrastructure/api.cjs +0 -43
- package/dist/types/infrastructure/firebase-user.cjs +0 -10
- package/dist/types/infrastructure/navigation.cjs +0 -3
- package/dist/types/infrastructure/network.cjs +0 -18
- package/dist/types/infrastructure/wallet.cjs +0 -37
- package/dist/types/subscription/entitlements.cjs +0 -14
- package/dist/types/subscription/period.cjs +0 -29
- package/dist/types/subscription/rate-limits.cjs +0 -20
- package/dist/utils/async-helpers.cjs +0 -244
- package/dist/utils/auth/admin-emails.cjs +0 -79
- package/dist/utils/auth/auth.cjs +0 -99
- package/dist/utils/blockchain/address.cjs +0 -225
- package/dist/utils/blockchain/event-helpers.cjs +0 -143
- package/dist/utils/constants/application.cjs +0 -152
- package/dist/utils/constants/status-values.cjs +0 -14
- package/dist/utils/formatting/currency.cjs +0 -39
- package/dist/utils/formatting/date.cjs +0 -197
- package/dist/utils/formatting/string.cjs +0 -326
- package/dist/utils/logging/logger.cjs +0 -92
- package/dist/utils/url/url-params.cjs +0 -128
- package/dist/utils/validation/type-validation.cjs +0 -250
- package/dist/utils/validation/web3-username-validator.cjs +0 -132
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Platform-agnostic URLSearchParams wrapper
|
|
4
|
-
* Provides URLSearchParams functionality with React Native compatibility
|
|
5
|
-
*/
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.createURLSearchParams = createURLSearchParams;
|
|
8
|
-
exports.createSearchParams = createSearchParams;
|
|
9
|
-
exports.searchParamsToString = searchParamsToString;
|
|
10
|
-
exports.parseSearchParams = parseSearchParams;
|
|
11
|
-
/**
|
|
12
|
-
* Simple URLSearchParams implementation for environments that don't have it
|
|
13
|
-
*/
|
|
14
|
-
class SimpleURLSearchParams {
|
|
15
|
-
constructor(init) {
|
|
16
|
-
this.params = new Map();
|
|
17
|
-
if (init) {
|
|
18
|
-
if (typeof init === 'string') {
|
|
19
|
-
this.parseString(init);
|
|
20
|
-
}
|
|
21
|
-
else if (Array.isArray(init)) {
|
|
22
|
-
for (const [key, value] of init) {
|
|
23
|
-
this.append(key, value);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
for (const [key, value] of Object.entries(init)) {
|
|
28
|
-
if (value !== undefined) {
|
|
29
|
-
this.append(key, value);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
parseString(str) {
|
|
36
|
-
const params = str.startsWith('?') ? str.slice(1) : str;
|
|
37
|
-
if (!params)
|
|
38
|
-
return;
|
|
39
|
-
for (const pair of params.split('&')) {
|
|
40
|
-
const [key, value = ''] = pair.split('=');
|
|
41
|
-
if (key) {
|
|
42
|
-
this.append(decodeURIComponent(key), decodeURIComponent(value));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
append(name, value) {
|
|
47
|
-
if (!this.params.has(name)) {
|
|
48
|
-
this.params.set(name, []);
|
|
49
|
-
}
|
|
50
|
-
const existingValues = this.params.get(name);
|
|
51
|
-
if (existingValues) {
|
|
52
|
-
existingValues.push(value);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
delete(name) {
|
|
56
|
-
this.params.delete(name);
|
|
57
|
-
}
|
|
58
|
-
get(name) {
|
|
59
|
-
const values = this.params.get(name);
|
|
60
|
-
return values && values.length > 0 ? values[0] : null;
|
|
61
|
-
}
|
|
62
|
-
getAll(name) {
|
|
63
|
-
return this.params.get(name) || [];
|
|
64
|
-
}
|
|
65
|
-
has(name) {
|
|
66
|
-
return this.params.has(name);
|
|
67
|
-
}
|
|
68
|
-
set(name, value) {
|
|
69
|
-
this.params.set(name, [value]);
|
|
70
|
-
}
|
|
71
|
-
toString() {
|
|
72
|
-
const pairs = [];
|
|
73
|
-
this.params.forEach((values, key) => {
|
|
74
|
-
for (const value of values) {
|
|
75
|
-
pairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
return pairs.join('&');
|
|
79
|
-
}
|
|
80
|
-
forEach(callback) {
|
|
81
|
-
this.params.forEach((values, key) => {
|
|
82
|
-
for (const value of values) {
|
|
83
|
-
callback(value, key);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Create a URLSearchParams instance with cross-platform compatibility
|
|
90
|
-
*/
|
|
91
|
-
function createURLSearchParams(init) {
|
|
92
|
-
// Check if native URLSearchParams is available
|
|
93
|
-
if (typeof URLSearchParams !== 'undefined') {
|
|
94
|
-
return new URLSearchParams(init);
|
|
95
|
-
}
|
|
96
|
-
// Fall back to our implementation for React Native or other environments
|
|
97
|
-
return new SimpleURLSearchParams(init);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Convenience function to create URL search params from an object
|
|
101
|
-
*/
|
|
102
|
-
function createSearchParams(params) {
|
|
103
|
-
const searchParams = createURLSearchParams(undefined);
|
|
104
|
-
for (const [key, value] of Object.entries(params)) {
|
|
105
|
-
if (value !== undefined && value !== null) {
|
|
106
|
-
searchParams.append(key, String(value));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return searchParams;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Convert search params to a query string
|
|
113
|
-
*/
|
|
114
|
-
function searchParamsToString(params) {
|
|
115
|
-
return params.toString();
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Parse a query string into an object
|
|
119
|
-
*/
|
|
120
|
-
function parseSearchParams(queryString) {
|
|
121
|
-
const params = createURLSearchParams(queryString);
|
|
122
|
-
const result = {};
|
|
123
|
-
params.forEach((value, key) => {
|
|
124
|
-
result[key] = value;
|
|
125
|
-
});
|
|
126
|
-
return result;
|
|
127
|
-
}
|
|
128
|
-
//# sourceMappingURL=url-params.js.map
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Type validation utilities for runtime type checking
|
|
4
|
-
*
|
|
5
|
-
* These utilities help ensure type safety at runtime, especially useful
|
|
6
|
-
* for validating API responses and external data.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.parseJson = exports.createAssertion = exports.isUrl = exports.isEmail = exports.isValidDate = exports.isErrorResponse = exports.isSuccessResponse = exports.isApiResponse = exports.optional = exports.validateArray = exports.hasRequiredProperties = exports.isNullish = exports.isArray = exports.isObject = exports.isBoolean = exports.isNumber = exports.isString = exports.createValidator = void 0;
|
|
10
|
-
/**
|
|
11
|
-
* Creates a validation function that safely checks if a value matches
|
|
12
|
-
* the expected type. Returns a {@link ValidationResult}.
|
|
13
|
-
*
|
|
14
|
-
* @template T - The validated type
|
|
15
|
-
* @param validationFn - Type guard function
|
|
16
|
-
* @param typeName - Name used in error messages
|
|
17
|
-
* @returns A function returning `ValidationResult<T>`
|
|
18
|
-
* @since 1.0.0
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* const validateString = createValidator(isString, 'string');
|
|
23
|
-
* validateString('hi'); // { isValid: true, data: 'hi' }
|
|
24
|
-
* validateString(42); // { isValid: false, error: 'Invalid string' }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
const createValidator = (validationFn, typeName) => {
|
|
28
|
-
return (data) => {
|
|
29
|
-
try {
|
|
30
|
-
if (validationFn(data)) {
|
|
31
|
-
return { isValid: true, data };
|
|
32
|
-
}
|
|
33
|
-
return { isValid: false, error: `Invalid ${typeName}`, data: null };
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
return {
|
|
37
|
-
isValid: false,
|
|
38
|
-
error: `Validation error for ${typeName}: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
39
|
-
data: null,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
exports.createValidator = createValidator;
|
|
45
|
-
/**
|
|
46
|
-
* Runtime type guard: checks if value is a `string`.
|
|
47
|
-
* @since 1.0.0
|
|
48
|
-
*/
|
|
49
|
-
const isString = (value) => typeof value === 'string';
|
|
50
|
-
exports.isString = isString;
|
|
51
|
-
/**
|
|
52
|
-
* Runtime type guard: checks if value is a finite `number` (excludes NaN).
|
|
53
|
-
* @since 1.0.0
|
|
54
|
-
*/
|
|
55
|
-
const isNumber = (value) => typeof value === 'number' && !isNaN(value);
|
|
56
|
-
exports.isNumber = isNumber;
|
|
57
|
-
/**
|
|
58
|
-
* Runtime type guard: checks if value is a `boolean`.
|
|
59
|
-
* @since 1.0.0
|
|
60
|
-
*/
|
|
61
|
-
const isBoolean = (value) => typeof value === 'boolean';
|
|
62
|
-
exports.isBoolean = isBoolean;
|
|
63
|
-
/**
|
|
64
|
-
* Runtime type guard: checks if value is a non-null, non-array object.
|
|
65
|
-
* @since 1.0.0
|
|
66
|
-
*/
|
|
67
|
-
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
68
|
-
exports.isObject = isObject;
|
|
69
|
-
/**
|
|
70
|
-
* Runtime type guard: checks if value is an array.
|
|
71
|
-
* @since 1.0.0
|
|
72
|
-
*/
|
|
73
|
-
const isArray = (value) => Array.isArray(value);
|
|
74
|
-
exports.isArray = isArray;
|
|
75
|
-
/**
|
|
76
|
-
* Runtime type guard: checks if value is `null` or `undefined`.
|
|
77
|
-
* @since 1.0.0
|
|
78
|
-
*/
|
|
79
|
-
const isNullish = (value) => value === null || value === undefined;
|
|
80
|
-
exports.isNullish = isNullish;
|
|
81
|
-
/**
|
|
82
|
-
* Validates that an object has all required properties present.
|
|
83
|
-
*
|
|
84
|
-
* @template T - Expected object shape
|
|
85
|
-
* @param obj - Value to check
|
|
86
|
-
* @param requiredProps - Array of required property keys
|
|
87
|
-
* @returns True if obj has all required properties
|
|
88
|
-
* @since 1.0.0
|
|
89
|
-
*/
|
|
90
|
-
const hasRequiredProperties = (obj, requiredProps) => {
|
|
91
|
-
if (!(0, exports.isObject)(obj))
|
|
92
|
-
return false;
|
|
93
|
-
return requiredProps.every((prop) => prop in obj);
|
|
94
|
-
};
|
|
95
|
-
exports.hasRequiredProperties = hasRequiredProperties;
|
|
96
|
-
/**
|
|
97
|
-
* Validates that a value is an array where every item passes a validator.
|
|
98
|
-
*
|
|
99
|
-
* @template T - Expected item type
|
|
100
|
-
* @param data - Value to check
|
|
101
|
-
* @param itemValidator - Type guard for individual items
|
|
102
|
-
* @returns True if data is an array of T
|
|
103
|
-
* @since 1.0.0
|
|
104
|
-
*/
|
|
105
|
-
const validateArray = (data, itemValidator) => {
|
|
106
|
-
if (!(0, exports.isArray)(data))
|
|
107
|
-
return false;
|
|
108
|
-
return data.every(itemValidator);
|
|
109
|
-
};
|
|
110
|
-
exports.validateArray = validateArray;
|
|
111
|
-
/**
|
|
112
|
-
* Wraps a validator to also accept `undefined`.
|
|
113
|
-
*
|
|
114
|
-
* @template T - The validated type
|
|
115
|
-
* @param validator - Base type guard
|
|
116
|
-
* @returns Type guard that also accepts `undefined`
|
|
117
|
-
* @since 1.0.0
|
|
118
|
-
*/
|
|
119
|
-
const optional = (validator) => (value) => {
|
|
120
|
-
return value === undefined || validator(value);
|
|
121
|
-
};
|
|
122
|
-
exports.optional = optional;
|
|
123
|
-
/**
|
|
124
|
-
* Check if data looks like an API response (has `success` boolean).
|
|
125
|
-
* @since 1.0.0
|
|
126
|
-
*/
|
|
127
|
-
const isApiResponse = (data) => {
|
|
128
|
-
return (0, exports.isObject)(data) && (0, exports.isBoolean)(data.success);
|
|
129
|
-
};
|
|
130
|
-
exports.isApiResponse = isApiResponse;
|
|
131
|
-
const isSuccessResponse = (data, dataValidator) => {
|
|
132
|
-
if (!(0, exports.isApiResponse)(data) || !data.success)
|
|
133
|
-
return false;
|
|
134
|
-
if (dataValidator && 'data' in data) {
|
|
135
|
-
return dataValidator(data.data);
|
|
136
|
-
}
|
|
137
|
-
return true;
|
|
138
|
-
};
|
|
139
|
-
exports.isSuccessResponse = isSuccessResponse;
|
|
140
|
-
const isErrorResponse = (data) => {
|
|
141
|
-
return ((0, exports.isApiResponse)(data) &&
|
|
142
|
-
!data.success &&
|
|
143
|
-
'error' in data &&
|
|
144
|
-
(0, exports.isString)(data.error));
|
|
145
|
-
};
|
|
146
|
-
exports.isErrorResponse = isErrorResponse;
|
|
147
|
-
/**
|
|
148
|
-
* Check if a value is a string that parses to a valid date.
|
|
149
|
-
* @since 1.0.0
|
|
150
|
-
*/
|
|
151
|
-
const isValidDate = (value) => {
|
|
152
|
-
if (!(0, exports.isString)(value))
|
|
153
|
-
return false;
|
|
154
|
-
const date = new Date(value);
|
|
155
|
-
return !isNaN(date.getTime());
|
|
156
|
-
};
|
|
157
|
-
exports.isValidDate = isValidDate;
|
|
158
|
-
/**
|
|
159
|
-
* Basic email format validation.
|
|
160
|
-
* @since 1.0.0
|
|
161
|
-
*/
|
|
162
|
-
const isEmail = (value) => {
|
|
163
|
-
if (!(0, exports.isString)(value))
|
|
164
|
-
return false;
|
|
165
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
166
|
-
return emailRegex.test(value);
|
|
167
|
-
};
|
|
168
|
-
exports.isEmail = isEmail;
|
|
169
|
-
/**
|
|
170
|
-
* Basic URL validation using the `URL` constructor.
|
|
171
|
-
* @since 1.0.0
|
|
172
|
-
*/
|
|
173
|
-
const isUrl = (value) => {
|
|
174
|
-
if (!(0, exports.isString)(value))
|
|
175
|
-
return false;
|
|
176
|
-
try {
|
|
177
|
-
new URL(value);
|
|
178
|
-
return true;
|
|
179
|
-
}
|
|
180
|
-
catch {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
exports.isUrl = isUrl;
|
|
185
|
-
/**
|
|
186
|
-
* Creates a type assertion function that throws `TypeError` on
|
|
187
|
-
* invalid data. Use with `createValidator` for the non-throwing variant.
|
|
188
|
-
*
|
|
189
|
-
* @template T - The asserted type
|
|
190
|
-
* @param validator - Type guard function
|
|
191
|
-
* @param typeName - Name used in error messages
|
|
192
|
-
* @returns An assertion function
|
|
193
|
-
* @since 1.0.0
|
|
194
|
-
*
|
|
195
|
-
* @example
|
|
196
|
-
* ```typescript
|
|
197
|
-
* const assertString = createAssertion(isString, 'string');
|
|
198
|
-
* assertString('hello'); // passes
|
|
199
|
-
* assertString(42); // throws TypeError
|
|
200
|
-
* ```
|
|
201
|
-
*/
|
|
202
|
-
const createAssertion = (validator, typeName) => {
|
|
203
|
-
return (data, context = typeName) => {
|
|
204
|
-
if (!validator(data)) {
|
|
205
|
-
throw new TypeError(`Invalid ${context}: expected ${typeName}`);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
};
|
|
209
|
-
exports.createAssertion = createAssertion;
|
|
210
|
-
/**
|
|
211
|
-
* Safely parse a JSON string, optionally validating the result.
|
|
212
|
-
* Returns a {@link ValidationResult} instead of throwing.
|
|
213
|
-
*
|
|
214
|
-
* @template T - Expected parsed type
|
|
215
|
-
* @param jsonString - JSON string to parse
|
|
216
|
-
* @param validator - Optional type guard to validate the parsed result
|
|
217
|
-
* @returns Validation result with parsed data or error
|
|
218
|
-
* @since 1.0.0
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* ```typescript
|
|
222
|
-
* const result = parseJson('{"name":"Alice"}');
|
|
223
|
-
* if (result.isValid) console.log(result.data);
|
|
224
|
-
* ```
|
|
225
|
-
*/
|
|
226
|
-
const parseJson = (jsonString, validator) => {
|
|
227
|
-
try {
|
|
228
|
-
const parsed = JSON.parse(jsonString);
|
|
229
|
-
if (validator) {
|
|
230
|
-
if (validator(parsed)) {
|
|
231
|
-
return { isValid: true, data: parsed };
|
|
232
|
-
}
|
|
233
|
-
return {
|
|
234
|
-
isValid: false,
|
|
235
|
-
error: 'Parsed JSON does not match expected type',
|
|
236
|
-
data: null,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
return { isValid: true, data: parsed };
|
|
240
|
-
}
|
|
241
|
-
catch (error) {
|
|
242
|
-
return {
|
|
243
|
-
isValid: false,
|
|
244
|
-
error: `JSON parse error: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
245
|
-
data: null,
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
exports.parseJson = parseJson;
|
|
250
|
-
//# sourceMappingURL=type-validation.js.map
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @fileoverview Address Validation Utility
|
|
4
|
-
* @description Centralized address validation for EVM, Solana, ENS, and SNS addresses
|
|
5
|
-
* Eliminates code duplication across multiple files
|
|
6
|
-
*
|
|
7
|
-
* Pure TypeScript implementation with no external dependencies
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.Web3UsernameValidator = void 0;
|
|
11
|
-
// Import ChainType from business enums
|
|
12
|
-
const enums_1 = require("../../types/business/enums");
|
|
13
|
-
class Web3UsernameValidator {
|
|
14
|
-
/**
|
|
15
|
-
* Comprehensive address validation for API endpoint
|
|
16
|
-
* Returns AddressValidationResult for valid addresses, undefined for invalid ones
|
|
17
|
-
*/
|
|
18
|
-
static validate(address) {
|
|
19
|
-
if (!address) {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
// 1. Check if it's a valid EVM address (0x + 40 hex characters)
|
|
23
|
-
if (this.EVM_REGEX.test(address)) {
|
|
24
|
-
return {
|
|
25
|
-
name: null,
|
|
26
|
-
address: address.toLowerCase(),
|
|
27
|
-
chainType: enums_1.ChainType.EVM,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
// 2. Check if it's a valid Solana address (Base58, 32-44 characters, no 0x prefix)
|
|
31
|
-
if (!address.startsWith('0x') &&
|
|
32
|
-
address.length >= 32 &&
|
|
33
|
-
address.length <= 44 &&
|
|
34
|
-
this.BASE58_REGEX.test(address)) {
|
|
35
|
-
return {
|
|
36
|
-
name: null,
|
|
37
|
-
address: address, // Keep case for Solana
|
|
38
|
-
chainType: enums_1.ChainType.SOLANA,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
// 3. Check if it's a valid ENS name (.eth or .box)
|
|
42
|
-
if ((address.toLowerCase().endsWith('.eth') ||
|
|
43
|
-
address.toLowerCase().endsWith('.box')) &&
|
|
44
|
-
address.length >= 5 && // minimum: "a.eth" = 5 chars
|
|
45
|
-
this.ENS_REGEX.test(address)) {
|
|
46
|
-
return {
|
|
47
|
-
name: address.toLowerCase(),
|
|
48
|
-
address: null,
|
|
49
|
-
chainType: enums_1.ChainType.EVM, // ENS resolves to EVM addresses
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
// 4. Check if it's a valid SNS name (Solana Name Service)
|
|
53
|
-
if (address.toLowerCase().includes('.')) {
|
|
54
|
-
const parts = address.toLowerCase().split('.');
|
|
55
|
-
if (parts.length === 2) {
|
|
56
|
-
const [name, tld] = parts;
|
|
57
|
-
if (this.VALID_SNS_TLDS.includes(tld) &&
|
|
58
|
-
this.SNS_NAME_REGEX.test(name) &&
|
|
59
|
-
name.length >= 1) {
|
|
60
|
-
return {
|
|
61
|
-
name: address.toLowerCase(),
|
|
62
|
-
address: null,
|
|
63
|
-
chainType: enums_1.ChainType.SOLANA, // SNS resolves to Solana addresses
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// If no format matches, return undefined
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Quick EVM address validation
|
|
73
|
-
*/
|
|
74
|
-
static isValidEVMAddress(address) {
|
|
75
|
-
return this.EVM_REGEX.test(address);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Quick Solana address validation
|
|
79
|
-
*/
|
|
80
|
-
static isValidSolanaAddress(address) {
|
|
81
|
-
return (!address.startsWith('0x') &&
|
|
82
|
-
address.length >= 32 &&
|
|
83
|
-
address.length <= 44 &&
|
|
84
|
-
this.BASE58_REGEX.test(address));
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Quick ENS name validation
|
|
88
|
-
*/
|
|
89
|
-
static isValidENSName(address) {
|
|
90
|
-
return ((address.toLowerCase().endsWith('.eth') ||
|
|
91
|
-
address.toLowerCase().endsWith('.box')) &&
|
|
92
|
-
address.length >= 5 &&
|
|
93
|
-
this.ENS_REGEX.test(address));
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Quick SNS name validation
|
|
97
|
-
*/
|
|
98
|
-
static isValidSNSName(address) {
|
|
99
|
-
if (!address.toLowerCase().includes('.'))
|
|
100
|
-
return false;
|
|
101
|
-
const parts = address.toLowerCase().split('.');
|
|
102
|
-
if (parts.length !== 2)
|
|
103
|
-
return false;
|
|
104
|
-
const [name, tld] = parts;
|
|
105
|
-
return (this.VALID_SNS_TLDS.includes(tld) &&
|
|
106
|
-
this.SNS_NAME_REGEX.test(name) &&
|
|
107
|
-
name.length >= 1);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
exports.Web3UsernameValidator = Web3UsernameValidator;
|
|
111
|
-
// Regex patterns for different address types
|
|
112
|
-
Web3UsernameValidator.EVM_REGEX = /^0x[a-fA-F0-9]{40}$/;
|
|
113
|
-
Web3UsernameValidator.BASE58_REGEX = /^[1-9A-HJ-NP-Za-km-z]+$/;
|
|
114
|
-
Web3UsernameValidator.ENS_REGEX = /^[a-zA-Z0-9]([a-zA-Z0-9]|(-[a-zA-Z0-9]))*\.(eth|box)$/i;
|
|
115
|
-
Web3UsernameValidator.SNS_NAME_REGEX = /^[a-zA-Z0-9]([a-zA-Z0-9]|(-[a-zA-Z0-9]))*$/;
|
|
116
|
-
// Valid SNS top-level domains
|
|
117
|
-
Web3UsernameValidator.VALID_SNS_TLDS = [
|
|
118
|
-
'sol',
|
|
119
|
-
'abc',
|
|
120
|
-
'backpack',
|
|
121
|
-
'bonk',
|
|
122
|
-
'coin',
|
|
123
|
-
'dao',
|
|
124
|
-
'defi',
|
|
125
|
-
'gm',
|
|
126
|
-
'poor',
|
|
127
|
-
'pump',
|
|
128
|
-
'shdw',
|
|
129
|
-
'stepn',
|
|
130
|
-
'web3',
|
|
131
|
-
];
|
|
132
|
-
//# sourceMappingURL=web3-username-validator.js.map
|