@ic-reactor/react 3.13.0 → 4.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +237 -787
  2. package/dist/index.d.ts +260 -16
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +471 -23
  5. package/dist/index.js.map +1 -1
  6. package/llms.txt +82 -278
  7. package/package.json +11 -39
  8. package/src/index.tsx +612 -0
  9. package/dist/auth/auth-client-compat.d.ts +0 -122
  10. package/dist/auth/auth-client-compat.d.ts.map +0 -1
  11. package/dist/auth/auth-client-compat.js +0 -162
  12. package/dist/auth/auth-client-compat.js.map +0 -1
  13. package/dist/auth/authentication-manager.d.ts +0 -405
  14. package/dist/auth/authentication-manager.d.ts.map +0 -1
  15. package/dist/auth/authentication-manager.js +0 -1537
  16. package/dist/auth/authentication-manager.js.map +0 -1
  17. package/dist/auth/constants.d.ts +0 -24
  18. package/dist/auth/constants.d.ts.map +0 -1
  19. package/dist/auth/constants.js +0 -24
  20. package/dist/auth/constants.js.map +0 -1
  21. package/dist/auth/createIdentityAttributeHooks.d.ts +0 -14
  22. package/dist/auth/createIdentityAttributeHooks.d.ts.map +0 -1
  23. package/dist/auth/createIdentityAttributeHooks.js +0 -122
  24. package/dist/auth/createIdentityAttributeHooks.js.map +0 -1
  25. package/dist/auth/identity-attributes-manager.d.ts +0 -27
  26. package/dist/auth/identity-attributes-manager.d.ts.map +0 -1
  27. package/dist/auth/identity-attributes-manager.js +0 -191
  28. package/dist/auth/identity-attributes-manager.js.map +0 -1
  29. package/dist/auth/identity-attributes.d.ts +0 -19
  30. package/dist/auth/identity-attributes.d.ts.map +0 -1
  31. package/dist/auth/identity-attributes.js +0 -227
  32. package/dist/auth/identity-attributes.js.map +0 -1
  33. package/dist/auth/index.d.ts +0 -8
  34. package/dist/auth/index.d.ts.map +0 -1
  35. package/dist/auth/index.js +0 -8
  36. package/dist/auth/index.js.map +0 -1
  37. package/dist/auth/local-ii-probe.d.ts +0 -57
  38. package/dist/auth/local-ii-probe.d.ts.map +0 -1
  39. package/dist/auth/local-ii-probe.js +0 -121
  40. package/dist/auth/local-ii-probe.js.map +0 -1
  41. package/dist/auth/types.d.ts +0 -222
  42. package/dist/auth/types.d.ts.map +0 -1
  43. package/dist/auth/types.js +0 -2
  44. package/dist/auth/types.js.map +0 -1
  45. package/dist/createActorHooks.d.ts +0 -41
  46. package/dist/createActorHooks.d.ts.map +0 -1
  47. package/dist/createActorHooks.js +0 -17
  48. package/dist/createActorHooks.js.map +0 -1
  49. package/dist/createInfiniteQuery.d.ts +0 -185
  50. package/dist/createInfiniteQuery.d.ts.map +0 -1
  51. package/dist/createInfiniteQuery.js +0 -198
  52. package/dist/createInfiniteQuery.js.map +0 -1
  53. package/dist/createMutation.d.ts +0 -33
  54. package/dist/createMutation.d.ts.map +0 -1
  55. package/dist/createMutation.js +0 -199
  56. package/dist/createMutation.js.map +0 -1
  57. package/dist/createQuery.d.ts +0 -63
  58. package/dist/createQuery.d.ts.map +0 -1
  59. package/dist/createQuery.js +0 -204
  60. package/dist/createQuery.js.map +0 -1
  61. package/dist/createReactorProvider.d.ts +0 -158
  62. package/dist/createReactorProvider.d.ts.map +0 -1
  63. package/dist/createReactorProvider.js +0 -256
  64. package/dist/createReactorProvider.js.map +0 -1
  65. package/dist/createSuspenseInfiniteQuery.d.ts +0 -154
  66. package/dist/createSuspenseInfiniteQuery.d.ts.map +0 -1
  67. package/dist/createSuspenseInfiniteQuery.js +0 -209
  68. package/dist/createSuspenseInfiniteQuery.js.map +0 -1
  69. package/dist/createSuspenseQuery.d.ts +0 -46
  70. package/dist/createSuspenseQuery.d.ts.map +0 -1
  71. package/dist/createSuspenseQuery.js +0 -158
  72. package/dist/createSuspenseQuery.js.map +0 -1
  73. package/dist/defineDisplayReactor.d.ts +0 -43
  74. package/dist/defineDisplayReactor.d.ts.map +0 -1
  75. package/dist/defineDisplayReactor.js +0 -42
  76. package/dist/defineDisplayReactor.js.map +0 -1
  77. package/dist/defineReactor.d.ts +0 -99
  78. package/dist/defineReactor.d.ts.map +0 -1
  79. package/dist/defineReactor.js +0 -15
  80. package/dist/defineReactor.js.map +0 -1
  81. package/dist/defineReactorShared.d.ts +0 -84
  82. package/dist/defineReactorShared.d.ts.map +0 -1
  83. package/dist/defineReactorShared.js +0 -139
  84. package/dist/defineReactorShared.js.map +0 -1
  85. package/dist/hooks/createAuthHooks.d.ts +0 -50
  86. package/dist/hooks/createAuthHooks.d.ts.map +0 -1
  87. package/dist/hooks/createAuthHooks.js +0 -291
  88. package/dist/hooks/createAuthHooks.js.map +0 -1
  89. package/dist/hooks/index.d.ts +0 -21
  90. package/dist/hooks/index.d.ts.map +0 -1
  91. package/dist/hooks/index.js +0 -24
  92. package/dist/hooks/index.js.map +0 -1
  93. package/dist/hooks/useActorInfiniteQuery.d.ts +0 -67
  94. package/dist/hooks/useActorInfiniteQuery.d.ts.map +0 -1
  95. package/dist/hooks/useActorInfiniteQuery.js +0 -89
  96. package/dist/hooks/useActorInfiniteQuery.js.map +0 -1
  97. package/dist/hooks/useActorMethod.d.ts +0 -148
  98. package/dist/hooks/useActorMethod.d.ts.map +0 -1
  99. package/dist/hooks/useActorMethod.js +0 -394
  100. package/dist/hooks/useActorMethod.js.map +0 -1
  101. package/dist/hooks/useActorMutation.d.ts +0 -51
  102. package/dist/hooks/useActorMutation.d.ts.map +0 -1
  103. package/dist/hooks/useActorMutation.js +0 -70
  104. package/dist/hooks/useActorMutation.js.map +0 -1
  105. package/dist/hooks/useActorQuery.d.ts +0 -45
  106. package/dist/hooks/useActorQuery.d.ts.map +0 -1
  107. package/dist/hooks/useActorQuery.js +0 -67
  108. package/dist/hooks/useActorQuery.js.map +0 -1
  109. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +0 -51
  110. package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +0 -1
  111. package/dist/hooks/useActorSuspenseInfiniteQuery.js +0 -76
  112. package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +0 -1
  113. package/dist/hooks/useActorSuspenseQuery.d.ts +0 -32
  114. package/dist/hooks/useActorSuspenseQuery.d.ts.map +0 -1
  115. package/dist/hooks/useActorSuspenseQuery.js +0 -58
  116. package/dist/hooks/useActorSuspenseQuery.js.map +0 -1
  117. package/dist/ownedAuthentication.d.ts +0 -52
  118. package/dist/ownedAuthentication.d.ts.map +0 -1
  119. package/dist/ownedAuthentication.js +0 -49
  120. package/dist/ownedAuthentication.js.map +0 -1
  121. package/dist/server.d.ts +0 -21
  122. package/dist/server.d.ts.map +0 -1
  123. package/dist/server.js +0 -23
  124. package/dist/server.js.map +0 -1
  125. package/dist/testing.d.ts +0 -19
  126. package/dist/testing.d.ts.map +0 -1
  127. package/dist/testing.js +0 -19
  128. package/dist/testing.js.map +0 -1
  129. package/dist/types.d.ts +0 -671
  130. package/dist/types.d.ts.map +0 -1
  131. package/dist/types.js +0 -5
  132. package/dist/types.js.map +0 -1
  133. package/dist/utils.d.ts +0 -207
  134. package/dist/utils.d.ts.map +0 -1
  135. package/dist/utils.js +0 -405
  136. package/dist/utils.js.map +0 -1
  137. package/dist/validation.d.ts +0 -136
  138. package/dist/validation.d.ts.map +0 -1
  139. package/dist/validation.js +0 -144
  140. package/dist/validation.js.map +0 -1
  141. package/src/auth/auth-client-compat.ts +0 -273
  142. package/src/auth/authentication-manager.ts +0 -1682
  143. package/src/auth/constants.ts +0 -32
  144. package/src/auth/createIdentityAttributeHooks.ts +0 -169
  145. package/src/auth/identity-attributes-manager.ts +0 -226
  146. package/src/auth/identity-attributes.ts +0 -345
  147. package/src/auth/index.ts +0 -7
  148. package/src/auth/local-ii-probe.ts +0 -173
  149. package/src/auth/types.ts +0 -243
  150. package/src/createActorHooks.ts +0 -208
  151. package/src/createInfiniteQuery.ts +0 -670
  152. package/src/createMutation.ts +0 -324
  153. package/src/createQuery.ts +0 -369
  154. package/src/createReactorProvider.ts +0 -365
  155. package/src/createSuspenseInfiniteQuery.ts +0 -651
  156. package/src/createSuspenseQuery.ts +0 -304
  157. package/src/defineDisplayReactor.ts +0 -62
  158. package/src/defineReactor.ts +0 -142
  159. package/src/defineReactorShared.ts +0 -268
  160. package/src/hooks/createAuthHooks.ts +0 -371
  161. package/src/hooks/index.ts +0 -103
  162. package/src/hooks/useActorInfiniteQuery.ts +0 -278
  163. package/src/hooks/useActorMethod.ts +0 -710
  164. package/src/hooks/useActorMutation.ts +0 -205
  165. package/src/hooks/useActorQuery.ts +0 -157
  166. package/src/hooks/useActorSuspenseInfiniteQuery.ts +0 -248
  167. package/src/hooks/useActorSuspenseQuery.ts +0 -147
  168. package/src/index.ts +0 -31
  169. package/src/ownedAuthentication.ts +0 -81
  170. package/src/server.ts +0 -23
  171. package/src/testing.ts +0 -18
  172. package/src/types.ts +0 -948
  173. package/src/utils.ts +0 -505
  174. package/src/validation.ts +0 -226
