@dalmore/api-contracts 1.0.3 → 1.0.6

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 (186) hide show
  1. package/README.md +34 -60
  2. package/index.mjs +1001 -18638
  3. package/package.json +5 -53
  4. package/src/common/types/address.spec.ts +203 -0
  5. package/src/common/types/batch-jobs.types.ts +1 -0
  6. package/src/common/types/common.types.spec.ts +336 -0
  7. package/src/common/types/files.types.spec.ts +154 -0
  8. package/src/common/types/issuer-payment-method.types.spec.ts +612 -0
  9. package/src/common/types/offering.types.spec.ts +91 -0
  10. package/src/common/types/phone.spec.ts +76 -0
  11. package/src/common/types/queue.types.ts +1 -0
  12. package/src/common/types/reminder-config.types.ts +40 -0
  13. package/src/common/types/site-link.types.spec.ts +134 -0
  14. package/src/common/types/trade.types.ts +2 -4
  15. package/clients/index.mjs +0 -10970
  16. package/compliance/index.mjs +0 -20016
  17. package/compliance-apikey/index.mjs +0 -9795
  18. package/helpers/index.mjs +0 -146
  19. package/investors/index.mjs +0 -12844
  20. package/issuers/index.mjs +0 -16168
  21. package/secondaries/index.mjs +0 -10282
  22. package/src/common/helpers/index.ts +0 -205
  23. package/src/contracts/compliance/account-contacts/index.ts +0 -82
  24. package/src/contracts/compliance/account-managers/index.ts +0 -142
  25. package/src/contracts/compliance/accounts/index.ts +0 -187
  26. package/src/contracts/compliance/activities/index.ts +0 -55
  27. package/src/contracts/compliance/aic/index.ts +0 -60
  28. package/src/contracts/compliance/api-keys/index.ts +0 -91
  29. package/src/contracts/compliance/assets/index.ts +0 -122
  30. package/src/contracts/compliance/auth/index.ts +0 -134
  31. package/src/contracts/compliance/batch-jobs/index.ts +0 -62
  32. package/src/contracts/compliance/bonus-tiers/index.ts +0 -55
  33. package/src/contracts/compliance/checklist/index.ts +0 -87
  34. package/src/contracts/compliance/checklist-items/index.ts +0 -86
  35. package/src/contracts/compliance/covered-persons/index.ts +0 -97
  36. package/src/contracts/compliance/dashboard/index.ts +0 -111
  37. package/src/contracts/compliance/data-records/index.ts +0 -116
  38. package/src/contracts/compliance/data-rooms/index.ts +0 -113
  39. package/src/contracts/compliance/default-theme-configs/index.ts +0 -95
  40. package/src/contracts/compliance/disbursement/index.ts +0 -165
  41. package/src/contracts/compliance/disbursement-approval-users/index.ts +0 -84
  42. package/src/contracts/compliance/disbursement-transactions/index.ts +0 -37
  43. package/src/contracts/compliance/domain-filters/index.ts +0 -117
  44. package/src/contracts/compliance/email-themes/index.ts +0 -284
  45. package/src/contracts/compliance/escrow-accounts/index.ts +0 -85
  46. package/src/contracts/compliance/exchange-api-keys/index.ts +0 -129
  47. package/src/contracts/compliance/exchange-imports/index.ts +0 -137
  48. package/src/contracts/compliance/files/index.ts +0 -267
  49. package/src/contracts/compliance/files-public/index.ts +0 -188
  50. package/src/contracts/compliance/health/index.ts +0 -26
  51. package/src/contracts/compliance/index.ts +0 -147
  52. package/src/contracts/compliance/individuals/index.ts +0 -57
  53. package/src/contracts/compliance/investor-accounts/index.ts +0 -141
  54. package/src/contracts/compliance/invites/index.ts +0 -137
  55. package/src/contracts/compliance/issuer-bank-accounts/index.ts +0 -81
  56. package/src/contracts/compliance/issuer-payment-methods/index.ts +0 -81
  57. package/src/contracts/compliance/issuers/index.ts +0 -97
  58. package/src/contracts/compliance/job-items/index.ts +0 -58
  59. package/src/contracts/compliance/jobs/index.ts +0 -59
  60. package/src/contracts/compliance/kyb/index.ts +0 -54
  61. package/src/contracts/compliance/kyc/index.ts +0 -77
  62. package/src/contracts/compliance/legal-entities/index.ts +0 -57
  63. package/src/contracts/compliance/login-histories/index.ts +0 -37
  64. package/src/contracts/compliance/notes/index.ts +0 -69
  65. package/src/contracts/compliance/notion-databases/index.ts +0 -107
  66. package/src/contracts/compliance/notion-pages/index.ts +0 -105
  67. package/src/contracts/compliance/offering-reports/index.ts +0 -149
  68. package/src/contracts/compliance/offerings/index.ts +0 -233
  69. package/src/contracts/compliance/pages/index.ts +0 -178
  70. package/src/contracts/compliance/payment-methods/index.ts +0 -57
  71. package/src/contracts/compliance/rejection-reasons/index.ts +0 -32
  72. package/src/contracts/compliance/review/index.ts +0 -169
  73. package/src/contracts/compliance/roles/index.ts +0 -34
  74. package/src/contracts/compliance/secondary-customers/index.ts +0 -77
  75. package/src/contracts/compliance/secondary-orders/index.ts +0 -60
  76. package/src/contracts/compliance/secondary-trades/index.ts +0 -100
  77. package/src/contracts/compliance/secure-requests/index.ts +0 -54
  78. package/src/contracts/compliance/signer/index.ts +0 -369
  79. package/src/contracts/compliance/site-links/index.ts +0 -128
  80. package/src/contracts/compliance/site-settings/index.ts +0 -669
  81. package/src/contracts/compliance/sites/index.ts +0 -56
  82. package/src/contracts/compliance/state-machine/index.ts +0 -94
  83. package/src/contracts/compliance/tasks/index.ts +0 -91
  84. package/src/contracts/compliance/third-parties/index.ts +0 -52
  85. package/src/contracts/compliance/trade-line-items/index.ts +0 -59
  86. package/src/contracts/compliance/trades/index.ts +0 -230
  87. package/src/contracts/compliance/transactions/index.ts +0 -161
  88. package/src/contracts/compliance/user-manuals/index.ts +0 -271
  89. package/src/contracts/compliance/user-settings/index.ts +0 -189
  90. package/src/contracts/compliance/users/index.ts +0 -200
  91. package/src/contracts/compliance/webhooks/index.ts +0 -41
  92. package/src/contracts/compliance-apikey/accounts/index.ts +0 -58
  93. package/src/contracts/compliance-apikey/index.ts +0 -14
  94. package/src/contracts/index.ts +0 -6
  95. package/src/contracts/investors/account-contacts/index.ts +0 -58
  96. package/src/contracts/investors/aic/index.ts +0 -59
  97. package/src/contracts/investors/assets/index.ts +0 -61
  98. package/src/contracts/investors/auth/index.ts +0 -116
  99. package/src/contracts/investors/bonus-tiers/index.ts +0 -37
  100. package/src/contracts/investors/cart/index.ts +0 -75
  101. package/src/contracts/investors/contact-us/index.ts +0 -48
  102. package/src/contracts/investors/data-records/index.ts +0 -113
  103. package/src/contracts/investors/data-rooms/index.ts +0 -96
  104. package/src/contracts/investors/files/index.ts +0 -167
  105. package/src/contracts/investors/files-public/index.ts +0 -185
  106. package/src/contracts/investors/index.ts +0 -72
  107. package/src/contracts/investors/individuals/index.ts +0 -99
  108. package/src/contracts/investors/investor-accounts/index.ts +0 -110
  109. package/src/contracts/investors/issuer-payment-methods/index.ts +0 -36
  110. package/src/contracts/investors/issuers/index.ts +0 -30
  111. package/src/contracts/investors/legal-entities/index.ts +0 -93
  112. package/src/contracts/investors/notes/index.ts +0 -69
  113. package/src/contracts/investors/offerings/index.ts +0 -93
  114. package/src/contracts/investors/pages/index.ts +0 -88
  115. package/src/contracts/investors/payment-methods/index.ts +0 -149
  116. package/src/contracts/investors/portfolios/index.ts +0 -53
  117. package/src/contracts/investors/sites/index.ts +0 -96
  118. package/src/contracts/investors/tasks/index.ts +0 -111
  119. package/src/contracts/investors/trade-line-items/index.ts +0 -75
  120. package/src/contracts/investors/trades/index.ts +0 -114
  121. package/src/contracts/investors/transactions/index.ts +0 -37
  122. package/src/contracts/investors/trusted-contacts/index.ts +0 -93
  123. package/src/contracts/investors/user-manuals/index.ts +0 -62
  124. package/src/contracts/investors/user-settings/index.ts +0 -170
  125. package/src/contracts/investors/users/index.ts +0 -45
  126. package/src/contracts/investors/webhooks/index.ts +0 -30
  127. package/src/contracts/issuers/account-contacts/index.ts +0 -76
  128. package/src/contracts/issuers/account-integrations/index.ts +0 -97
  129. package/src/contracts/issuers/accounts/index.ts +0 -97
  130. package/src/contracts/issuers/activities/index.ts +0 -54
  131. package/src/contracts/issuers/aic/index.ts +0 -39
  132. package/src/contracts/issuers/api-key-logs/index.ts +0 -53
  133. package/src/contracts/issuers/api-keys/index.ts +0 -93
  134. package/src/contracts/issuers/assets/index.ts +0 -122
  135. package/src/contracts/issuers/auth/index.ts +0 -152
  136. package/src/contracts/issuers/bonus-tiers/index.ts +0 -55
  137. package/src/contracts/issuers/contact-us/index.ts +0 -48
  138. package/src/contracts/issuers/covered-persons/index.ts +0 -136
  139. package/src/contracts/issuers/dashboard/index.ts +0 -72
  140. package/src/contracts/issuers/data-records/index.ts +0 -257
  141. package/src/contracts/issuers/data-rooms/index.ts +0 -134
  142. package/src/contracts/issuers/disbursement-approval-users/index.ts +0 -82
  143. package/src/contracts/issuers/disbursement-transactions/index.ts +0 -53
  144. package/src/contracts/issuers/disbursements/index.ts +0 -153
  145. package/src/contracts/issuers/email-themes/index.ts +0 -242
  146. package/src/contracts/issuers/escrow-accounts/index.ts +0 -81
  147. package/src/contracts/issuers/exchange-api-keys/index.ts +0 -144
  148. package/src/contracts/issuers/files/index.ts +0 -166
  149. package/src/contracts/issuers/files-public/index.ts +0 -166
  150. package/src/contracts/issuers/health/index.ts +0 -24
  151. package/src/contracts/issuers/index.ts +0 -112
  152. package/src/contracts/issuers/investor-accounts/index.ts +0 -148
  153. package/src/contracts/issuers/invites/index.ts +0 -129
  154. package/src/contracts/issuers/issuer/index.ts +0 -94
  155. package/src/contracts/issuers/issuer-bank-accounts/index.ts +0 -81
  156. package/src/contracts/issuers/issuer-payment-methods/index.ts +0 -136
  157. package/src/contracts/issuers/kyc/index.ts +0 -38
  158. package/src/contracts/issuers/login-histories/index.ts +0 -51
  159. package/src/contracts/issuers/notes/index.ts +0 -69
  160. package/src/contracts/issuers/offerings/index.ts +0 -206
  161. package/src/contracts/issuers/pages/index.ts +0 -138
  162. package/src/contracts/issuers/payment-methods/index.ts +0 -61
  163. package/src/contracts/issuers/portfolios/index.ts +0 -36
  164. package/src/contracts/issuers/rejection-reasons/index.ts +0 -32
  165. package/src/contracts/issuers/review/index.ts +0 -63
  166. package/src/contracts/issuers/secondary-customers/index.ts +0 -55
  167. package/src/contracts/issuers/secondary-orders/index.ts +0 -57
  168. package/src/contracts/issuers/secondary-trades/index.ts +0 -57
  169. package/src/contracts/issuers/secure-requests/index.ts +0 -34
  170. package/src/contracts/issuers/site-links/index.ts +0 -116
  171. package/src/contracts/issuers/site-settings/index.ts +0 -585
  172. package/src/contracts/issuers/sites/index.ts +0 -32
  173. package/src/contracts/issuers/tasks/index.ts +0 -111
  174. package/src/contracts/issuers/trades/index.ts +0 -132
  175. package/src/contracts/issuers/transactions/index.ts +0 -158
  176. package/src/contracts/issuers/user-manuals/index.ts +0 -62
  177. package/src/contracts/issuers/user-settings/index.ts +0 -170
  178. package/src/contracts/issuers/users/index.ts +0 -126
  179. package/src/contracts/secondaries/accounts/index.ts +0 -58
  180. package/src/contracts/secondaries/index.ts +0 -23
  181. package/src/contracts/secondaries/secondary-customers/index.ts +0 -55
  182. package/src/contracts/secondaries/secondary-issuers/index.ts +0 -94
  183. package/src/contracts/secondaries/secondary-orders/index.ts +0 -56
  184. package/src/contracts/secondaries/secondary-securities/index.ts +0 -95
  185. package/src/contracts/secondaries/secondary-trades/index.ts +0 -56
  186. package/types/index.mjs +0 -10320
