@ic-reactor/react 3.12.5 → 4.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/README.md +236 -423
  2. package/dist/index.d.ts +259 -12
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +470 -17
  5. package/dist/index.js.map +1 -1
  6. package/llms.txt +82 -54
  7. package/package.json +12 -28
  8. package/src/index.tsx +611 -0
  9. package/dist/auth/authentication-manager.d.ts +0 -123
  10. package/dist/auth/authentication-manager.d.ts.map +0 -1
  11. package/dist/auth/authentication-manager.js +0 -767
  12. package/dist/auth/authentication-manager.js.map +0 -1
  13. package/dist/auth/constants.d.ts +0 -24
  14. package/dist/auth/constants.d.ts.map +0 -1
  15. package/dist/auth/constants.js +0 -24
  16. package/dist/auth/constants.js.map +0 -1
  17. package/dist/auth/createIdentityAttributeHooks.d.ts +0 -14
  18. package/dist/auth/createIdentityAttributeHooks.d.ts.map +0 -1
  19. package/dist/auth/createIdentityAttributeHooks.js +0 -106
  20. package/dist/auth/createIdentityAttributeHooks.js.map +0 -1
  21. package/dist/auth/identity-attributes-manager.d.ts +0 -26
  22. package/dist/auth/identity-attributes-manager.d.ts.map +0 -1
  23. package/dist/auth/identity-attributes-manager.js +0 -107
  24. package/dist/auth/identity-attributes-manager.js.map +0 -1
  25. package/dist/auth/identity-attributes.d.ts +0 -19
  26. package/dist/auth/identity-attributes.d.ts.map +0 -1
  27. package/dist/auth/identity-attributes.js +0 -170
  28. package/dist/auth/identity-attributes.js.map +0 -1
  29. package/dist/auth/index.d.ts +0 -8
  30. package/dist/auth/index.d.ts.map +0 -1
  31. package/dist/auth/index.js +0 -8
  32. package/dist/auth/index.js.map +0 -1
  33. package/dist/auth/local-ii-probe.d.ts +0 -46
  34. package/dist/auth/local-ii-probe.d.ts.map +0 -1
  35. package/dist/auth/local-ii-probe.js +0 -102
  36. package/dist/auth/local-ii-probe.js.map +0 -1
  37. package/dist/auth/types.d.ts +0 -179
  38. package/dist/auth/types.d.ts.map +0 -1
  39. package/dist/auth/types.js +0 -2
  40. package/dist/auth/types.js.map +0 -1
  41. package/dist/createActorHooks.d.ts +0 -52
  42. package/dist/createActorHooks.d.ts.map +0 -1
  43. package/dist/createActorHooks.js +0 -17
  44. package/dist/createActorHooks.js.map +0 -1
  45. package/dist/createInfiniteQuery.d.ts +0 -144
  46. package/dist/createInfiniteQuery.d.ts.map +0 -1
  47. package/dist/createInfiniteQuery.js +0 -174
  48. package/dist/createInfiniteQuery.js.map +0 -1
  49. package/dist/createMutation.d.ts +0 -30
  50. package/dist/createMutation.d.ts.map +0 -1
  51. package/dist/createMutation.js +0 -192
  52. package/dist/createMutation.js.map +0 -1
  53. package/dist/createQuery.d.ts +0 -30
  54. package/dist/createQuery.d.ts.map +0 -1
  55. package/dist/createQuery.js +0 -117
  56. package/dist/createQuery.js.map +0 -1
  57. package/dist/createSuspenseInfiniteQuery.d.ts +0 -147
  58. package/dist/createSuspenseInfiniteQuery.d.ts.map +0 -1
  59. package/dist/createSuspenseInfiniteQuery.js +0 -177
  60. package/dist/createSuspenseInfiniteQuery.js.map +0 -1
  61. package/dist/createSuspenseQuery.d.ts +0 -25
  62. package/dist/createSuspenseQuery.d.ts.map +0 -1
  63. package/dist/createSuspenseQuery.js +0 -111
  64. package/dist/createSuspenseQuery.js.map +0 -1
  65. package/dist/defineReactor.d.ts +0 -125
  66. package/dist/defineReactor.d.ts.map +0 -1
  67. package/dist/defineReactor.js +0 -180
  68. package/dist/defineReactor.js.map +0 -1
  69. package/dist/hooks/createAuthHooks.d.ts +0 -43
  70. package/dist/hooks/createAuthHooks.d.ts.map +0 -1
  71. package/dist/hooks/createAuthHooks.js +0 -131
  72. package/dist/hooks/createAuthHooks.js.map +0 -1
  73. package/dist/hooks/index.d.ts +0 -21
  74. package/dist/hooks/index.d.ts.map +0 -1
  75. package/dist/hooks/index.js +0 -24
  76. package/dist/hooks/index.js.map +0 -1
  77. package/dist/hooks/useActorInfiniteQuery.d.ts +0 -39
  78. package/dist/hooks/useActorInfiniteQuery.d.ts.map +0 -1
  79. package/dist/hooks/useActorInfiniteQuery.js +0 -56
  80. package/dist/hooks/useActorInfiniteQuery.js.map +0 -1
  81. package/dist/hooks/useActorMethod.d.ts +0 -115
  82. package/dist/hooks/useActorMethod.d.ts.map +0 -1
  83. package/dist/hooks/useActorMethod.js +0 -250
  84. package/dist/hooks/useActorMethod.js.map +0 -1
  85. package/dist/hooks/useActorMutation.d.ts +0 -48
  86. package/dist/hooks/useActorMutation.d.ts.map +0 -1
  87. package/dist/hooks/useActorMutation.js +0 -69
  88. package/dist/hooks/useActorMutation.js.map +0 -1
  89. package/dist/hooks/useActorQuery.d.ts +0 -32
  90. package/dist/hooks/useActorQuery.d.ts.map +0 -1
  91. package/dist/hooks/useActorQuery.js +0 -46
  92. package/dist/hooks/useActorQuery.js.map +0 -1
  93. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +0 -39
  94. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +0 -1
  95. package/dist/hooks/useActorSuspenseInfiniteQuery.js +0 -56
  96. package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +0 -1
  97. package/dist/hooks/useActorSuspenseQuery.d.ts +0 -32
  98. package/dist/hooks/useActorSuspenseQuery.d.ts.map +0 -1
  99. package/dist/hooks/useActorSuspenseQuery.js +0 -47
  100. package/dist/hooks/useActorSuspenseQuery.js.map +0 -1
  101. package/dist/types.d.ts +0 -270
  102. package/dist/types.d.ts.map +0 -1
  103. package/dist/types.js +0 -5
  104. package/dist/types.js.map +0 -1
  105. package/dist/utils.d.ts +0 -51
  106. package/dist/utils.d.ts.map +0 -1
  107. package/dist/utils.js +0 -105
  108. package/dist/utils.js.map +0 -1
  109. package/dist/validation.d.ts +0 -131
  110. package/dist/validation.d.ts.map +0 -1
  111. package/dist/validation.js +0 -125
  112. package/dist/validation.js.map +0 -1
  113. package/src/auth/authentication-manager.ts +0 -860
  114. package/src/auth/constants.ts +0 -32
  115. package/src/auth/createIdentityAttributeHooks.ts +0 -143
  116. package/src/auth/identity-attributes-manager.ts +0 -131
  117. package/src/auth/identity-attributes.ts +0 -270
  118. package/src/auth/index.ts +0 -7
  119. package/src/auth/local-ii-probe.ts +0 -147
  120. package/src/auth/types.ts +0 -200
  121. package/src/createActorHooks.ts +0 -220
  122. package/src/createInfiniteQuery.ts +0 -578
  123. package/src/createMutation.ts +0 -341
  124. package/src/createQuery.ts +0 -237
  125. package/src/createSuspenseInfiniteQuery.ts +0 -601
  126. package/src/createSuspenseQuery.ts +0 -234
  127. package/src/defineReactor.ts +0 -324
  128. package/src/hooks/createAuthHooks.ts +0 -189
  129. package/src/hooks/index.ts +0 -103
  130. package/src/hooks/useActorInfiniteQuery.ts +0 -205
  131. package/src/hooks/useActorMethod.ts +0 -507
  132. package/src/hooks/useActorMutation.ts +0 -205
  133. package/src/hooks/useActorQuery.ts +0 -124
  134. package/src/hooks/useActorSuspenseInfiniteQuery.ts +0 -205
  135. package/src/hooks/useActorSuspenseQuery.ts +0 -132
  136. package/src/index.ts +0 -23
  137. package/src/types.ts +0 -499
  138. package/src/utils.ts +0 -121
  139. package/src/validation.ts +0 -202
