@sudobility/types 1.8.21

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.
Files changed (248) hide show
  1. package/CLAUDE.md +285 -0
  2. package/README.md +310 -0
  3. package/dist/index.cjs +62 -0
  4. package/dist/index.d.ts +18 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +62 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/types/blockchain/common.cjs +102 -0
  9. package/dist/types/blockchain/common.d.ts +262 -0
  10. package/dist/types/blockchain/common.d.ts.map +1 -0
  11. package/dist/types/blockchain/common.js +102 -0
  12. package/dist/types/blockchain/common.js.map +1 -0
  13. package/dist/types/blockchain/index.cjs +18 -0
  14. package/dist/types/blockchain/index.d.ts +4 -0
  15. package/dist/types/blockchain/index.d.ts.map +1 -0
  16. package/dist/types/blockchain/index.js +18 -0
  17. package/dist/types/blockchain/index.js.map +1 -0
  18. package/dist/types/blockchain/validation.cjs +88 -0
  19. package/dist/types/blockchain/validation.d.ts +9 -0
  20. package/dist/types/blockchain/validation.d.ts.map +1 -0
  21. package/dist/types/blockchain/validation.js +88 -0
  22. package/dist/types/blockchain/validation.js.map +1 -0
  23. package/dist/types/business/enums.cjs +314 -0
  24. package/dist/types/business/enums.d.ts +227 -0
  25. package/dist/types/business/enums.d.ts.map +1 -0
  26. package/dist/types/business/enums.js +314 -0
  27. package/dist/types/business/enums.js.map +1 -0
  28. package/dist/types/business/index.cjs +33 -0
  29. package/dist/types/business/index.d.ts +5 -0
  30. package/dist/types/business/index.d.ts.map +1 -0
  31. package/dist/types/business/index.js +33 -0
  32. package/dist/types/business/index.js.map +1 -0
  33. package/dist/types/business/wallet-status.cjs +38 -0
  34. package/dist/types/business/wallet-status.d.ts +32 -0
  35. package/dist/types/business/wallet-status.d.ts.map +1 -0
  36. package/dist/types/business/wallet-status.js +38 -0
  37. package/dist/types/business/wallet-status.js.map +1 -0
  38. package/dist/types/common.cjs +6 -0
  39. package/dist/types/common.d.ts +142 -0
  40. package/dist/types/common.d.ts.map +1 -0
  41. package/dist/types/common.js +6 -0
  42. package/dist/types/common.js.map +1 -0
  43. package/dist/types/config/app-config.cjs +6 -0
  44. package/dist/types/config/app-config.d.ts +67 -0
  45. package/dist/types/config/app-config.d.ts.map +1 -0
  46. package/dist/types/config/app-config.js +6 -0
  47. package/dist/types/config/app-config.js.map +1 -0
  48. package/dist/types/config/environment.cjs +24 -0
  49. package/dist/types/config/environment.d.ts +68 -0
  50. package/dist/types/config/environment.d.ts.map +1 -0
  51. package/dist/types/config/environment.js +24 -0
  52. package/dist/types/config/environment.js.map +1 -0
  53. package/dist/types/config/index.cjs +6 -0
  54. package/dist/types/config/index.d.ts +4 -0
  55. package/dist/types/config/index.d.ts.map +1 -0
  56. package/dist/types/config/index.js +6 -0
  57. package/dist/types/config/index.js.map +1 -0
  58. package/dist/types/index.cjs +35 -0
  59. package/dist/types/index.d.ts +10 -0
  60. package/dist/types/index.d.ts.map +1 -0
  61. package/dist/types/index.js +35 -0
  62. package/dist/types/index.js.map +1 -0
  63. package/dist/types/indexer/index.cjs +19 -0
  64. package/dist/types/indexer/index.d.ts +3 -0
  65. package/dist/types/indexer/index.d.ts.map +1 -0
  66. package/dist/types/indexer/index.js +19 -0
  67. package/dist/types/indexer/index.js.map +1 -0
  68. package/dist/types/indexer/indexer-guards.cjs +145 -0
  69. package/dist/types/indexer/indexer-guards.d.ts +26 -0
  70. package/dist/types/indexer/indexer-guards.d.ts.map +1 -0
  71. package/dist/types/indexer/indexer-guards.js +145 -0
  72. package/dist/types/indexer/indexer-guards.js.map +1 -0
  73. package/dist/types/indexer/indexer-responses.cjs +8 -0
  74. package/dist/types/indexer/indexer-responses.d.ts +136 -0
  75. package/dist/types/indexer/indexer-responses.d.ts.map +1 -0
  76. package/dist/types/indexer/indexer-responses.js +8 -0
  77. package/dist/types/indexer/indexer-responses.js.map +1 -0
  78. package/dist/types/infrastructure/analytics.cjs +212 -0
  79. package/dist/types/infrastructure/analytics.d.ts +449 -0
  80. package/dist/types/infrastructure/analytics.d.ts.map +1 -0
  81. package/dist/types/infrastructure/analytics.js +212 -0
  82. package/dist/types/infrastructure/analytics.js.map +1 -0
  83. package/dist/types/infrastructure/api.cjs +17 -0
  84. package/dist/types/infrastructure/api.d.ts +152 -0
  85. package/dist/types/infrastructure/api.d.ts.map +1 -0
  86. package/dist/types/infrastructure/api.js +17 -0
  87. package/dist/types/infrastructure/api.js.map +1 -0
  88. package/dist/types/infrastructure/index.cjs +14 -0
  89. package/dist/types/infrastructure/index.d.ts +9 -0
  90. package/dist/types/infrastructure/index.d.ts.map +1 -0
  91. package/dist/types/infrastructure/index.js +14 -0
  92. package/dist/types/infrastructure/index.js.map +1 -0
  93. package/dist/types/infrastructure/navigation.cjs +3 -0
  94. package/dist/types/infrastructure/navigation.d.ts +56 -0
  95. package/dist/types/infrastructure/navigation.d.ts.map +1 -0
  96. package/dist/types/infrastructure/navigation.js +3 -0
  97. package/dist/types/infrastructure/navigation.js.map +1 -0
  98. package/dist/types/infrastructure/network.cjs +18 -0
  99. package/dist/types/infrastructure/network.d.ts +48 -0
  100. package/dist/types/infrastructure/network.d.ts.map +1 -0
  101. package/dist/types/infrastructure/network.js +18 -0
  102. package/dist/types/infrastructure/network.js.map +1 -0
  103. package/dist/types/infrastructure/wallet.cjs +37 -0
  104. package/dist/types/infrastructure/wallet.d.ts +33 -0
  105. package/dist/types/infrastructure/wallet.d.ts.map +1 -0
  106. package/dist/types/infrastructure/wallet.js +37 -0
  107. package/dist/types/infrastructure/wallet.js.map +1 -0
  108. package/dist/types/kyc/index.cjs +19 -0
  109. package/dist/types/kyc/index.d.ts +2 -0
  110. package/dist/types/kyc/index.d.ts.map +1 -0
  111. package/dist/types/kyc/index.js +19 -0
  112. package/dist/types/kyc/index.js.map +1 -0
  113. package/dist/types/kyc/kyc-types.cjs +12 -0
  114. package/dist/types/kyc/kyc-types.d.ts +260 -0
  115. package/dist/types/kyc/kyc-types.d.ts.map +1 -0
  116. package/dist/types/kyc/kyc-types.js +12 -0
  117. package/dist/types/kyc/kyc-types.js.map +1 -0
  118. package/dist/types/mailer/index.cjs +19 -0
  119. package/dist/types/mailer/index.d.ts +2 -0
  120. package/dist/types/mailer/index.d.ts.map +1 -0
  121. package/dist/types/mailer/index.js +19 -0
  122. package/dist/types/mailer/index.js.map +1 -0
  123. package/dist/types/mailer/mail-types.cjs +38 -0
  124. package/dist/types/mailer/mail-types.d.ts +296 -0
  125. package/dist/types/mailer/mail-types.d.ts.map +1 -0
  126. package/dist/types/mailer/mail-types.js +38 -0
  127. package/dist/types/mailer/mail-types.js.map +1 -0
  128. package/dist/types/wildduck/index.cjs +19 -0
  129. package/dist/types/wildduck/index.d.ts +2 -0
  130. package/dist/types/wildduck/index.d.ts.map +1 -0
  131. package/dist/types/wildduck/index.js +19 -0
  132. package/dist/types/wildduck/index.js.map +1 -0
  133. package/dist/types/wildduck/wildduck-types.cjs +48 -0
  134. package/dist/types/wildduck/wildduck-types.d.ts +1239 -0
  135. package/dist/types/wildduck/wildduck-types.d.ts.map +1 -0
  136. package/dist/types/wildduck/wildduck-types.js +48 -0
  137. package/dist/types/wildduck/wildduck-types.js.map +1 -0
  138. package/dist/utils/async-helpers.cjs +130 -0
  139. package/dist/utils/async-helpers.d.ts +35 -0
  140. package/dist/utils/async-helpers.d.ts.map +1 -0
  141. package/dist/utils/async-helpers.js +130 -0
  142. package/dist/utils/async-helpers.js.map +1 -0
  143. package/dist/utils/auth/auth.cjs +96 -0
  144. package/dist/utils/auth/auth.d.ts +40 -0
  145. package/dist/utils/auth/auth.d.ts.map +1 -0
  146. package/dist/utils/auth/auth.js +96 -0
  147. package/dist/utils/auth/auth.js.map +1 -0
  148. package/dist/utils/auth/index.cjs +14 -0
  149. package/dist/utils/auth/index.d.ts +2 -0
  150. package/dist/utils/auth/index.d.ts.map +1 -0
  151. package/dist/utils/auth/index.js +14 -0
  152. package/dist/utils/auth/index.js.map +1 -0
  153. package/dist/utils/blockchain/address.cjs +231 -0
  154. package/dist/utils/blockchain/address.d.ts +65 -0
  155. package/dist/utils/blockchain/address.d.ts.map +1 -0
  156. package/dist/utils/blockchain/address.js +231 -0
  157. package/dist/utils/blockchain/address.js.map +1 -0
  158. package/dist/utils/blockchain/event-helpers.cjs +143 -0
  159. package/dist/utils/blockchain/event-helpers.d.ts +87 -0
  160. package/dist/utils/blockchain/event-helpers.d.ts.map +1 -0
  161. package/dist/utils/blockchain/event-helpers.js +143 -0
  162. package/dist/utils/blockchain/event-helpers.js.map +1 -0
  163. package/dist/utils/blockchain/index.cjs +30 -0
  164. package/dist/utils/blockchain/index.d.ts +8 -0
  165. package/dist/utils/blockchain/index.d.ts.map +1 -0
  166. package/dist/utils/blockchain/index.js +30 -0
  167. package/dist/utils/blockchain/index.js.map +1 -0
  168. package/dist/utils/blockchain/rpc-helpers.cjs +865 -0
  169. package/dist/utils/blockchain/rpc-helpers.d.ts +251 -0
  170. package/dist/utils/blockchain/rpc-helpers.d.ts.map +1 -0
  171. package/dist/utils/blockchain/rpc-helpers.js +865 -0
  172. package/dist/utils/blockchain/rpc-helpers.js.map +1 -0
  173. package/dist/utils/constants/application.cjs +158 -0
  174. package/dist/utils/constants/application.d.ts +119 -0
  175. package/dist/utils/constants/application.d.ts.map +1 -0
  176. package/dist/utils/constants/application.js +158 -0
  177. package/dist/utils/constants/application.js.map +1 -0
  178. package/dist/utils/constants/index.cjs +30 -0
  179. package/dist/utils/constants/index.d.ts +7 -0
  180. package/dist/utils/constants/index.d.ts.map +1 -0
  181. package/dist/utils/constants/index.js +30 -0
  182. package/dist/utils/constants/index.js.map +1 -0
  183. package/dist/utils/constants/status-values.cjs +14 -0
  184. package/dist/utils/constants/status-values.d.ts +12 -0
  185. package/dist/utils/constants/status-values.d.ts.map +1 -0
  186. package/dist/utils/constants/status-values.js +14 -0
  187. package/dist/utils/constants/status-values.js.map +1 -0
  188. package/dist/utils/formatting/currency.cjs +36 -0
  189. package/dist/utils/formatting/currency.d.ts +26 -0
  190. package/dist/utils/formatting/currency.d.ts.map +1 -0
  191. package/dist/utils/formatting/currency.js +36 -0
  192. package/dist/utils/formatting/currency.js.map +1 -0
  193. package/dist/utils/formatting/date.cjs +138 -0
  194. package/dist/utils/formatting/date.d.ts +33 -0
  195. package/dist/utils/formatting/date.d.ts.map +1 -0
  196. package/dist/utils/formatting/date.js +138 -0
  197. package/dist/utils/formatting/date.js.map +1 -0
  198. package/dist/utils/formatting/index.cjs +37 -0
  199. package/dist/utils/formatting/index.d.ts +4 -0
  200. package/dist/utils/formatting/index.d.ts.map +1 -0
  201. package/dist/utils/formatting/index.js +37 -0
  202. package/dist/utils/formatting/index.js.map +1 -0
  203. package/dist/utils/formatting/string.cjs +193 -0
  204. package/dist/utils/formatting/string.d.ts +69 -0
  205. package/dist/utils/formatting/string.d.ts.map +1 -0
  206. package/dist/utils/formatting/string.js +193 -0
  207. package/dist/utils/formatting/string.js.map +1 -0
  208. package/dist/utils/index.cjs +28 -0
  209. package/dist/utils/index.d.ts +12 -0
  210. package/dist/utils/index.d.ts.map +1 -0
  211. package/dist/utils/index.js +28 -0
  212. package/dist/utils/index.js.map +1 -0
  213. package/dist/utils/logging/index.cjs +16 -0
  214. package/dist/utils/logging/index.d.ts +5 -0
  215. package/dist/utils/logging/index.d.ts.map +1 -0
  216. package/dist/utils/logging/index.js +16 -0
  217. package/dist/utils/logging/index.js.map +1 -0
  218. package/dist/utils/logging/logger.cjs +92 -0
  219. package/dist/utils/logging/logger.d.ts +70 -0
  220. package/dist/utils/logging/logger.d.ts.map +1 -0
  221. package/dist/utils/logging/logger.js +92 -0
  222. package/dist/utils/logging/logger.js.map +1 -0
  223. package/dist/utils/url/index.cjs +13 -0
  224. package/dist/utils/url/index.d.ts +5 -0
  225. package/dist/utils/url/index.d.ts.map +1 -0
  226. package/dist/utils/url/index.js +13 -0
  227. package/dist/utils/url/index.js.map +1 -0
  228. package/dist/utils/url/url-params.cjs +128 -0
  229. package/dist/utils/url/url-params.d.ts +36 -0
  230. package/dist/utils/url/url-params.d.ts.map +1 -0
  231. package/dist/utils/url/url-params.js +128 -0
  232. package/dist/utils/url/url-params.js.map +1 -0
  233. package/dist/utils/validation/index.cjs +25 -0
  234. package/dist/utils/validation/index.d.ts +5 -0
  235. package/dist/utils/validation/index.d.ts.map +1 -0
  236. package/dist/utils/validation/index.js +25 -0
  237. package/dist/utils/validation/index.js.map +1 -0
  238. package/dist/utils/validation/type-validation.cjs +167 -0
  239. package/dist/utils/validation/type-validation.d.ts +68 -0
  240. package/dist/utils/validation/type-validation.d.ts.map +1 -0
  241. package/dist/utils/validation/type-validation.js +167 -0
  242. package/dist/utils/validation/type-validation.js.map +1 -0
  243. package/dist/utils/validation/web3-username-validator.cjs +132 -0
  244. package/dist/utils/validation/web3-username-validator.d.ts +43 -0
  245. package/dist/utils/validation/web3-username-validator.d.ts.map +1 -0
  246. package/dist/utils/validation/web3-username-validator.js +132 -0
  247. package/dist/utils/validation/web3-username-validator.js.map +1 -0
  248. package/package.json +80 -0
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateArray = exports.parseJson = exports.optional = exports.isValidDate = exports.isUrl = exports.isSuccessResponse = exports.isString = exports.isObject = exports.isNumber = exports.isNullish = exports.isErrorResponse = exports.isEmail = exports.isBoolean = exports.isArray = exports.isApiResponse = exports.hasRequiredProperties = exports.createValidator = exports.createAssertion = exports.Web3UsernameValidator = void 0;
4
+ var web3_username_validator_1 = require("./web3-username-validator");
5
+ Object.defineProperty(exports, "Web3UsernameValidator", { enumerable: true, get: function () { return web3_username_validator_1.Web3UsernameValidator; } });
6
+ var type_validation_1 = require("./type-validation");
7
+ Object.defineProperty(exports, "createAssertion", { enumerable: true, get: function () { return type_validation_1.createAssertion; } });
8
+ Object.defineProperty(exports, "createValidator", { enumerable: true, get: function () { return type_validation_1.createValidator; } });
9
+ Object.defineProperty(exports, "hasRequiredProperties", { enumerable: true, get: function () { return type_validation_1.hasRequiredProperties; } });
10
+ Object.defineProperty(exports, "isApiResponse", { enumerable: true, get: function () { return type_validation_1.isApiResponse; } });
11
+ Object.defineProperty(exports, "isArray", { enumerable: true, get: function () { return type_validation_1.isArray; } });
12
+ Object.defineProperty(exports, "isBoolean", { enumerable: true, get: function () { return type_validation_1.isBoolean; } });
13
+ Object.defineProperty(exports, "isEmail", { enumerable: true, get: function () { return type_validation_1.isEmail; } });
14
+ Object.defineProperty(exports, "isErrorResponse", { enumerable: true, get: function () { return type_validation_1.isErrorResponse; } });
15
+ Object.defineProperty(exports, "isNullish", { enumerable: true, get: function () { return type_validation_1.isNullish; } });
16
+ Object.defineProperty(exports, "isNumber", { enumerable: true, get: function () { return type_validation_1.isNumber; } });
17
+ Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return type_validation_1.isObject; } });
18
+ Object.defineProperty(exports, "isString", { enumerable: true, get: function () { return type_validation_1.isString; } });
19
+ Object.defineProperty(exports, "isSuccessResponse", { enumerable: true, get: function () { return type_validation_1.isSuccessResponse; } });
20
+ Object.defineProperty(exports, "isUrl", { enumerable: true, get: function () { return type_validation_1.isUrl; } });
21
+ Object.defineProperty(exports, "isValidDate", { enumerable: true, get: function () { return type_validation_1.isValidDate; } });
22
+ Object.defineProperty(exports, "optional", { enumerable: true, get: function () { return type_validation_1.optional; } });
23
+ Object.defineProperty(exports, "parseJson", { enumerable: true, get: function () { return type_validation_1.parseJson; } });
24
+ Object.defineProperty(exports, "validateArray", { enumerable: true, get: function () { return type_validation_1.validateArray; } });
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/validation/index.ts"],"names":[],"mappings":";;;AAGA,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA;AAK9B,qDAmB2B;AAlBzB,kHAAA,eAAe,OAAA;AACf,kHAAA,eAAe,OAAA;AACf,wHAAA,qBAAqB,OAAA;AACrB,gHAAA,aAAa,OAAA;AACb,0GAAA,OAAO,OAAA;AACP,4GAAA,SAAS,OAAA;AACT,0GAAA,OAAO,OAAA;AACP,kHAAA,eAAe,OAAA;AACf,4GAAA,SAAS,OAAA;AACT,2GAAA,QAAQ,OAAA;AACR,2GAAA,QAAQ,OAAA;AACR,2GAAA,QAAQ,OAAA;AACR,oHAAA,iBAAiB,OAAA;AACjB,wGAAA,KAAK,OAAA;AACL,8GAAA,WAAW,OAAA;AACX,2GAAA,QAAQ,OAAA;AACR,4GAAA,SAAS,OAAA;AACT,gHAAA,aAAa,OAAA"}
@@ -0,0 +1,167 @@
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 expected type
12
+ */
13
+ const createValidator = (validationFn, typeName) => {
14
+ return (data) => {
15
+ try {
16
+ if (validationFn(data)) {
17
+ return { isValid: true, data };
18
+ }
19
+ return { isValid: false, error: `Invalid ${typeName}`, data: null };
20
+ }
21
+ catch (error) {
22
+ return {
23
+ isValid: false,
24
+ error: `Validation error for ${typeName}: ${error instanceof Error ? error.message : 'Unknown error'}`,
25
+ data: null,
26
+ };
27
+ }
28
+ };
29
+ };
30
+ exports.createValidator = createValidator;
31
+ /**
32
+ * Basic type validators
33
+ */
34
+ const isString = (value) => typeof value === 'string';
35
+ exports.isString = isString;
36
+ const isNumber = (value) => typeof value === 'number' && !isNaN(value);
37
+ exports.isNumber = isNumber;
38
+ const isBoolean = (value) => typeof value === 'boolean';
39
+ exports.isBoolean = isBoolean;
40
+ const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
41
+ exports.isObject = isObject;
42
+ const isArray = (value) => Array.isArray(value);
43
+ exports.isArray = isArray;
44
+ const isNullish = (value) => value === null || value === undefined;
45
+ exports.isNullish = isNullish;
46
+ /**
47
+ * Validates that an object has required properties
48
+ */
49
+ const hasRequiredProperties = (obj, requiredProps) => {
50
+ if (!(0, exports.isObject)(obj))
51
+ return false;
52
+ return requiredProps.every((prop) => prop in obj);
53
+ };
54
+ exports.hasRequiredProperties = hasRequiredProperties;
55
+ /**
56
+ * Validates array of objects with a validator function
57
+ */
58
+ const validateArray = (data, itemValidator) => {
59
+ if (!(0, exports.isArray)(data))
60
+ return false;
61
+ return data.every(itemValidator);
62
+ };
63
+ exports.validateArray = validateArray;
64
+ /**
65
+ * Creates optional property validator
66
+ */
67
+ const optional = (validator) => (value) => {
68
+ return value === undefined || validator(value);
69
+ };
70
+ exports.optional = optional;
71
+ /**
72
+ * Common pattern validators for API responses
73
+ */
74
+ const isApiResponse = (data) => {
75
+ return (0, exports.isObject)(data) && (0, exports.isBoolean)(data.success);
76
+ };
77
+ exports.isApiResponse = isApiResponse;
78
+ const isSuccessResponse = (data, dataValidator) => {
79
+ if (!(0, exports.isApiResponse)(data) || !data.success)
80
+ return false;
81
+ if (dataValidator && 'data' in data) {
82
+ return dataValidator(data.data);
83
+ }
84
+ return true;
85
+ };
86
+ exports.isSuccessResponse = isSuccessResponse;
87
+ const isErrorResponse = (data) => {
88
+ return ((0, exports.isApiResponse)(data) &&
89
+ !data.success &&
90
+ 'error' in data &&
91
+ (0, exports.isString)(data.error));
92
+ };
93
+ exports.isErrorResponse = isErrorResponse;
94
+ /**
95
+ * Date validation
96
+ */
97
+ const isValidDate = (value) => {
98
+ if (!(0, exports.isString)(value))
99
+ return false;
100
+ const date = new Date(value);
101
+ return !isNaN(date.getTime());
102
+ };
103
+ exports.isValidDate = isValidDate;
104
+ /**
105
+ * Email validation (basic)
106
+ */
107
+ const isEmail = (value) => {
108
+ if (!(0, exports.isString)(value))
109
+ return false;
110
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
111
+ return emailRegex.test(value);
112
+ };
113
+ exports.isEmail = isEmail;
114
+ /**
115
+ * URL validation (basic)
116
+ */
117
+ const isUrl = (value) => {
118
+ if (!(0, exports.isString)(value))
119
+ return false;
120
+ try {
121
+ new URL(value);
122
+ return true;
123
+ }
124
+ catch {
125
+ return false;
126
+ }
127
+ };
128
+ exports.isUrl = isUrl;
129
+ /**
130
+ * Creates a type assertion function that throws on invalid data
131
+ */
132
+ const createAssertion = (validator, typeName) => {
133
+ return (data, context = typeName) => {
134
+ if (!validator(data)) {
135
+ throw new TypeError(`Invalid ${context}: expected ${typeName}`);
136
+ }
137
+ };
138
+ };
139
+ exports.createAssertion = createAssertion;
140
+ /**
141
+ * Safe JSON parsing with validation
142
+ */
143
+ const parseJson = (jsonString, validator) => {
144
+ try {
145
+ const parsed = JSON.parse(jsonString);
146
+ if (validator) {
147
+ if (validator(parsed)) {
148
+ return { isValid: true, data: parsed };
149
+ }
150
+ return {
151
+ isValid: false,
152
+ error: 'Parsed JSON does not match expected type',
153
+ data: null,
154
+ };
155
+ }
156
+ return { isValid: true, data: parsed };
157
+ }
158
+ catch (error) {
159
+ return {
160
+ isValid: false,
161
+ error: `JSON parse error: ${error instanceof Error ? error.message : 'Unknown error'}`,
162
+ data: null,
163
+ };
164
+ }
165
+ };
166
+ exports.parseJson = parseJson;
167
+ //# sourceMappingURL=type-validation.js.map
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Type validation utilities for runtime type checking
3
+ *
4
+ * These utilities help ensure type safety at runtime, especially useful
5
+ * for validating API responses and external data.
6
+ */
7
+ import type { ValidationResult, Optional } from '../../types/common';
8
+ export type { ValidationResult };
9
+ /**
10
+ * Creates a validation function that safely checks if a value matches expected type
11
+ */
12
+ export declare const createValidator: <T>(validationFn: (data: unknown) => data is T, typeName: string) => (data: unknown) => ValidationResult<T>;
13
+ /**
14
+ * Basic type validators
15
+ */
16
+ export declare const isString: (value: unknown) => value is string;
17
+ export declare const isNumber: (value: unknown) => value is number;
18
+ export declare const isBoolean: (value: unknown) => value is boolean;
19
+ export declare const isObject: (value: unknown) => value is Record<string, unknown>;
20
+ export declare const isArray: (value: unknown) => value is unknown[];
21
+ export declare const isNullish: (value: unknown) => value is null | undefined;
22
+ /**
23
+ * Validates that an object has required properties
24
+ */
25
+ export declare const hasRequiredProperties: <T extends Record<string, unknown>>(obj: unknown, requiredProps: (keyof T)[]) => obj is T;
26
+ /**
27
+ * Validates array of objects with a validator function
28
+ */
29
+ export declare const validateArray: <T>(data: unknown, itemValidator: (item: unknown) => item is T) => data is T[];
30
+ /**
31
+ * Creates optional property validator
32
+ */
33
+ export declare const optional: <T>(validator: (value: unknown) => value is T) => (value: unknown) => value is T | undefined;
34
+ /**
35
+ * Common pattern validators for API responses
36
+ */
37
+ export declare const isApiResponse: (data: unknown) => data is {
38
+ success: boolean;
39
+ };
40
+ export declare const isSuccessResponse: <T>(data: unknown, dataValidator?: Optional<(value: unknown) => value is T>) => data is {
41
+ success: true;
42
+ data: T;
43
+ };
44
+ export declare const isErrorResponse: (data: unknown) => data is {
45
+ success: false;
46
+ error: string;
47
+ };
48
+ /**
49
+ * Date validation
50
+ */
51
+ export declare const isValidDate: (value: unknown) => value is string;
52
+ /**
53
+ * Email validation (basic)
54
+ */
55
+ export declare const isEmail: (value: unknown) => value is string;
56
+ /**
57
+ * URL validation (basic)
58
+ */
59
+ export declare const isUrl: (value: unknown) => value is string;
60
+ /**
61
+ * Creates a type assertion function that throws on invalid data
62
+ */
63
+ export declare const createAssertion: <T>(validator: (data: unknown) => data is T, typeName: string) => (data: unknown, context?: string) => asserts data is T;
64
+ /**
65
+ * Safe JSON parsing with validation
66
+ */
67
+ export declare const parseJson: <T>(jsonString: string, validator?: Optional<(data: unknown) => data is T>) => ValidationResult<T>;
68
+ //# sourceMappingURL=type-validation.d.ts.map
@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IAAI,EAAE,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,KACjD,gBAAgB,CAAC,CAAC,CAqBpB,CAAC"}
@@ -0,0 +1,167 @@
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 expected type
12
+ */
13
+ const createValidator = (validationFn, typeName) => {
14
+ return (data) => {
15
+ try {
16
+ if (validationFn(data)) {
17
+ return { isValid: true, data };
18
+ }
19
+ return { isValid: false, error: `Invalid ${typeName}`, data: null };
20
+ }
21
+ catch (error) {
22
+ return {
23
+ isValid: false,
24
+ error: `Validation error for ${typeName}: ${error instanceof Error ? error.message : 'Unknown error'}`,
25
+ data: null,
26
+ };
27
+ }
28
+ };
29
+ };
30
+ exports.createValidator = createValidator;
31
+ /**
32
+ * Basic type validators
33
+ */
34
+ const isString = (value) => typeof value === 'string';
35
+ exports.isString = isString;
36
+ const isNumber = (value) => typeof value === 'number' && !isNaN(value);
37
+ exports.isNumber = isNumber;
38
+ const isBoolean = (value) => typeof value === 'boolean';
39
+ exports.isBoolean = isBoolean;
40
+ const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
41
+ exports.isObject = isObject;
42
+ const isArray = (value) => Array.isArray(value);
43
+ exports.isArray = isArray;
44
+ const isNullish = (value) => value === null || value === undefined;
45
+ exports.isNullish = isNullish;
46
+ /**
47
+ * Validates that an object has required properties
48
+ */
49
+ const hasRequiredProperties = (obj, requiredProps) => {
50
+ if (!(0, exports.isObject)(obj))
51
+ return false;
52
+ return requiredProps.every((prop) => prop in obj);
53
+ };
54
+ exports.hasRequiredProperties = hasRequiredProperties;
55
+ /**
56
+ * Validates array of objects with a validator function
57
+ */
58
+ const validateArray = (data, itemValidator) => {
59
+ if (!(0, exports.isArray)(data))
60
+ return false;
61
+ return data.every(itemValidator);
62
+ };
63
+ exports.validateArray = validateArray;
64
+ /**
65
+ * Creates optional property validator
66
+ */
67
+ const optional = (validator) => (value) => {
68
+ return value === undefined || validator(value);
69
+ };
70
+ exports.optional = optional;
71
+ /**
72
+ * Common pattern validators for API responses
73
+ */
74
+ const isApiResponse = (data) => {
75
+ return (0, exports.isObject)(data) && (0, exports.isBoolean)(data.success);
76
+ };
77
+ exports.isApiResponse = isApiResponse;
78
+ const isSuccessResponse = (data, dataValidator) => {
79
+ if (!(0, exports.isApiResponse)(data) || !data.success)
80
+ return false;
81
+ if (dataValidator && 'data' in data) {
82
+ return dataValidator(data.data);
83
+ }
84
+ return true;
85
+ };
86
+ exports.isSuccessResponse = isSuccessResponse;
87
+ const isErrorResponse = (data) => {
88
+ return ((0, exports.isApiResponse)(data) &&
89
+ !data.success &&
90
+ 'error' in data &&
91
+ (0, exports.isString)(data.error));
92
+ };
93
+ exports.isErrorResponse = isErrorResponse;
94
+ /**
95
+ * Date validation
96
+ */
97
+ const isValidDate = (value) => {
98
+ if (!(0, exports.isString)(value))
99
+ return false;
100
+ const date = new Date(value);
101
+ return !isNaN(date.getTime());
102
+ };
103
+ exports.isValidDate = isValidDate;
104
+ /**
105
+ * Email validation (basic)
106
+ */
107
+ const isEmail = (value) => {
108
+ if (!(0, exports.isString)(value))
109
+ return false;
110
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
111
+ return emailRegex.test(value);
112
+ };
113
+ exports.isEmail = isEmail;
114
+ /**
115
+ * URL validation (basic)
116
+ */
117
+ const isUrl = (value) => {
118
+ if (!(0, exports.isString)(value))
119
+ return false;
120
+ try {
121
+ new URL(value);
122
+ return true;
123
+ }
124
+ catch {
125
+ return false;
126
+ }
127
+ };
128
+ exports.isUrl = isUrl;
129
+ /**
130
+ * Creates a type assertion function that throws on invalid data
131
+ */
132
+ const createAssertion = (validator, typeName) => {
133
+ return (data, context = typeName) => {
134
+ if (!validator(data)) {
135
+ throw new TypeError(`Invalid ${context}: expected ${typeName}`);
136
+ }
137
+ };
138
+ };
139
+ exports.createAssertion = createAssertion;
140
+ /**
141
+ * Safe JSON parsing with validation
142
+ */
143
+ const parseJson = (jsonString, validator) => {
144
+ try {
145
+ const parsed = JSON.parse(jsonString);
146
+ if (validator) {
147
+ if (validator(parsed)) {
148
+ return { isValid: true, data: parsed };
149
+ }
150
+ return {
151
+ isValid: false,
152
+ error: 'Parsed JSON does not match expected type',
153
+ data: null,
154
+ };
155
+ }
156
+ return { isValid: true, data: parsed };
157
+ }
158
+ catch (error) {
159
+ return {
160
+ isValid: false,
161
+ error: `JSON parse error: ${error instanceof Error ? error.message : 'Unknown error'}`,
162
+ data: null,
163
+ };
164
+ }
165
+ };
166
+ exports.parseJson = parseJson;
167
+ //# sourceMappingURL=type-validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-validation.js","sourceRoot":"","sources":["../../../src/utils/validation/type-validation.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAOH;;GAEG;AACI,MAAM,eAAe,GAAG,CAC7B,YAA0C,EAC1C,QAAgB,EAChB,EAAE;IACF,OAAO,CAAC,IAAa,EAAuB,EAAE;QAC5C,IAAI,CAAC;YACH,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;gBACvB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;YACjC,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QACtE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,O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AS,CAAC,IAAI,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,SAAS,CAAC,WAAW,OAAO,cAAc,QAAQ,EAAE,CAAC,CAAC;QAClE,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,eAAe,mBAS1B;AAEF;;GAEG;AACI,MAAM,SAAS,GAAG,CACvB,UAAkB,EAClB,SAAkD,EAC7B,EAAE;IACvB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QACtC,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;gBACtB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;YACzC,CAAC;YACD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,0CAA0C;gBACjD,IAAI,EAAE,IAAI;aACX,CAAC;QACJ,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAW,EAAE,CAAC;IAC9C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,qBAAqB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE;YACtF,IAAI,EAAE,IAAI;SACX,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAxBW,QAAA,SAAS,aAwBpB"}
@@ -0,0 +1,132 @@
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
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @fileoverview Address Validation Utility
3
+ * @description Centralized address validation for EVM, Solana, ENS, and SNS addresses
4
+ * Eliminates code duplication across multiple files
5
+ *
6
+ * Pure TypeScript implementation with no external dependencies
7
+ */
8
+ import { ChainType } from '../../types/business/enums';
9
+ import { Optional } from '../../types/common';
10
+ export interface AddressValidationResult {
11
+ name?: Optional<string>;
12
+ address?: Optional<string>;
13
+ chainType: ChainType;
14
+ }
15
+ export declare class Web3UsernameValidator {
16
+ private static readonly EVM_REGEX;
17
+ private static readonly BASE58_REGEX;
18
+ private static readonly ENS_REGEX;
19
+ private static readonly SNS_NAME_REGEX;
20
+ private static readonly VALID_SNS_TLDS;
21
+ /**
22
+ * Comprehensive address validation for API endpoint
23
+ * Returns AddressValidationResult for valid addresses, undefined for invalid ones
24
+ */
25
+ static validate(address: string): Optional<AddressValidationResult>;
26
+ /**
27
+ * Quick EVM address validation
28
+ */
29
+ static isValidEVMAddress(address: string): boolean;
30
+ /**
31
+ * Quick Solana address validation
32
+ */
33
+ static isValidSolanaAddress(address: string): boolean;
34
+ /**
35
+ * Quick ENS name validation
36
+ */
37
+ static isValidENSName(address: string): boolean;
38
+ /**
39
+ * Quick SNS name validation
40
+ */
41
+ static isValidSNSName(address: string): boolean;
42
+ }
43
+ //# sourceMappingURL=web3-username-validator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web3-username-validator.d.ts","sourceRoot":"","sources":["../../../src/utils/validation/web3-username-validator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MAAM,WAAW,uBAAuB;IACtC,IAAI,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxB,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3B,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,qBAAa,qBAAqB;IAEhC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAyB;IAC1D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAA6B;IACjE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAC0B;IAC3D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CACS;IAG/C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAcpC;IAEF;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAAC,uBAAuB,CAAC;IAiEnE;;OAEG;IACH,MAAM,CAAC,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIlD;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IASrD;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAS/C;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;CAWhD"}