package/dist/utils.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAWjC,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAS9C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,mBAAmB,CACjC,WAAoC;IAEpC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,WAAW;YAAE,OAAM;QACxB,WAAW,CAAC,KAAK,EAAE,CAAA;QACnB,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,CAAA;IACpC,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;AACnB,CAAC;AAED,MAAM,UAAU,GAAG,CAAC,KAAc,EAAiC,EAAE,CACnE,OAAQ,KAA+C,EAAE,IAAI,KAAK,UAAU,CAAA;AAE9E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,mBAAmB,CACj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,EAAE,GAAG,EAAE;oBACb,kEAAkE;oBAClE,mEAAmE;oBACnE,6DAA6D;oBAC7D,IAAI,eAAe,CAAC,OAAO,CAAC,KAAK,SAAS;wBAAE,OAAM;oBAClD,mEAAmE;oBACnE,iEAAiE;oBACjE,qBAAqB;oBACrB,WAAW,CAAC,YAAY,CAAe,QAAQ,EAAE,QAAQ,EAAE;wBACzD,SAAS,EAAE,aAAa;qBACzB,CAAC,CAAA;oBACF,+DAA+D;oBAC/D,kEAAkE;oBAClE,6DAA6D;oBAC7D,8BAA8B;oBAC9B,IAAI,aAAa,EAAE,CAAC;wBAClB,KAAK,WAAW,CAAC,iBAAiB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;oBAC/D,CAAC;gBACH,CAAC;aACF,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -1,136 +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
- import { ValidationError, isValidationError, ValidationIssue } from "@ic-reactor/core";
8
- export { isValidationError, ValidationError };
9
- export type { ValidationIssue };
10
- /**
11
- * A map of field names to error messages.
12
- * This format is compatible with most form libraries.
13
- */
14
- export type FieldErrors = Record<string, string>;
15
- /**
16
- * A map of field names to arrays of error messages.
17
- * Use when you need to show multiple errors per field.
18
- */
19
- export type FieldErrorsMultiple = Record<string, string[]>;
20
- /**
21
- * Options for mapValidationErrors
22
- */
23
- export interface MapValidationErrorsOptions {
24
- /**
25
- * If true, returns all messages for each field as an array.
26
- * If false (default), returns only the first message for each field.
27
- */
28
- multiple?: boolean;
29
- }
30
- /**
31
- * Maps validation error issues to a simple field -> message object.
32
- * Returns the first error message for each field path, or every message with
33
- * `{ multiple: true }`. Issues about the whole argument (an empty path) are
34
- * filed under `""`.
35
- *
36
- * @example
37
- * ```tsx
38
- * const { mutate } = useActorMutation({
39
- * functionName: "transfer",
40
- * onError: (error) => {
41
- * if (isValidationError(error)) {
42
- * const fieldErrors = mapValidationErrors(error)
43
- * // { to: "Recipient is required", amount: "Must be a number" }
44
- *
45
- * // Use with React Hook Form
46
- * Object.entries(fieldErrors).forEach(([field, message]) => {
47
- * form.setError(field, { message })
48
- * })
49
- * }
50
- * }
51
- * })
52
- * ```
53
- */
54
- export declare function mapValidationErrors(error: ValidationError, options?: {
55
- multiple?: false;
56
- }): FieldErrors;
57
- export declare function mapValidationErrors(error: ValidationError, options: {
58
- multiple: true;
59
- }): FieldErrorsMultiple;
60
- export declare function mapValidationErrors(error: ValidationError, options?: MapValidationErrorsOptions): FieldErrors | FieldErrorsMultiple;
61
- /**
62
- * Gets error message for a specific field from a ValidationError.
63
- * Returns undefined if no error exists for that field. Pass `""` for issues
64
- * about the whole argument (an empty path), the key `mapValidationErrors`
65
- * files them under.
66
- *
67
- * @example
68
- * ```tsx
69
- * if (isValidationError(error)) {
70
- * const toError = getFieldError(error, "to")
71
- * const amountError = getFieldError(error, "amount")
72
- * }
73
- * ```
74
- */
75
- export declare function getFieldError(error: ValidationError, fieldName: string): string | undefined;
76
- /**
77
- * Gets all error messages for a specific field from a ValidationError.
78
- * Returns empty array if no errors exist for that field. Pass `""` for issues
79
- * about the whole argument (an empty path).
80
- *
81
- * @example
82
- * ```tsx
83
- * if (isValidationError(error)) {
84
- * const amountErrors = getFieldErrors(error, "amount")
85
- * // ["Amount is required", "Amount must be positive"]
86
- * }
87
- * ```
88
- */
89
- export declare function getFieldErrors(error: ValidationError, fieldName: string): string[];
90
- /**
91
- * Checks if a given error is a ValidationError and optionally
92
- * extracts field errors in one step.
93
- *
94
- * @example
95
- * ```tsx
96
- * const { mutateAsync } = useActorMutation({ functionName: "transfer" })
97
- *
98
- * const handleSubmit = async (data) => {
99
- * try {
100
- * await mutateAsync([data])
101
- * } catch (error) {
102
- * const fieldErrors = extractValidationErrors(error)
103
- * if (fieldErrors) {
104
- * // Handle validation errors
105
- * Object.entries(fieldErrors).forEach(([field, message]) => {
106
- * form.setError(field, { message })
107
- * })
108
- * } else {
109
- * // Handle other errors
110
- * console.error(error)
111
- * }
112
- * }
113
- * }
114
- * ```
115
- */
116
- export declare function extractValidationErrors(error: unknown): FieldErrors | null;
117
- /**
118
- * React hook-friendly error handler that extracts validation errors.
119
- * Returns a callback suitable for onError handlers.
120
- *
121
- * @example
122
- * ```tsx
123
- * const [fieldErrors, setFieldErrors] = useState<FieldErrors>({})
124
- *
125
- * const { mutate } = useActorMutation({
126
- * functionName: "transfer",
127
- * onError: handleValidationError(setFieldErrors),
128
- * })
129
- *
130
- * // In JSX
131
- * <input name="to" />
132
- * {fieldErrors.to && <span className="error">{fieldErrors.to}</span>}
133
- * ```
134
- */
135
- export declare function handleValidationError(setFieldErrors: (errors: FieldErrors) => void, onOtherError?: (error: Error) => void): (error: Error) => void;
136
- //# sourceMappingURL=validation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,eAAe,EAChB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,CAAA;AAC7C,YAAY,EAAE,eAAe,EAAE,CAAA;AAE/B;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEhD;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;AAE1D;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAWD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,eAAe,EACtB,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAA;CAAE,GAC7B,WAAW,CAAA;AACd,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE;IAAE,QAAQ,EAAE,IAAI,CAAA;CAAE,GAC1B,mBAAmB,CAAA;AACtB,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,eAAe,EACtB,OAAO,CAAC,EAAE,0BAA0B,GACnC,WAAW,GAAG,mBAAmB,CAAA;AAkCpC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAGpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,MAAM,GAChB,MAAM,EAAE,CAIV;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAK1E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CACnC,cAAc,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,EAC7C,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GACpC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CASxB"}
@@ -1,144 +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
- import { ValidationError, isValidationError, } from "@ic-reactor/core";
8
- // Re-export for convenience
9
- export { isValidationError, ValidationError };
10
- /**
11
- * The field an issue belongs to: the first segment of its path, as a string.
12
- * An issue with an empty path is about the whole argument (a zod object-level
13
- * `.refine()`, or any issue of a primitive argument) and belongs to `""`.
14
- */
15
- function fieldNameOf(issue) {
16
- return String(issue.path[0] ?? "");
17
- }
18
- export function mapValidationErrors(error, options) {
19
- // Collected in a Map, not a plain object: a field named like an
20
- // Object.prototype member (`constructor`, `toString`, `__proto__`) read that
21
- // member back as if the field were already filled, which dropped its issue,
22
- // and threw on `.push` with `multiple`. `Object.fromEntries` then creates
23
- // every field as an own property, `__proto__` included.
24
- if (options?.multiple) {
25
- const messages = new Map();
26
- for (const issue of error.issues) {
27
- const fieldName = fieldNameOf(issue);
28
- const fieldMessages = messages.get(fieldName);
29
- if (fieldMessages) {
30
- fieldMessages.push(issue.message);
31
- }
32
- else {
33
- messages.set(fieldName, [issue.message]);
34
- }
35
- }
36
- return Object.fromEntries(messages);
37
- }
38
- const messages = new Map();
39
- for (const issue of error.issues) {
40
- const fieldName = fieldNameOf(issue);
41
- if (!messages.get(fieldName)) {
42
- messages.set(fieldName, issue.message);
43
- }
44
- }
45
- return Object.fromEntries(messages);
46
- }
47
- /**
48
- * Gets error message for a specific field from a ValidationError.
49
- * Returns undefined if no error exists for that field. Pass `""` for issues
50
- * about the whole argument (an empty path), the key `mapValidationErrors`
51
- * files them under.
52
- *
53
- * @example
54
- * ```tsx
55
- * if (isValidationError(error)) {
56
- * const toError = getFieldError(error, "to")
57
- * const amountError = getFieldError(error, "amount")
58
- * }
59
- * ```
60
- */
61
- export function getFieldError(error, fieldName) {
62
- const issue = error.issues.find((i) => fieldNameOf(i) === fieldName);
63
- return issue?.message;
64
- }
65
- /**
66
- * Gets all error messages for a specific field from a ValidationError.
67
- * Returns empty array if no errors exist for that field. Pass `""` for issues
68
- * about the whole argument (an empty path).
69
- *
70
- * @example
71
- * ```tsx
72
- * if (isValidationError(error)) {
73
- * const amountErrors = getFieldErrors(error, "amount")
74
- * // ["Amount is required", "Amount must be positive"]
75
- * }
76
- * ```
77
- */
78
- export function getFieldErrors(error, fieldName) {
79
- return error.issues
80
- .filter((i) => fieldNameOf(i) === fieldName)
81
- .map((i) => i.message);
82
- }
83
- /**
84
- * Checks if a given error is a ValidationError and optionally
85
- * extracts field errors in one step.
86
- *
87
- * @example
88
- * ```tsx
89
- * const { mutateAsync } = useActorMutation({ functionName: "transfer" })
90
- *
91
- * const handleSubmit = async (data) => {
92
- * try {
93
- * await mutateAsync([data])
94
- * } catch (error) {
95
- * const fieldErrors = extractValidationErrors(error)
96
- * if (fieldErrors) {
97
- * // Handle validation errors
98
- * Object.entries(fieldErrors).forEach(([field, message]) => {
99
- * form.setError(field, { message })
100
- * })
101
- * } else {
102
- * // Handle other errors
103
- * console.error(error)
104
- * }
105
- * }
106
- * }
107
- * ```
108
- */
109
- export function extractValidationErrors(error) {
110
- if (isValidationError(error)) {
111
- return mapValidationErrors(error);
112
- }
113
- return null;
114
- }
115
- /**
116
- * React hook-friendly error handler that extracts validation errors.
117
- * Returns a callback suitable for onError handlers.
118
- *
119
- * @example
120
- * ```tsx
121
- * const [fieldErrors, setFieldErrors] = useState<FieldErrors>({})
122
- *
123
- * const { mutate } = useActorMutation({
124
- * functionName: "transfer",
125
- * onError: handleValidationError(setFieldErrors),
126
- * })
127
- *
128
- * // In JSX
129
- * <input name="to" />
130
- * {fieldErrors.to && <span className="error">{fieldErrors.to}</span>}
131
- * ```
132
- */
133
- export function handleValidationError(setFieldErrors, onOtherError) {
134
- return (error) => {
135
- const fieldErrors = extractValidationErrors(error);
136
- if (fieldErrors) {
137
- setFieldErrors(fieldErrors);
138
- }
139
- else if (onOtherError) {
140
- onOtherError(error);
141
- }
142
- };
143
- }
144
- //# sourceMappingURL=validation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,eAAe,EACf,iBAAiB,GAElB,MAAM,kBAAkB,CAAA;AAEzB,4BAA4B;AAC5B,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,CAAA;AA0B7C;;;;GAIG;AACH,SAAS,WAAW,CAAC,KAAsB;IACzC,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;AACpC,CAAC;AAsCD,MAA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AC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAA;IACpE,OAAO,KAAK,EAAE,OAAO,CAAA;AACvB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAsB,EACtB,SAAiB;IAEjB,OAAO,KAAK,CAAC,MAAM;SAChB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;SAC3C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;AAC1B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACpD,IAAI,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAA;IACnC,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,qBAAqB,CACnC,cAA6C,EAC7C,YAAqC;IAErC,OAAO,CAAC,KAAY,EAAE,EAAE;QACtB,MAAM,WAAW,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAA;QAClD,IAAI,WAAW,EAAE,CAAC;YAChB,cAAc,CAAC,WAAW,CAAC,CAAA;QAC7B,CAAC;aAAM,IAAI,YAAY,EAAE,CAAC;YACxB,YAAY,CAAC,KAAK,CAAC,CAAA;QACrB,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
@@ -1,273 +0,0 @@
1
- /**
2
- * Bridges IC Reactor's stable authentication options onto whichever
3
- * `@icp-sdk/auth` major is installed.
4
- *
5
- * `@icp-sdk/auth` v9 reshaped the `AuthClient` constructor and v10 moved its
6
- * `@icp-sdk/core` peer to `^6`. The *method* surface IC Reactor calls --
7
- * `signIn`, `signOut`, `getIdentity`, `isAuthenticated`, `requestAttributes`,
8
- * `memoize` -- is byte-identical across v8 and v10, so only the option objects
9
- * handed to the constructor and to `signIn` have to be translated.
10
- *
11
- * The translation lives here rather than in `AuthenticationManager` so that
12
- * {@link AuthenticationClientOptions} stays IC Reactor's own contract. Callers
13
- * keep writing `identityProvider: "https://id.ai/authorize"` whichever peer
14
- * they installed, and the shapes diverge only at the boundary.
15
- *
16
- * Why both majors: v8 peers `@icp-sdk/core@^5` while IC Reactor needs `^6`, so
17
- * a strict `npm install` resolving v8 fails with `ERESOLVE` unless the app adds
18
- * an `overrides` block. v10 is the first release whose peer is `^6`, which
19
- * removes that workaround -- but pinning v10 alone would break every app
20
- * already installed on v8.
21
- */
22
- import type {
23
- AuthClientSignInOptions,
24
- AuthenticationClientOptions,
25
- } from "./types.js"
26
-
27
- /**
28
- * Which options contract the installed `AuthClient` accepts.
29
- *
30
- * - `legacy` -- v8. `identityProvider` is a URL; `storage`, `keyType`,
31
- * `idleOptions` and `identity` are constructor options; `signIn` takes
32
- * `targets`.
33
- * - `session` -- v9/v10. `identityProvider` is an `{ authorizeUrl, canisterId }`
34
- * pair, credentials moved behind `credentialStorage`, idle moved to the
35
- * identity provider canister, and `signIn` no longer takes `targets`.
36
- */
37
- export type AuthClientFlavor = "legacy" | "session"
38
-
39
- /** The `{ authorizeUrl, canisterId }` pair a v9+ client names a deployment by. */
40
- export interface SessionIdentityProvider {
41
- authorizeUrl: string | URL
42
- canisterId: string
43
- }
44
-
45
- /**
46
- * Which canister a v9+ client should pair with the configured
47
- * `identityProvider` URL, as `AuthenticationManager` works it out.
48
- *
49
- * - `mainnet`: the URL is mainnet's and nothing overrides the canister, so the
50
- * option is omitted and the client uses mainnet for both halves.
51
- * - `pair`: the canister is known, from `internetIdentityId` or because the URL
52
- * is one IC Reactor derived for a local deployment.
53
- * - `unknown`: a URL the caller configured with no canister to go with it.
54
- */
55
- export type IdentityProviderPairing =
56
- | { kind: "mainnet" }
57
- | { kind: "pair"; canisterId: string }
58
- | { kind: "unknown" }
59
-
60
- /**
61
- * Detects the contract from the constructor itself rather than from the
62
- * module's exports.
63
- *
64
- * `getStatus`, `getPrincipal`, `subscribe` and `dispose` were added to
65
- * `AuthClient` in v9 and have no v8 counterpart. Reading them off the prototype
66
- * beats sniffing the module namespace: a bundler may drop an unreferenced named
67
- * export (`IdbStorage`, `IdleManager`) from the namespace object it synthesizes
68
- * for a dynamic import, but it never drops a class's own methods.
69
- *
70
- * Two markers rather than one, because a single name is a coincidence away from
71
- * matching some future shim. An unrecognised constructor is treated as `legacy`
72
- * -- the shape IC Reactor's own options already mirror, so a wrong guess there
73
- * passes the values through untouched instead of rewriting them into a shape
74
- * nothing understands.
75
- */
76
- export function detectAuthClientFlavor(AuthClient: unknown): AuthClientFlavor {
77
- const prototype = (AuthClient as { prototype?: Record<string, unknown> })
78
- ?.prototype
79
-
80
- if (!prototype) {
81
- return "legacy"
82
- }
83
-
84
- return typeof prototype.getStatus === "function" &&
85
- typeof prototype.getPrincipal === "function"
86
- ? "session"
87
- : "legacy"
88
- }
89
-
90
- /**
91
- * Detects the contract of a client the caller built and passed in.
92
- *
93
- * Such a client never goes through the module loader, so there is no
94
- * constructor to hand {@link detectAuthClientFlavor}. The markers are the same
95
- * two methods, reached through the instance instead of the prototype.
96
- */
97
- export function detectAuthClientInstanceFlavor(
98
- client: unknown
99
- ): AuthClientFlavor {
100
- const instance = client as Record<string, unknown> | undefined
101
-
102
- return typeof instance?.getStatus === "function" &&
103
- typeof instance?.getPrincipal === "function"
104
- ? "session"
105
- : "legacy"
106
- }
107
-
108
- /**
109
- * Options a `session`-era client drops on the floor, and what replaced them.
110
- *
111
- * Each is a real capability in v8 with no v9+ constructor equivalent, so the
112
- * only honest thing to do is say so rather than pass a key that is ignored.
113
- */
114
- const DROPPED_CONSTRUCTOR_OPTIONS: Record<string, string> = {
115
- storage:
116
- "`storage` (an AuthClientStorage) has no v9+ equivalent: credentials moved behind `credentialStorage`, whose store also generates identities and holds a delegation alongside each key, so an AuthClientStorage cannot be adapted into one. Construct the client yourself and pass it as `authClient` to keep a custom store.",
117
- keyType:
118
- "`keyType` was removed in v9+: the credential store decides the key type, because a store that has to serialise needs an extractable key and one that does not should not hold one.",
119
- idleOptions:
120
- "`idleOptions` was removed in v9+: the idle timeout belongs to the identity provider canister. Pass `maxTimeToIdle` to `login()` instead, and set `disableBrowserActivity` in the AuthenticationManager options to stop the client watching the browser.",
121
- identity:
122
- "`identity` was removed from v9+ constructor options: the agent signs as the session rather than as an identity handed in at construction.",
123
- }
124
-
125
- /** Emits each distinct warning once per process, so a render loop cannot spam. */
126
- const warned = new Set<string>()
127
-
128
- function warnOnce(key: string, message: string) {
129
- if (warned.has(key)) return
130
- warned.add(key)
131
- console.warn(`[ic-reactor] ${message}`)
132
- }
133
-
134
- /** @internal Test seam -- lets a suite assert the first warning every time. */
135
- export function resetAuthCompatWarnings() {
136
- warned.clear()
137
- }
138
-
139
- /**
140
- * Translates IC Reactor's constructor options into the installed client's shape.
141
- *
142
- * On `legacy` the object is already the right shape and is returned as-is,
143
- * except for `disableBrowserActivity`. That option exists only on v10, so it is
144
- * dropped with a one-time warning rather than handed to a v8 client that
145
- * ignores it.
146
- *
147
- * On `session` the identity provider becomes a pair. The canister is not
148
- * derived from the URL, because v9+ is explicit that the origin serving a
149
- * ceremony is not a promise about which canister mints there. `pairing` says
150
- * which canister goes with the URL. When nothing does, this throws rather than
151
- * guessing: a guessed canister sends the delegation calls to a different
152
- * deployment than the one the user signs in at, and sign-in fails later with an
153
- * error that names neither.
154
- *
155
- * @param options - IC Reactor's resolved options, in the v8-shaped contract.
156
- * @param flavor - The contract the installed client accepts.
157
- * @param pairing - Which canister goes with `options.identityProvider`.
158
- * @param agentOptions - Options for the agent a v9+ client mints delegations
159
- * with. v8 has no such agent, so a `legacy` client never receives them.
160
- */
161
- export function toAuthClientConstructorOptions(
162
- options: AuthenticationClientOptions | undefined,
163
- flavor: AuthClientFlavor,
164
- pairing: IdentityProviderPairing = { kind: "unknown" },
165
- agentOptions?: Record<string, unknown>
166
- ): AuthenticationClientOptions | Record<string, unknown> | undefined {
167
- if (!options) {
168
- return options
169
- }
170
-
171
- if (flavor === "legacy") {
172
- if (options.disableBrowserActivity === undefined) {
173
- return options
174
- }
175
- warnOnce(
176
- "constructor:disableBrowserActivity",
177
- "`disableBrowserActivity` needs @icp-sdk/auth v10 and is ignored by v8, which has no equivalent. On v8, `idleOptions` controls idle handling."
178
- )
179
- const { disableBrowserActivity: _disableBrowserActivity, ...legacy } =
180
- options
181
- return legacy
182
- }
183
-
184
- // Prefixed with `_` because they are destructured only to keep them out of
185
- // `carried`: a v9+ constructor has no equivalent for any of them, and the
186
- // loop below is what actually reports each one that was set.
187
- const {
188
- identityProvider,
189
- storage: _storage,
190
- keyType: _keyType,
191
- idleOptions: _idleOptions,
192
- identity: _identity,
193
- ...carried
194
- } = options
195
-
196
- for (const [name, explanation] of Object.entries(
197
- DROPPED_CONSTRUCTOR_OPTIONS
198
- )) {
199
- if ((options as Record<string, unknown>)[name] !== undefined) {
200
- warnOnce(`constructor:${name}`, explanation)
201
- }
202
- }
203
- const translated: Record<string, unknown> = { ...carried }
204
-
205
- if (agentOptions !== undefined) {
206
- translated.agentOptions = agentOptions
207
- }
208
-
209
- if (identityProvider !== undefined) {
210
- if (pairing.kind === "unknown") {
211
- throw new Error(
212
- `[ic-reactor] identityProvider ${String(identityProvider)} needs internetIdentityId with @icp-sdk/auth v10, which names a provider by its authorize URL and the canister that mints its delegations. Set internetIdentityId to the canister that serves that URL.`
213
- )
214
- }
215
- // An absent option is how v9+ says "both values are mainnet's".
216
- if (pairing.kind === "pair") {
217
- translated.identityProvider = {
218
- authorizeUrl: identityProvider,
219
- canisterId: pairing.canisterId,
220
- } satisfies SessionIdentityProvider
221
- }
222
- }
223
-
224
- return translated
225
- }
226
-
227
- /**
228
- * Translates `signIn` options into the installed client's shape.
229
- *
230
- * `targets` is the one that matters. v8 forwards it to restrict the delegation
231
- * to named canisters; v9+ removed it, and scoping is decided by the identity
232
- * provider against the app's own canister. Passing it to a v9+ client does not
233
- * fail -- it is simply ignored, and the delegation that comes back is broader
234
- * than the caller asked for. That is a security-relevant difference, so it
235
- * warns unconditionally rather than only in development.
236
- *
237
- * `maxTimeToIdle` goes the other way. It exists only on v10, so a v10 client
238
- * receives it, and a v8 client, whose sign-in has no idle limit, gets it
239
- * dropped with a one-time warning.
240
- */
241
- export function toAuthClientSignInOptions(
242
- options: AuthClientSignInOptions | undefined,
243
- flavor: AuthClientFlavor
244
- ): AuthClientSignInOptions | undefined {
245
- if (!options) {
246
- return options
247
- }
248
-
249
- if (flavor === "legacy") {
250
- if (options.maxTimeToIdle === undefined) {
251
- return options
252
- }
253
- warnOnce(
254
- "signIn:maxTimeToIdle",
255
- "`maxTimeToIdle` needs @icp-sdk/auth v10 and is ignored by v8, whose sign-in has no idle limit. On v8, set `idleOptions` instead."
256
- )
257
- const { maxTimeToIdle: _maxTimeToIdle, ...legacy } = options
258
- return legacy
259
- }
260
-
261
- const { targets, ...carried } = options
262
-
263
- if (targets !== undefined) {
264
- // Every time, not once: each sign-in that passes `targets` receives a
265
- // delegation broader than it asked for, and a warning spent on an earlier
266
- // one says nothing about this one.
267
- console.warn(
268
- "[ic-reactor] `targets` was removed in @icp-sdk/auth v9+ and is ignored: the delegation you receive is NOT restricted to those canisters. The identity provider scopes a session to the application canister instead. Remove `targets`, or pin @icp-sdk/auth to ^8 if you depend on canister-scoped delegations."
269
- )
270
- }
271
-
272
- return carried
273
- }