package/src/validation.ts DELETED
@@ -1,202 +0,0 @@
1
- /**
2
- * Validation utilities for React
3
- *
4
- * Helpers for working with ValidationError in React components,
5
- * especially for form integration.
6
- */
7
-
8
- import {
9
- ValidationError,
10
- isValidationError,
11
- ValidationIssue,
12
- } from "@ic-reactor/core"
13
-
14
- // Re-export for convenience
15
- export { isValidationError, ValidationError }
16
- export type { ValidationIssue }
17
-
18
- /**
19
- * A map of field names to error messages.
20
- * This format is compatible with most form libraries.
21
- */
22
- export type FieldErrors = Record<string, string>
23
-
24
- /**
25
- * A map of field names to arrays of error messages.
26
- * Use when you need to show multiple errors per field.
27
- */
28
- export type FieldErrorsMultiple = Record<string, string[]>
29
-
30
- /**
31
- * Options for mapValidationErrors
32
- */
33
- export interface MapValidationErrorsOptions {
34
- /**
35
- * If true, returns all messages for each field as an array.
36
- * If false (default), returns only the first message for each field.
37
- */
38
- multiple?: boolean
39
- }
40
-
41
- /**
42
- * Maps validation error issues to a simple field -> message object.
43
- * Returns the first error message for each field path.
44
- *
45
- * @example
46
- * ```tsx
47
- * const { mutate } = useActorMutation({
48
- * functionName: "transfer",
49
- * onError: (error) => {
50
- * if (isValidationError(error)) {
51
- * const fieldErrors = mapValidationErrors(error)
52
- * // { to: "Recipient is required", amount: "Must be a number" }
53
- *
54
- * // Use with React Hook Form
55
- * Object.entries(fieldErrors).forEach(([field, message]) => {
56
- * form.setError(field, { message })
57
- * })
58
- * }
59
- * }
60
- * })
61
- * ```
62
- */
63
- export function mapValidationErrors(error: ValidationError): FieldErrors
64
- export function mapValidationErrors(
65
- error: ValidationError,
66
- options: { multiple: true }
67
- ): FieldErrorsMultiple
68
- export function mapValidationErrors(
69
- error: ValidationError,
70
- options: { multiple: false }
71
- ): FieldErrors
72
- export function mapValidationErrors(
73
- error: ValidationError,
74
- options?: MapValidationErrorsOptions
75
- ): FieldErrors | FieldErrorsMultiple {
76
- if (options?.multiple) {
77
- const result: FieldErrorsMultiple = {}
78
- for (const issue of error.issues) {
79
- const fieldName = String(issue.path[0] ?? "")
80
- if (!result[fieldName]) {
81
- result[fieldName] = []
82
- }
83
- result[fieldName].push(issue.message)
84
- }
85
- return result
86
- }
87
-
88
- const result: FieldErrors = {}
89
- for (const issue of error.issues) {
90
- const fieldName = String(issue.path[0] ?? "")
91
- if (!result[fieldName]) {
92
- result[fieldName] = issue.message
93
- }
94
- }
95
- return result
96
- }
97
-
98
- /**
99
- * Gets error message for a specific field from a ValidationError.
100
- * Returns undefined if no error exists for that field.
101
- *
102
- * @example
103
- * ```tsx
104
- * if (isValidationError(error)) {
105
- * const toError = getFieldError(error, "to")
106
- * const amountError = getFieldError(error, "amount")
107
- * }
108
- * ```
109
- */
110
- export function getFieldError(
111
- error: ValidationError,
112
- fieldName: string
113
- ): string | undefined {
114
- const issue = error.issues.find((i) => String(i.path[0]) === fieldName)
115
- return issue?.message
116
- }
117
-
118
- /**
119
- * Gets all error messages for a specific field from a ValidationError.
120
- * Returns empty array if no errors exist for that field.
121
- *
122
- * @example
123
- * ```tsx
124
- * if (isValidationError(error)) {
125
- * const amountErrors = getFieldErrors(error, "amount")
126
- * // ["Amount is required", "Amount must be positive"]
127
- * }
128
- * ```
129
- */
130
- export function getFieldErrors(
131
- error: ValidationError,
132
- fieldName: string
133
- ): string[] {
134
- return error.issues
135
- .filter((i) => String(i.path[0]) === fieldName)
136
- .map((i) => i.message)
137
- }
138
-
139
- /**
140
- * Checks if a given error is a ValidationError and optionally
141
- * extracts field errors in one step.
142
- *
143
- * @example
144
- * ```tsx
145
- * const { mutateAsync } = useActorMutation({ functionName: "transfer" })
146
- *
147
- * const handleSubmit = async (data) => {
148
- * try {
149
- * await mutateAsync([data])
150
- * } catch (error) {
151
- * const fieldErrors = extractValidationErrors(error)
152
- * if (fieldErrors) {
153
- * // Handle validation errors
154
- * Object.entries(fieldErrors).forEach(([field, message]) => {
155
- * form.setError(field, { message })
156
- * })
157
- * } else {
158
- * // Handle other errors
159
- * console.error(error)
160
- * }
161
- * }
162
- * }
163
- * ```
164
- */
165
- export function extractValidationErrors(error: unknown): FieldErrors | null {
166
- if (isValidationError(error)) {
167
- return mapValidationErrors(error)
168
- }
169
- return null
170
- }
171
-
172
- /**
173
- * React hook-friendly error handler that extracts validation errors.
174
- * Returns a callback suitable for onError handlers.
175
- *
176
- * @example
177
- * ```tsx
178
- * const [fieldErrors, setFieldErrors] = useState<FieldErrors>({})
179
- *
180
- * const { mutate } = useActorMutation({
181
- * functionName: "transfer",
182
- * onError: handleValidationError(setFieldErrors),
183
- * })
184
- *
185
- * // In JSX
186
- * <input name="to" />
187
- * {fieldErrors.to && <span className="error">{fieldErrors.to}</span>}
188
- * ```
189
- */
190
- export function handleValidationError(
191
- setFieldErrors: (errors: FieldErrors) => void,
192
- onOtherError?: (error: Error) => void
193
- ): (error: Error) => void {
194
- return (error: Error) => {
195
- const fieldErrors = extractValidationErrors(error)
196
- if (fieldErrors) {
197
- setFieldErrors(fieldErrors)
198
- } else if (onOtherError) {
199
- onOtherError(error)
200
- }
201
- }
202
- }