package/package.json CHANGED
@@ -1,67 +1,19 @@
1
1
  {
2
2
  "name": "@dalmore/api-contracts",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "Type-safe API contracts for Dalmore Client Portal",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",
7
- "types": "./src/contracts/index.ts",
7
+ "types": "./src/contracts/clients/index.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "types": "./src/contracts/index.ts",
10
+ "types": "./src/contracts/clients/index.ts",
11
11
  "import": "./index.mjs",
12
12
  "default": "./index.mjs"
13
- },
14
- "./compliance": {
15
- "types": "./src/contracts/compliance/index.ts",
16
- "import": "./compliance/index.mjs",
17
- "default": "./compliance/index.mjs"
18
- },
19
- "./investors": {
20
- "types": "./src/contracts/investors/index.ts",
21
- "import": "./investors/index.mjs",
22
- "default": "./investors/index.mjs"
23
- },
24
- "./issuers": {
25
- "types": "./src/contracts/issuers/index.ts",
26
- "import": "./issuers/index.mjs",
27
- "default": "./issuers/index.mjs"
28
- },
29
- "./clients": {
30
- "types": "./src/contracts/clients/index.ts",
31
- "import": "./clients/index.mjs",
32
- "default": "./clients/index.mjs"
33
- },
34
- "./secondaries": {
35
- "types": "./src/contracts/secondaries/index.ts",
36
- "import": "./secondaries/index.mjs",
37
- "default": "./secondaries/index.mjs"
38
- },
39
- "./compliance-apikey": {
40
- "types": "./src/contracts/compliance-apikey/index.ts",
41
- "import": "./compliance-apikey/index.mjs",
42
- "default": "./compliance-apikey/index.mjs"
43
- },
44
- "./types": {
45
- "types": "./src/common/types/index.ts",
46
- "import": "./types/index.mjs",
47
- "default": "./types/index.mjs"
48
- },
49
- "./helpers": {
50
- "types": "./src/common/helpers/index.ts",
51
- "import": "./helpers/index.mjs",
52
- "default": "./helpers/index.mjs"
53
13
  }
