@molecule/app-angular 3.3.1 → 3.6.0

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 (114) hide show
  1. package/README.md +4049 -1255
  2. package/dist/chat.d.ts.map +1 -1
  3. package/dist/chat.js +3 -2
  4. package/dist/chat.js.map +1 -1
  5. package/dist/hooks/external-store.d.ts +32 -0
  6. package/dist/hooks/external-store.d.ts.map +1 -0
  7. package/dist/hooks/external-store.js +62 -0
  8. package/dist/hooks/external-store.js.map +1 -0
  9. package/dist/hooks/index.d.ts +24 -0
  10. package/dist/hooks/index.d.ts.map +1 -0
  11. package/dist/hooks/index.js +24 -0
  12. package/dist/hooks/index.js.map +1 -0
  13. package/dist/hooks/use-ai-models.d.ts +53 -0
  14. package/dist/hooks/use-ai-models.d.ts.map +1 -0
  15. package/dist/hooks/use-ai-models.js +167 -0
  16. package/dist/hooks/use-ai-models.js.map +1 -0
  17. package/dist/hooks/use-async.d.ts +129 -0
  18. package/dist/hooks/use-async.d.ts.map +1 -0
  19. package/dist/hooks/use-async.js +194 -0
  20. package/dist/hooks/use-async.js.map +1 -0
  21. package/dist/hooks/use-auth-flows.d.ts +226 -0
  22. package/dist/hooks/use-auth-flows.d.ts.map +1 -0
  23. package/dist/hooks/use-auth-flows.js +481 -0
  24. package/dist/hooks/use-auth-flows.js.map +1 -0
  25. package/dist/hooks/use-auth.d.ts +85 -0
  26. package/dist/hooks/use-auth.d.ts.map +1 -0
  27. package/dist/hooks/use-auth.js +104 -0
  28. package/dist/hooks/use-auth.js.map +1 -0
  29. package/dist/hooks/use-forms.d.ts +174 -0
  30. package/dist/hooks/use-forms.d.ts.map +1 -0
  31. package/dist/hooks/use-forms.js +221 -0
  32. package/dist/hooks/use-forms.js.map +1 -0
  33. package/dist/hooks/use-http.d.ts +163 -0
  34. package/dist/hooks/use-http.d.ts.map +1 -0
  35. package/dist/hooks/use-http.js +198 -0
  36. package/dist/hooks/use-http.js.map +1 -0
  37. package/dist/hooks/use-ide.d.ts +208 -0
  38. package/dist/hooks/use-ide.d.ts.map +1 -0
  39. package/dist/hooks/use-ide.js +217 -0
  40. package/dist/hooks/use-ide.js.map +1 -0
  41. package/dist/hooks/use-logger.d.ts +40 -0
  42. package/dist/hooks/use-logger.d.ts.map +1 -0
  43. package/dist/hooks/use-logger.js +56 -0
  44. package/dist/hooks/use-logger.js.map +1 -0
  45. package/dist/hooks/use-native.d.ts +218 -0
  46. package/dist/hooks/use-native.d.ts.map +1 -0
  47. package/dist/hooks/use-native.js +173 -0
  48. package/dist/hooks/use-native.js.map +1 -0
  49. package/dist/hooks/use-profile-form.d.ts +113 -0
  50. package/dist/hooks/use-profile-form.d.ts.map +1 -0
  51. package/dist/hooks/use-profile-form.js +253 -0
  52. package/dist/hooks/use-profile-form.js.map +1 -0
  53. package/dist/hooks/use-router.d.ts +219 -0
  54. package/dist/hooks/use-router.d.ts.map +1 -0
  55. package/dist/hooks/use-router.js +266 -0
  56. package/dist/hooks/use-router.js.map +1 -0
  57. package/dist/hooks/use-storage.d.ts +142 -0
  58. package/dist/hooks/use-storage.d.ts.map +1 -0
  59. package/dist/hooks/use-storage.js +299 -0
  60. package/dist/hooks/use-storage.js.map +1 -0
  61. package/dist/hooks/use-store.d.ts +81 -0
  62. package/dist/hooks/use-store.d.ts.map +1 -0
  63. package/dist/hooks/use-store.js +143 -0
  64. package/dist/hooks/use-store.js.map +1 -0
  65. package/dist/hooks/use-theme.d.ts +59 -0
  66. package/dist/hooks/use-theme.d.ts.map +1 -0
  67. package/dist/hooks/use-theme.js +117 -0
  68. package/dist/hooks/use-theme.js.map +1 -0
  69. package/dist/hooks/use-translation.d.ts +91 -0
  70. package/dist/hooks/use-translation.d.ts.map +1 -0
  71. package/dist/hooks/use-translation.js +152 -0
  72. package/dist/hooks/use-translation.js.map +1 -0
  73. package/dist/hooks/use-verify-payment-return.d.ts +86 -0
  74. package/dist/hooks/use-verify-payment-return.d.ts.map +1 -0
  75. package/dist/hooks/use-verify-payment-return.js +167 -0
  76. package/dist/hooks/use-verify-payment-return.js.map +1 -0
  77. package/dist/hooks/use-version.d.ts +49 -0
  78. package/dist/hooks/use-version.d.ts.map +1 -0
  79. package/dist/hooks/use-version.js +70 -0
  80. package/dist/hooks/use-version.js.map +1 -0
  81. package/dist/i18n-reactive.d.ts +2 -5
  82. package/dist/i18n-reactive.d.ts.map +1 -1
  83. package/dist/i18n-reactive.js.map +1 -1
  84. package/dist/index.d.ts +8 -0
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +8 -0
  87. package/dist/index.js.map +1 -1
  88. package/dist/inject.d.ts +24 -0
  89. package/dist/inject.d.ts.map +1 -0
  90. package/dist/inject.js +33 -0
  91. package/dist/inject.js.map +1 -0
  92. package/dist/link.d.ts +63 -0
  93. package/dist/link.d.ts.map +1 -0
  94. package/dist/link.js +82 -0
  95. package/dist/link.js.map +1 -0
  96. package/dist/maybe-signal.d.ts +26 -0
  97. package/dist/maybe-signal.d.ts.map +1 -0
  98. package/dist/maybe-signal.js +20 -0
  99. package/dist/maybe-signal.js.map +1 -0
  100. package/dist/providers.d.ts +24 -0
  101. package/dist/providers.d.ts.map +1 -1
  102. package/dist/providers.js +44 -3
  103. package/dist/providers.js.map +1 -1
  104. package/dist/session-ready.d.ts +41 -0
  105. package/dist/session-ready.d.ts.map +1 -0
  106. package/dist/session-ready.js +79 -0
  107. package/dist/session-ready.js.map +1 -0
  108. package/dist/tokens.d.ts +15 -0
  109. package/dist/tokens.d.ts.map +1 -1
  110. package/dist/tokens.js +12 -0
  111. package/dist/tokens.js.map +1 -1
  112. package/dist/types.d.ts +14 -1
  113. package/dist/types.d.ts.map +1 -1
  114. package/package.json +5 -5
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Angular functions for async state, mirroring `usePromise`, `useAsyncState`
3
+ * and `useOptimisticValue` from `@molecule/app-react`.
4
+ *
5
+ * `usePromise` and `useAsyncState` return a plain mutable TUPLE whose state
6
+ * member is updated in place: the tuple is the mounted result for this
7
+ * component instance's whole lifetime, and every snapshot of it must show the
8
+ * state at that moment (React re-renders a new state object into the same
9
+ * tuple; this port mutates the same tuple's members).
10
+ *
11
+ * @module
12
+ */
13
+ import { computed, DestroyRef, effect, inject, untracked } from '@angular/core';
14
+ import { createOptimisticValue, shallowEqual } from '@molecule/app-state';
15
+ import { readMaybeSignal } from '../maybe-signal.js';
16
+ import { useExternalStore } from './external-store.js';
17
+ /**
18
+ * Wraps an async function with the state of its latest call. Call it in an
19
+ * injection context (a component field initializer or constructor).
20
+ *
21
+ * For one UI action, pass `state.status === 'pending'` to a button's loading
22
+ * input. The control then refuses input while the request is pending and
23
+ * re-enables when the tracked call settles. Handle the returned promise's
24
+ * rejection; the hook also records the failure in `state.error`.
25
+ *
26
+ * This hook tracks the latest call: it does not serialize invocations or
27
+ * cancel their network requests. An explicit reset/cancel changes the tracked
28
+ * state, so it is not proof that an outstanding request has stopped. Use an
29
+ * app-owned queue when every click must be accepted in order.
30
+ *
31
+ * @param asyncFn - The async function to wrap.
32
+ * @returns A tuple of `[state, wrappedFunction]`; the state object is updated
33
+ * in place for this instance's lifetime.
34
+ */
35
+ export const usePromise = (asyncFn) => {
36
+ const destroyRef = inject(DestroyRef);
37
+ let unmounted = false;
38
+ destroyRef.onDestroy(() => {
39
+ unmounted = true;
40
+ });
41
+ let callId = 0;
42
+ // The state object is MUTATED in place: the tuple is returned once per
43
+ // instance and every later read of it must see the current call's state.
44
+ const state = {
45
+ status: 'idle',
46
+ value: null,
47
+ error: null,
48
+ cancel: (message) => {
49
+ callId += 1;
50
+ if (!unmounted) {
51
+ state.status = 'rejected';
52
+ state.error = message ? new Error(message) : null;
53
+ }
54
+ },
55
+ reset: () => {
56
+ if (!unmounted) {
57
+ state.status = 'idle';
58
+ state.value = null;
59
+ state.error = null;
60
+ }
61
+ },
62
+ };
63
+ const callAsyncFn = (...args) => {
64
+ callId += 1;
65
+ const thisCallId = callId;
66
+ if (!unmounted) {
67
+ state.status = 'pending';
68
+ state.error = null;
69
+ }
70
+ const promise = asyncFn(...args);
71
+ return promise.then((resolved) => {
72
+ if (thisCallId === callId && !unmounted) {
73
+ state.status = 'resolved';
74
+ state.value = resolved;
75
+ state.error = null;
76
+ }
77
+ return resolved;
78
+ }, (err) => {
79
+ const rejection = err instanceof Error ? err : new Error(String(err));
80
+ if (thisCallId === callId && !unmounted) {
81
+ state.status = 'rejected';
82
+ state.error = rejection;
83
+ }
84
+ throw rejection;
85
+ });
86
+ };
87
+ return [state, callAsyncFn];
88
+ };
89
+ /**
90
+ * Like `useState` but accepts Promises and supports partial state extension.
91
+ * Call it in an injection context.
92
+ *
93
+ * There is NO latest-wins guard (pinned like React's): whatever settles last
94
+ * wins, even over a newer synchronous set.
95
+ *
96
+ * @param initialState - Initial state value.
97
+ * @returns A tuple of `[state, setState, extendState]`; the state member is
98
+ * replaced in place for this instance's lifetime.
99
+ */
100
+ export const useAsyncState = (initialState) => {
101
+ // The tuple's first member is replaced on every change; the tuple itself is
102
+ // the mounted result for this instance's lifetime.
103
+ const tuple = [
104
+ initialState,
105
+ async (_nextState) => {
106
+ try {
107
+ const nextState = await _nextState;
108
+ const prev = tuple[0];
109
+ const next = typeof nextState === 'function' ? nextState(prev) : nextState;
110
+ tuple[0] = next;
111
+ }
112
+ catch (_error) {
113
+ // Silently swallow errors from resolved Promises to avoid unhandled
114
+ // rejections, exactly like React's hook.
115
+ }
116
+ },
117
+ async (_partial) => {
118
+ try {
119
+ const partial = await _partial;
120
+ const prev = tuple[0];
121
+ const resolved = typeof partial === 'function' ? partial(prev) : partial;
122
+ tuple[0] = { ...prev, ...resolved };
123
+ }
124
+ catch (_error) {
125
+ // Silently swallow errors from resolved Promises to avoid unhandled
126
+ // rejections, exactly like React's hook.
127
+ }
128
+ },
129
+ ];
130
+ return tuple;
131
+ };
132
+ /**
133
+ * A server-backed value — a favorite, follow, like or bookmark button, a
134
+ * rating, a quantity, a setting switch — that changes on the first read after
135
+ * a tap and is saved one change at a time, in order. Call it in an injection
136
+ * context.
137
+ *
138
+ * Only a failure of the newest change puts the server value back. A new server
139
+ * `value` is taken only while nothing is being saved, so a parent re-render or
140
+ * a refetch of older data never flips the control mid-save.
141
+ *
142
+ * The options may be a signal, and the controller follows them the way React's
143
+ * re-render does: `commit`, `equals` and `onError` are read from the options
144
+ * the signal holds at the moment they run, and a server `value` that differs
145
+ * (by `equals`) from the last one received is synced in — kept as the fallback
146
+ * while a save runs — with the controller and any pending save kept on the same
147
+ * component.
148
+ *
149
+ * @param options - The server's current value and how to save a change (or a
150
+ * signal of them).
151
+ * @returns The value to render, whether a save is pending, the newest failure,
152
+ * and `set`/`update`.
153
+ */
154
+ export const useOptimisticValue = (options) => {
155
+ const initial = readMaybeSignal(options);
156
+ // The latest options, exactly like React's `latest` ref (republished on
157
+ // every committed render): the controller's wrappers read it when they run.
158
+ let latest = initial;
159
+ const controller = createOptimisticValue({
160
+ value: initial.value,
161
+ commit: (next, previous, confirm) => latest.commit(next, previous, confirm),
162
+ equals: (a, b) => (latest.equals ?? shallowEqual)(a, b),
163
+ onError: (error, value) => latest.onError?.(error, value),
164
+ });
165
+ // The last server value this controller received, like React's `received`
166
+ // ref + effect: equal (by the options' `equals`) → nothing; different → the
167
+ // new server value is synced in (immediately when idle, kept as fallback
168
+ // while saving). React's effect runs the check on mount too, so the initial
169
+ // options are checked the same way.
170
+ let received = initial.value;
171
+ const considerServerValue = (opts) => {
172
+ if ((opts.equals ?? shallowEqual)(received, opts.value))
173
+ return;
174
+ received = opts.value;
175
+ controller.sync(opts.value);
176
+ };
177
+ considerServerValue(initial);
178
+ const state = useExternalStore(() => controller.getState(), (notify) => controller.subscribe(notify));
179
+ effect(() => {
180
+ const next = readMaybeSignal(options);
181
+ if (next === latest)
182
+ return;
183
+ latest = next;
184
+ untracked(() => considerServerValue(next));
185
+ });
186
+ return {
187
+ value: computed(() => state().value),
188
+ pending: computed(() => state().pending),
189
+ error: computed(() => state().error),
190
+ set: (next) => controller.set(next),
191
+ update: (change) => controller.update(change),
192
+ };
193
+ };
194
+ //# sourceMappingURL=use-async.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-async.js","sourceRoot":"","sources":["../../src/hooks/use-async.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAe,SAAS,EAAE,MAAM,eAAe,CAAA;AAG5F,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAGzE,OAAO,EAAoB,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAoBtD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,OAAU,EAIV,EAAE;IAGF,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAA;IACrC,IAAI,SAAS,GAAG,KAAK,CAAA;IACrB,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE;QACxB,SAAS,GAAG,IAAI,CAAA;IAClB,CAAC,CAAC,CAAA;IACF,IAAI,MAAM,GAAG,CAAC,CAAA;IAEd,uEAAuE;IACvE,yEAAyE;IACzE,MAAM,KAAK,GAAuB;QAChC,MAAM,EAAE,MAAM;QACd,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,IAAI;QACX,MAAM,EAAE,CAAC,OAAgB,EAAQ,EAAE;YACjC,MAAM,IAAI,CAAC,CAAA;YACX,IAAI,CAAC,SAAS,EAAE,CAAC;gBACf,KAAK,CAAC,MAAM,GAAG,UAAU,CAAA;gBACzB,KAAK,CAAC,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;YACnD,CAAC;QACH,CAAC;QACD,KAAK,EAAE,GAAS,EAAE;YAChB,IAAI,CAAC,SAAS,EAAE,C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CAAC,OAAO,CAAC,CAAA;QACrC,IAAI,IAAI,KAAK,MAAM;YAAE,OAAM;QAC3B,MAAM,GAAG,IAAI,CAAA;QACb,SAAS,CAAC,GAAG,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAA;IAC5C,CAAC,CAAC,CAAA;IAEF,OAAO;QACL,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC;QACpC,OAAO,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,OAAO,CAAC;QACxC,KAAK,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC;QACpC,GAAG,EAAE,CAAC,IAAO,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC;QACtC,MAAM,EAAE,CAAC,MAAyB,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC;KACjE,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Angular functions for the auth flows, mirroring `useLogin`, `useSignup`,
3
+ * `useChangePassword`, `usePasswordReset` and `useOAuth` from
4
+ * `@molecule/app-react`.
5
+ *
6
+ * The state fields of the tracked hooks are LIVE getters over the underlying
7
+ * `usePromise` state object: the result object is built once per instance (an
8
+ * Angular instantiation runs once), and every later read must show the
9
+ * current state, which React re-renders into a fresh result object.
10
+ *
11
+ * @module
12
+ */
13
+ import type { AuthResult, LoginCredentials, PasswordResetConfirm, PasswordResetRequest, RegisterData, RegisterExtraShape } from '@molecule/app-auth';
14
+ import { type MaybeSignal } from '../maybe-signal.js';
15
+ import { type UsePromiseState } from './use-async.js';
16
+ /**
17
+ * Return type for {@link useLogin}.
18
+ *
19
+ * @template T - The user profile the API returns.
20
+ */
21
+ export interface UseLoginReturn<T = unknown> {
22
+ /** The login state: `'idle'`, `'pending'`, `'resolved'` or `'rejected'`. */
23
+ readonly status: UsePromiseState<AuthResult<T>>['status'];
24
+ /** The resolved session, `null` before the first resolution. */
25
+ readonly value: UsePromiseState<AuthResult<T>>['value'];
26
+ /** The failure of the latest login. */
27
+ readonly error: UsePromiseState<AuthResult<T>>['error'];
28
+ /**
29
+ * Runs one tracked login.
30
+ *
31
+ * @param credentials - The credentials to sign in with.
32
+ * @returns The session.
33
+ */
34
+ login: (credentials: LoginCredentials) => Promise<AuthResult<T>>;
35
+ /** Returns the state to idle. */
36
+ reset: () => void;
37
+ }
38
+ /**
39
+ * Login with async state tracking. Call it in an injection context.
40
+ *
41
+ * Registration is available through `const { register } = useAuth()`;
42
+ * call `register({ email, password, name })` to create an account. There is
43
+ * no separate `useRegister` hook. Use `usePromise(register)` when the form
44
+ * needs the same pending/error tracking as this login hook.
45
+ *
46
+ * @returns Login state and action.
47
+ */
48
+ export declare function useLogin<T = unknown>(): UseLoginReturn<T>;
49
+ /**
50
+ * Return type for {@link useSignup}.
51
+ *
52
+ * @template T - The user profile the API returns.
53
+ * @template TRegister - The app's own registration fields (the second generic
54
+ * of `createJWTAuthClient<T, TRegister>`), so `signup()` is typed like the
55
+ * client's `register()`.
56
+ */
57
+ export interface UseSignupReturn<T = unknown, TRegister extends RegisterExtraShape<TRegister> = Record<never, never>> {
58
+ /** The signup state. */
59
+ readonly status: UsePromiseState<AuthResult<T>>['status'];
60
+ /** The resolved session, `null` before the first resolution. */
61
+ readonly value: UsePromiseState<AuthResult<T>>['value'];
62
+ /** The failure of the latest signup. */
63
+ readonly error: UsePromiseState<AuthResult<T>>['error'];
64
+ /**
65
+ * Runs one tracked registration (and signs the account in).
66
+ *
67
+ * @param data - The registration data.
68
+ * @returns The session.
69
+ */
70
+ signup: (data: RegisterData<TRegister>) => Promise<AuthResult<T>>;
71
+ /** Returns the state to idle. */
72
+ reset: () => void;
73
+ }
74
+ /**
75
+ * Registration with async state tracking. Call it in an injection context.
76
+ *
77
+ * @returns Signup state and action.
78
+ */
79
+ export declare function useSignup<T = unknown, TRegister extends RegisterExtraShape<TRegister> = Record<never, never>>(): UseSignupReturn<T, TRegister>;
80
+ /**
81
+ * Return type for {@link useChangePassword}.
82
+ */
83
+ export interface UseChangePasswordReturn {
84
+ /** The change state. */
85
+ readonly status: UsePromiseState<void>['status'];
86
+ /** The failure of the latest change. */
87
+ readonly error: UsePromiseState<void>['error'];
88
+ /**
89
+ * Runs one tracked password change.
90
+ *
91
+ * @param oldPassword - The current password.
92
+ * @param newPassword - The new password.
93
+ * @returns Resolves once changed.
94
+ */
95
+ changePassword: (oldPassword: string, newPassword: string) => Promise<void>;
96
+ /** Returns the state to idle. */
97
+ reset: () => void;
98
+ }
99
+ /**
100
+ * Changing a password with async state tracking. Call it in an injection
101
+ * context.
102
+ *
103
+ * @returns Change-password state and action.
104
+ */
105
+ export declare function useChangePassword(): UseChangePasswordReturn;
106
+ /**
107
+ * Return type for {@link usePasswordReset}.
108
+ */
109
+ export interface UsePasswordResetReturn {
110
+ /** The request half's state. */
111
+ readonly requestStatus: UsePromiseState<void>['status'];
112
+ /** The request half's failure. */
113
+ readonly requestError: UsePromiseState<void>['error'];
114
+ /** The confirm half's state. */
115
+ readonly confirmStatus: UsePromiseState<void>['status'];
116
+ /** The confirm half's failure. */
117
+ readonly confirmError: UsePromiseState<void>['error'];
118
+ /**
119
+ * Sends the reset email.
120
+ *
121
+ * @param data - The request data.
122
+ * @returns Resolves once sent.
123
+ */
124
+ requestReset: (data: PasswordResetRequest) => Promise<void>;
125
+ /**
126
+ * Submits the token and the new password.
127
+ *
128
+ * @param data - The confirm data.
129
+ * @returns Resolves once confirmed.
130
+ */
131
+ confirmReset: (data: PasswordResetConfirm) => Promise<void>;
132
+ /** Returns both halves to idle. */
133
+ reset: () => void;
134
+ }
135
+ /**
136
+ * The password reset flow with async state tracking, one tracker per step.
137
+ * Call it in an injection context.
138
+ *
139
+ * @returns Password reset state and actions.
140
+ */
141
+ export declare function usePasswordReset(): UsePasswordResetReturn;
142
+ /**
143
+ * Return type for {@link useOAuth}.
144
+ */
145
+ export interface UseOAuthReturn {
146
+ /**
147
+ * The supported provider names. A live getter: it reads the config the hook
148
+ * currently holds, so it follows a config passed as a signal the way React's
149
+ * re-rendered `providers` list does.
150
+ */
151
+ providers: string[];
152
+ /**
153
+ * Builds the initiation URL for one provider.
154
+ *
155
+ * @param provider - The provider name.
156
+ * @returns The URL.
157
+ */
158
+ getOAuthUrl: (provider: string) => string;
159
+ /**
160
+ * Full-page redirect to the provider (default). The opener page navigates
161
+ * away.
162
+ *
163
+ * @param provider - The provider name.
164
+ */
165
+ redirect: (provider: string) => void;
166
+ /**
167
+ * Open the provider in a popup so the opener page does NOT navigate. On
168
+ * success the session is established in the opener in place and
169
+ * `config.onSuccess` fires; on failure `config.onError` fires. Falls back to
170
+ * a full-page {@link redirect} when the popup is blocked.
171
+ *
172
+ * @param provider - The provider name.
173
+ */
174
+ loginViaPopup: (provider: string) => void;
175
+ }
176
+ /**
177
+ * OAuth configuration for {@link useOAuth}: the app's `oauthConfig` (from its `config.ts`),
178
+ * the same type under the same name in every framework binding.
179
+ */
180
+ export interface UseOAuthConfig {
181
+ /** Base URL for the API server (e.g. "https://api.example.com"). */
182
+ baseURL?: string;
183
+ /** List of supported OAuth provider names (e.g. ["google", "github"]). */
184
+ oauthProviders?: string[];
185
+ /** Path prefix for OAuth routes (defaults to "/oauth"). */
186
+ oauthEndpoint?: string;
187
+ /** Path for the OAuth login POST endpoint (defaults to "/users/log-in/oauth"). */
188
+ loginEndpoint?: string;
189
+ /** Callback after successful OAuth login. */
190
+ onSuccess?: () => void;
191
+ /** Callback on OAuth login failure. */
192
+ onError?: (error: string) => void;
193
+ /**
194
+ * How the page leaves for the provider: {@link UseOAuthReturn.redirect} and the
195
+ * blocked-popup fallback call it with the provider URL. Defaults to a full-page
196
+ * navigation (`window.location.href = url`); pass an in-app browser opener on
197
+ * native, or a router's external navigation.
198
+ */
199
+ navigate?: (url: string) => void;
200
+ }
201
+ /**
202
+ * OAuth authentication. Call it in an injection context.
203
+ *
204
+ * Reads OAuth configuration from the provided config and provides helpers to
205
+ * build OAuth URLs and start a login (full-page or popup). Automatically
206
+ * handles OAuth callbacks by detecting `code` and `state` URL parameters and
207
+ * exchanging them for a session — and, when the callback is running inside a
208
+ * popup we opened, relaying the result to the opener instead.
209
+ *
210
+ * The config may be a signal, and the result follows it the way React's
211
+ * re-render does: `providers` reads the config at the moment it is read,
212
+ * `getOAuthUrl` builds from the config at call time, and a flow (`redirect`,
213
+ * `loginViaPopup`, a callback exchange) uses the config it was started with,
214
+ * like the render closure React started it from.
215
+ *
216
+ * Unmounting does not cancel a flow that has started. A popup result or a
217
+ * callback exchange that settles afterwards still establishes the session on
218
+ * the shared auth client, because the user did sign in. `onSuccess` and
219
+ * `onError` are not called after unmount: they belong to the unmounted view.
220
+ *
221
+ * @param config - Optional OAuth configuration override (see
222
+ * {@link UseOAuthConfig}), or a signal of it.
223
+ * @returns OAuth helpers: providers, getOAuthUrl, redirect, and loginViaPopup.
224
+ */
225
+ export declare function useOAuth(config?: MaybeSignal<UseOAuthConfig>): UseOAuthReturn;
226
+ //# sourceMappingURL=use-auth-flows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-auth-flows.d.ts","sourceRoot":"","sources":["../../src/hooks/use-auth-flows.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EACZ,kBAAkB,EACnB,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,KAAK,WAAW,EAAmB,MAAM,oBAAoB,CAAA;AACtE,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAGjE;;;;GAIG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC,4EAA4E;IAC5E,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CA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