54
14
  },
55
15
  "files": [
56
- "*.mjs",
57
- "compliance",
58
- "investors",
59
- "issuers",
60
- "clients",
61
- "secondaries",
62
- "compliance-apikey",
63
- "types",
64
- "helpers",
16
+ "index.mjs",
65
17
  "src"
66
18
  ],
67
19
  "keywords": [
@@ -90,6 +42,6 @@
90
42
  "zod": "^3.24.4"
91
43
  },
92
44
  "engines": {
93
- "node": ">=18.0.0"
45
+ "node": ">=24.0.0 <25.0.0"
94
46
  }
95
47
  }
@@ -0,0 +1,203 @@
1
+ import { createAddress } from '../../tests/factory/address.factory';
2
+ import { AddressSchema } from './address.types';
3
+
4
+ describe('AddressSchema Tests', () => {
5
+ it('should fail if counry is not valid', () => {
6
+ const address = createAddress({
7
+ country: 'eg',
8
+ });
9
+ const parseRes = AddressSchema.safeParse(address);
10
+
11
+ const result = parseRes.success;
12
+ expect(result).toBeFalsy();
13
+ });
14
+
15
+ it('should succeed if counry is valid', () => {
16
+ const address = createAddress({
17
+ country: 'CA',
18
+ zip: 'A1A 1A1',
19
+ state: 'AB',
20
+ });
21
+ const parseRes = AddressSchema.safeParse(address);
22
+
23
+ const result = parseRes.success;
24
+ expect(result).toBeTruthy();
25
+ });
26
+
27
+ it('should fail if CANADA state is not valid', () => {
28
+ const address = createAddress({
29
+ country: 'CA',
30
+ zip: 'A1A 1A1',
31
+ state: 'AS',
32
+ });
33
+ const parseRes = AddressSchema.safeParse(address);
34
+
35
+ const result = parseRes.success;
36
+ expect(result).toBeFalsy();
37
+ });
38
+
39
+ it('should succeed if CANADA state is valid', () => {
40
+ const address = createAddress({
41
+ country: 'CA',
42
+ zip: 'A1A 1A1',
43
+ state: 'AB',
44
+ });
45
+ const parseRes = AddressSchema.safeParse(address);
46
+
47
+ const result = parseRes.success;
48
+ expect(result).toBeTruthy();
49
+ });
50
+
51
+ it('should fail if CANADA state is not valid', () => {
52
+ const address = createAddress({
53
+ country: 'CA',
54
+ zip: '12345',
55
+ state: 'AS',
56
+ });
57
+ const parseRes = AddressSchema.safeParse(address);
58
+
59
+ const result = parseRes.success;
60
+ expect(result).toBeFalsy();
61
+ });
62
+
63
+ it('should succeed if CANADA zip is valid', () => {
64
+ const address = createAddress({
65
+ country: 'CA',
66
+ zip: 'A1A 1A1',
67
+ state: 'AB',
68
+ });
69
+ const parseRes = AddressSchema.safeParse(address);
70
+
71
+ const result = parseRes.success;
72
+ expect(result).toBeTruthy();
73
+ });
74
+
75
+ it('should fail if US state is not valid', () => {
76
+ const address = createAddress({
77
+ country: 'US',
78
+ zip: '12345',
79
+ state: 'CS',
80
+ });
81
+ const parseRes = AddressSchema.safeParse(address);
82
+
83
+ const result = parseRes.success;
84
+ expect(result).toBeFalsy();
85
+ });
86
+
87
+ it('should succeed if US state is valid', () => {
88
+ const address = createAddress({
89
+ country: 'US',
90
+ zip: '12345',
91
+ state: 'CA',
92
+ });
93
+ const parseRes = AddressSchema.safeParse(address);
94
+
95
+ const result = parseRes.success;
96
+ expect(result).toBeTruthy();
97
+ });
98
+
99
+ it('should fail if US zip is not valid', () => {
100
+ const address = createAddress({
101
+ country: 'US',
102
+ zip: '12345 d',
103
+ state: 'CS',
104
+ });
105
+ const parseRes = AddressSchema.safeParse(address);
106
+
107
+ const result = parseRes.success;
108
+ expect(result).toBeFalsy();
109
+ });
110
+
111
+ it('should succeed if US zip is valid', () => {
112
+ const address = createAddress({
113
+ country: 'US',
114
+ zip: '12345',
115
+ state: 'CA',
116
+ });
117
+ const parseRes = AddressSchema.safeParse(address);
118
+
119
+ const result = parseRes.success;
120
+ expect(result).toBeTruthy();
121
+ });
122
+
123
+ it('should fail if state is not valid, state(min=2,max=35)', () => {
124
+ const address = createAddress({
125
+ country: 'EG',
126
+ zip: '12345',
127
+ state: 'Alex Cairo Tanta Hurgada Dahb Luxor Aswan Sharm ', // length 48
128
+ });
129
+ const parseRes = AddressSchema.safeParse(address);
130
+
131
+ const result = parseRes.success;
132
+ expect(result).toBeFalsy();
133
+ });
134
+
135
+ it('should fail if state is not valid', () => {
136
+ const address = createAddress({
137
+ country: 'EG',
138
+ zip: '12345',
139
+ state: 'A',
140
+ });
141
+ const parseRes = AddressSchema.safeParse(address);
142
+
143
+ const result = parseRes.success;
144
+ expect(result).toBeFalsy();
145
+ });
146
+
147
+ it('should succeed if state is valid', () => {
148
+ const address = createAddress({
149
+ country: 'EG',
150
+ zip: '12345',
151
+ state: 'Alexandria',
152
+ });
153
+ const parseRes = AddressSchema.safeParse(address);
154
+
155
+ const result = parseRes.success;
156
+ expect(result).toBeTruthy();
157
+ });
158
+
159
+ it('should fail if zip is not valid', () => {
160
+ const address = createAddress({
161
+ country: 'EG',
162
+ zip: '1',
163
+ state: 'Cairo',
164
+ });
165
+ const parseRes = AddressSchema.safeParse(address);
166
+
167
+ const result = parseRes.success;
168
+ expect(result).toBeFalsy();
169
+ });
170
+
171
+ it('should succeed if zip is valid', () => {
172
+ const address = createAddress({
173
+ country: 'EG',
174
+ zip: '12345678',
175
+ state: 'Cairo',
176
+ });
177
+ const parseRes = AddressSchema.safeParse(address);
178
+
179
+ const result = parseRes.success;
180
+ expect(result).toBeTruthy();
181
+ });
182
+
183
+ it('should succeed if zip is optional', () => {
184
+ const address = createAddress({
185
+ country: 'EG',
186
+ state: 'Cairo',
187
+ });
188
+ const parseRes = AddressSchema.safeParse(address);
189
+
190
+ const result = parseRes.success;
191
+ expect(result).toBeTruthy();
192
+ });
193
+
194
+ it('should succeed if state is optional', () => {
195
+ const address = createAddress({
196
+ country: 'EG',
197
+ });
198
+ const parseRes = AddressSchema.safeParse(address);
199
+
200
+ const result = parseRes.success;
201
+ expect(result).toBeTruthy();
202
+ });
203
+ });
@@ -5,6 +5,7 @@ import { dateSchema, IPaginationMeta, UserRole } from './common.types';
5
5
  import { userIdSchema } from './user.types';
6
6
  import { accountIdSchema } from './account.types';
7
7
  import { IBaseEntity } from './entity.types';
8
+ import { JobsOptions } from 'bullmq';
8
9
 
9
10
  extendZodWithOpenApi(z);
10
11
 
@@ -0,0 +1,336 @@
1
+ import { PaginationOptionsZod, numberPrecisionSchema } from './common.types';
2
+ import { z } from 'zod';
3
+
4
+ describe('PaginationOptionsZod', () => {
5
+ it('should use default values when no values are provided', () => {
6
+ const result = PaginationOptionsZod.parse({});
7
+ expect(result).toEqual({ page: 1, limit: 10 });
8
+ });
9
+
10
+ it('should use provided values when they are valid', () => {
11
+ const result = PaginationOptionsZod.parse({ page: 2, limit: 20 });
12
+ expect(result).toEqual({ page: 2, limit: 20 });
13
+ });
14
+
15
+ it('should transform page 0 to page 1', () => {
16
+ const result = PaginationOptionsZod.parse({ page: 0 });
17
+ expect(result).toEqual({ page: 1, limit: 10 });
18
+ });
19
+
20
+ it('should transform limit 0 to limit 10', () => {
21
+ const result = PaginationOptionsZod.parse({ limit: 0 });
22
+ expect(result).toEqual({ page: 1, limit: 10 });
23
+ });
24
+
25
+ it('should coerce string values to numbers', () => {
26
+ const result = PaginationOptionsZod.parse({ page: '3', limit: '15' });
27
+ expect(result).toEqual({ page: 3, limit: 15 });
28
+ });
29
+
30
+ it('should handle negative values without transformation', () => {
31
+ const result = PaginationOptionsZod.parse({ page: -1, limit: -5 });
32
+ expect(result).toEqual({ page: -1, limit: -5 });
33
+ });
34
+
35
+ it('should handle decimal values', () => {
36
+ const result = PaginationOptionsZod.parse({ page: 2.5, limit: 15.7 });
37
+ expect(result).toEqual({ page: 2.5, limit: 15.7 });
38
+ });
39
+
40
+ it('should throw an error for non-numeric string values', () => {
41
+ expect(() => {
42
+ PaginationOptionsZod.parse({ page: 'abc' });
43
+ }).toThrow();
44
+ });
45
+
46
+ it('should accept empty string values and convert them to defaults', () => {
47
+ const result = PaginationOptionsZod.parse({ page: '' });
48
+ expect(result).toEqual({ page: 1, limit: 10 });
49
+ });
50
+
51
+ it('should accept undefined values and use defaults', () => {
52
+ const result = PaginationOptionsZod.parse({ page: undefined });
53
+ expect(result).toEqual({ page: 1, limit: 10 });
54
+ });
55
+
56
+ it('should handle null values by using defaults', () => {
57
+ const result = PaginationOptionsZod.parse({ page: null, limit: null });
58
+ expect(result).toEqual({ page: 1, limit: 10 });
59
+ });
60
+
61
+ it('should handle objects with extra properties', () => {
62
+ const result = PaginationOptionsZod.parse({
63
+ page: 5,
64
+ limit: 25,
65
+ sort: 'asc',
66
+ filter: 'active',
67
+ });
68
+ expect(result).toEqual({ page: 5, limit: 25 });
69
+ });
70
+
71
+ it('should handle string numbers with leading zeros', () => {
72
+ const result = PaginationOptionsZod.parse({ page: '01', limit: '05' });
73
+ expect(result).toEqual({ page: 1, limit: 5 });
74
+ });
75
+
76
+ it('should handle exponential notation', () => {
77
+ const result = PaginationOptionsZod.parse({ page: 1e2, limit: 1e1 });
78
+ expect(result).toEqual({ page: 100, limit: 10 });
79
+ });
80
+ });
81
+
82
+ describe('numberPrecisionSchema', () => {
83
+ describe('default precision (2 decimal places)', () => {
84
+ it('should transform numbers with more than 2 decimal places', () => {
85
+ const schema = numberPrecisionSchema();
86
+ expect(schema.parse(123.456)).toBe(123.46);
87
+ expect(schema.parse(123.456789)).toBe(123.46);
88
+ expect(schema.parse(0.999)).toBe(1.0);
89
+ });
90
+
91
+ it('should keep numbers with exactly 2 decimal places unchanged', () => {
92
+ const schema = numberPrecisionSchema();
93
+ expect(schema.parse(123.45)).toBe(123.45);
94
+ expect(schema.parse(0.99)).toBe(0.99);
95
+ expect(schema.parse(1000.0)).toBe(1000.0);
96
+ });
97
+
98
+ it('should pad numbers with fewer than 2 decimal places', () => {
99
+ const schema = numberPrecisionSchema();
100
+ expect(schema.parse(123.4)).toBe(123.4);
101
+ expect(schema.parse(123)).toBe(123.0);
102
+ expect(schema.parse(0.5)).toBe(0.5);
103
+ });
104
+
105
+ it('should handle whole numbers', () => {
106
+ const schema = numberPrecisionSchema();
107
+ expect(schema.parse(100)).toBe(100.0);
108
+ expect(schema.parse(0)).toBe(0.0);
109
+ expect(schema.parse(999)).toBe(999.0);
110
+ });
111
+
112
+ it('should handle negative numbers', () => {
113
+ const schema = numberPrecisionSchema();
114
+ expect(schema.parse(-123.456)).toBe(-123.46);
115
+ expect(schema.parse(-123.45)).toBe(-123.45);
116
+ expect(schema.parse(-100)).toBe(-100.0);
117
+ });
118
+
119
+ it('should handle zero', () => {
120
+ const schema = numberPrecisionSchema();
121
+ expect(schema.parse(0)).toBe(0.0);
122
+ expect(schema.parse(0.0)).toBe(0.0);
123
+ expect(schema.parse(0.001)).toBe(0.0);
124
+ });
125
+
126
+ it('should handle very small numbers', () => {
127
+ const schema = numberPrecisionSchema();
128
+ expect(schema.parse(0.001)).toBe(0.0);
129
+ expect(schema.parse(0.004)).toBe(0.0);
130
+ expect(schema.parse(0.005)).toBe(0.01);
131
+ expect(schema.parse(0.015)).toBe(0.02);
132
+ });
133
+
134
+ it('should handle very large numbers', () => {
135
+ const schema = numberPrecisionSchema();
136
+ expect(schema.parse(999999999.123456)).toBe(999999999.12);
137
+ expect(schema.parse(1234567890.99)).toBe(1234567890.99);
138
+ });
139
+
140
+ it('should handle numbers with floating point precision issues', () => {
141
+ const schema = numberPrecisionSchema();
142
+ // Common floating point issue: 0.1 + 0.2 = 0.30000000000000004
143
+ expect(schema.parse(0.1 + 0.2)).toBe(0.3);
144
+ expect(schema.parse(0.1 + 0.7)).toBe(0.8);
145
+ });
146
+ });
147
+
148
+ describe('custom precision values', () => {
149
+ it('should work with precision 0 (whole numbers)', () => {
150
+ const schema = numberPrecisionSchema(0);
151
+ expect(schema.parse(123.456)).toBe(123);
152
+ expect(schema.parse(123.5)).toBe(124);
153
+ expect(schema.parse(123.4)).toBe(123);
154
+ expect(schema.parse(0.9)).toBe(1);
155
+ });
156
+
157
+ it('should work with precision 1', () => {
158
+ const schema = numberPrecisionSchema(1);
159
+ expect(schema.parse(123.45)).toBe(123.5);
160
+ expect(schema.parse(123.44)).toBe(123.4);
161
+ expect(schema.parse(123.456)).toBe(123.5);
162
+ });
163
+
164
+ it('should work with precision 3', () => {
165
+ const schema = numberPrecisionSchema(3);
166
+ expect(schema.parse(123.4567)).toBe(123.457);
167
+ expect(schema.parse(123.456)).toBe(123.456);
168
+ expect(schema.parse(123.4)).toBe(123.4);
169
+ });
170
+
171
+ it('should work with precision 4', () => {
172
+ const schema = numberPrecisionSchema(4);
173
+ expect(schema.parse(123.45678)).toBe(123.4568);
174
+ expect(schema.parse(123.4567)).toBe(123.4567);
175
+ expect(schema.parse(123.4)).toBe(123.4);
176
+ });
177
+
178
+ it('should work with precision 6', () => {
179
+ const schema = numberPrecisionSchema(6);
180
+ expect(schema.parse(123.4567890123)).toBe(123.456789);
181
+ expect(schema.parse(123.456789)).toBe(123.456789);
182
+ });
183
+ });
184
+
185
+ describe('with base schema constraints', () => {
186
+ it('should apply positive constraint', () => {
187
+ const schema = numberPrecisionSchema(2, z.number().positive());
188
+ expect(schema.parse(123.456)).toBe(123.46);
189
+ expect(() => schema.parse(-123.456)).toThrow();
190
+ expect(() => schema.parse(0)).toThrow();
191
+ });
192
+
193
+ it('should apply max constraint', () => {
194
+ const schema = numberPrecisionSchema(2, z.number().max(1000));
195
+ expect(schema.parse(999.99)).toBe(999.99);
196
+ expect(schema.parse(1000.0)).toBe(1000.0);
197
+ expect(() => schema.parse(1000.01)).toThrow();
198
+ });
199
+
200
+ it('should apply min constraint', () => {
201
+ const schema = numberPrecisionSchema(2, z.number().min(0.01));
202
+ expect(schema.parse(0.01)).toBe(0.01);
203
+ expect(schema.parse(0.015)).toBe(0.02);
204
+ expect(() => schema.parse(0.005)).toThrow();
205
+ });
206
+
207
+ it('should apply multiple constraints', () => {
208
+ const schema = numberPrecisionSchema(
209
+ 2,
210
+ z.number().positive().min(0.01).max(999999999),
211
+ );
212
+ expect(schema.parse(500.99)).toBe(500.99);
213
+ expect(schema.parse(0.015)).toBe(0.02);
214
+ expect(() => schema.parse(-100)).toThrow();
215
+ expect(() => schema.parse(0.005)).toThrow();
216
+ expect(() => schema.parse(1000000000)).toThrow();
217
+ });
218
+ });
219
+
220
+ describe('rounding behavior', () => {
221
+ it('should round up correctly', () => {
222
+ const schema = numberPrecisionSchema(2);
223
+ expect(schema.parse(123.455)).toBe(123.46);
224
+ expect(schema.parse(123.445)).toBe(123.45);
225
+ expect(schema.parse(0.995)).toBe(1.0);
226
+ });
227
+
228
+ it('should round down correctly', () => {
229
+ const schema = numberPrecisionSchema(2);
230
+ expect(schema.parse(123.444)).toBe(123.44);
231
+ expect(schema.parse(123.441)).toBe(123.44);
232
+ });
233
+
234
+ it("should handle banker's rounding (round half to even)", () => {
235
+ const schema = numberPrecisionSchema(2);
236
+ // JavaScript's toFixed uses standard rounding, not banker's rounding
237
+ expect(schema.parse(123.445)).toBe(123.45);
238
+ expect(schema.parse(123.435)).toBe(123.44);
239
+ });
240
+
241
+ it('should handle edge cases in rounding', () => {
242
+ const schema = numberPrecisionSchema(2);
243
+ expect(schema.parse(0.004)).toBe(0.0);
244
+ expect(schema.parse(0.005)).toBe(0.01);
245
+ expect(schema.parse(0.015)).toBe(0.02);
246
+ expect(schema.parse(0.025)).toBe(0.03);
247
+ });
248
+ });
249
+
250
+ describe('edge cases', () => {
251
+ it('should handle very small positive numbers', () => {
252
+ const schema = numberPrecisionSchema(2);
253
+ expect(schema.parse(0.0001)).toBe(0.0);
254
+ expect(schema.parse(0.0005)).toBe(0.0);
255
+ expect(schema.parse(0.0006)).toBe(0.0);
256
+ });
257
+
258
+ it('should handle very large numbers', () => {
259
+ const schema = numberPrecisionSchema(2);
260
+ expect(schema.parse(Number.MAX_SAFE_INTEGER)).toBe(
261
+ Number(Number.MAX_SAFE_INTEGER.toFixed(2)),
262
+ );
263
+ });
264
+
265
+ it('should handle numbers at precision boundaries', () => {
266
+ const schema = numberPrecisionSchema(2);
267
+ expect(schema.parse(123.444)).toBe(123.44);
268
+ expect(schema.parse(123.445)).toBe(123.45);
269
+ expect(schema.parse(123.446)).toBe(123.45);
270
+ });
271
+
272
+ it('should handle scientific notation', () => {
273
+ const schema = numberPrecisionSchema(2);
274
+ expect(schema.parse(1.23e2)).toBe(123.0);
275
+ expect(schema.parse(1.234e2)).toBe(123.4);
276
+ expect(schema.parse(1.2345e2)).toBe(123.45);
277
+ });
278
+
279
+ it('should handle Infinity', () => {
280
+ const schema = numberPrecisionSchema(2);
281
+ expect(schema.parse(Infinity)).toBe(Infinity);
282
+ expect(schema.parse(-Infinity)).toBe(-Infinity);
283
+ });
284
+
285
+ it('should handle NaN', () => {
286
+ const schema = numberPrecisionSchema(2);
287
+ expect(() => schema.parse(NaN)).toThrow();
288
+ });
289
+ });
290
+
291
+ describe('real-world scenarios', () => {
292
+ it('should handle currency amounts', () => {
293
+ const schema = numberPrecisionSchema(2);
294
+ expect(schema.parse(122.4444)).toBe(122.44);
295
+ expect(schema.parse(99.995)).toBe(100.0);
296
+ expect(schema.parse(0.01)).toBe(0.01);
297
+ expect(schema.parse(1000.0)).toBe(1000.0);
298
+ });
299
+
300
+ it('should handle percentage values', () => {
301
+ const schema = numberPrecisionSchema(2);
302
+ expect(schema.parse(12.3456)).toBe(12.35);
303
+ expect(schema.parse(99.999)).toBe(100.0);
304
+ expect(schema.parse(0.123)).toBe(0.12);
305
+ });
306
+
307
+ it('should handle measurement values with different precision', () => {
308
+ const schema3 = numberPrecisionSchema(3);
309
+ expect(schema3.parse(12.34567)).toBe(12.346);
310
+ expect(schema3.parse(0.1234)).toBe(0.123);
311
+ });
312
+ });
313
+
314
+ describe('integration with Zod features', () => {
315
+ it('should work with safeParse', () => {
316
+ const schema = numberPrecisionSchema(2);
317
+ const result = schema.safeParse(123.456);
318
+ expect(result.success).toBe(true);
319
+ if (result.success) {
320
+ expect(result.data).toBe(123.46);
321
+ }
322
+ });
323
+
324
+ it('should work with safeParse for invalid input', () => {
325
+ const schema = numberPrecisionSchema(2, z.number().positive());
326
+ const result = schema.safeParse(-123.456);
327
+ expect(result.success).toBe(false);
328
+ });
329
+
330
+ it('should preserve type information', () => {
331
+ const schema = numberPrecisionSchema(2);
332
+ const result = schema.parse(123.456);
333
+ expect(typeof result).toBe('number');
334
+ });
335
+ });
336
+ });