@molecule/app-angular 3.3.0 → 3.5.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 (115) hide show
  1. package/README.md +3889 -1267
  2. package/dist/hooks/external-store.d.ts +32 -0
  3. package/dist/hooks/external-store.d.ts.map +1 -0
  4. package/dist/hooks/external-store.js +62 -0
  5. package/dist/hooks/external-store.js.map +1 -0
  6. package/dist/hooks/index.d.ts +24 -0
  7. package/dist/hooks/index.d.ts.map +1 -0
  8. package/dist/hooks/index.js +24 -0
  9. package/dist/hooks/index.js.map +1 -0
  10. package/dist/hooks/use-ai-models.d.ts +46 -0
  11. package/dist/hooks/use-ai-models.d.ts.map +1 -0
  12. package/dist/hooks/use-ai-models.js +142 -0
  13. package/dist/hooks/use-ai-models.js.map +1 -0
  14. package/dist/hooks/use-async.d.ts +125 -0
  15. package/dist/hooks/use-async.d.ts.map +1 -0
  16. package/dist/hooks/use-async.js +189 -0
  17. package/dist/hooks/use-async.js.map +1 -0
  18. package/dist/hooks/use-auth-flows.d.ts +207 -0
  19. package/dist/hooks/use-auth-flows.d.ts.map +1 -0
  20. package/dist/hooks/use-auth-flows.js +460 -0
  21. package/dist/hooks/use-auth-flows.js.map +1 -0
  22. package/dist/hooks/use-auth.d.ts +80 -0
  23. package/dist/hooks/use-auth.d.ts.map +1 -0
  24. package/dist/hooks/use-auth.js +89 -0
  25. package/dist/hooks/use-auth.js.map +1 -0
  26. package/dist/hooks/use-forms.d.ts +177 -0
  27. package/dist/hooks/use-forms.d.ts.map +1 -0
  28. package/dist/hooks/use-forms.js +185 -0
  29. package/dist/hooks/use-forms.js.map +1 -0
  30. package/dist/hooks/use-http.d.ts +155 -0
  31. package/dist/hooks/use-http.d.ts.map +1 -0
  32. package/dist/hooks/use-http.js +212 -0
  33. package/dist/hooks/use-http.js.map +1 -0
  34. package/dist/hooks/use-ide.d.ts +208 -0
  35. package/dist/hooks/use-ide.d.ts.map +1 -0
  36. package/dist/hooks/use-ide.js +217 -0
  37. package/dist/hooks/use-ide.js.map +1 -0
  38. package/dist/hooks/use-logger.d.ts +40 -0
  39. package/dist/hooks/use-logger.d.ts.map +1 -0
  40. package/dist/hooks/use-logger.js +56 -0
  41. package/dist/hooks/use-logger.js.map +1 -0
  42. package/dist/hooks/use-native.d.ts +213 -0
  43. package/dist/hooks/use-native.d.ts.map +1 -0
  44. package/dist/hooks/use-native.js +158 -0
  45. package/dist/hooks/use-native.js.map +1 -0
  46. package/dist/hooks/use-profile-form.d.ts +113 -0
  47. package/dist/hooks/use-profile-form.d.ts.map +1 -0
  48. package/dist/hooks/use-profile-form.js +253 -0
  49. package/dist/hooks/use-profile-form.js.map +1 -0
  50. package/dist/hooks/use-router.d.ts +212 -0
  51. package/dist/hooks/use-router.d.ts.map +1 -0
  52. package/dist/hooks/use-router.js +251 -0
  53. package/dist/hooks/use-router.js.map +1 -0
  54. package/dist/hooks/use-storage.d.ts +128 -0
  55. package/dist/hooks/use-storage.d.ts.map +1 -0
  56. package/dist/hooks/use-storage.js +217 -0
  57. package/dist/hooks/use-storage.js.map +1 -0
  58. package/dist/hooks/use-store.d.ts +74 -0
  59. package/dist/hooks/use-store.d.ts.map +1 -0
  60. package/dist/hooks/use-store.js +103 -0
  61. package/dist/hooks/use-store.js.map +1 -0
  62. package/dist/hooks/use-theme.d.ts +59 -0
  63. package/dist/hooks/use-theme.d.ts.map +1 -0
  64. package/dist/hooks/use-theme.js +117 -0
  65. package/dist/hooks/use-theme.js.map +1 -0
  66. package/dist/hooks/use-translation.d.ts +86 -0
  67. package/dist/hooks/use-translation.d.ts.map +1 -0
  68. package/dist/hooks/use-translation.js +146 -0
  69. package/dist/hooks/use-translation.js.map +1 -0
  70. package/dist/hooks/use-verify-payment-return.d.ts +86 -0
  71. package/dist/hooks/use-verify-payment-return.d.ts.map +1 -0
  72. package/dist/hooks/use-verify-payment-return.js +167 -0
  73. package/dist/hooks/use-verify-payment-return.js.map +1 -0
  74. package/dist/hooks/use-version.d.ts +49 -0
  75. package/dist/hooks/use-version.d.ts.map +1 -0
  76. package/dist/hooks/use-version.js +70 -0
  77. package/dist/hooks/use-version.js.map +1 -0
  78. package/dist/i18n-reactive.d.ts +2 -5
  79. package/dist/i18n-reactive.d.ts.map +1 -1
  80. package/dist/i18n-reactive.js.map +1 -1
  81. package/dist/index.d.ts +2 -0
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +2 -0
  84. package/dist/index.js.map +1 -1
  85. package/dist/inject.d.ts +24 -0
  86. package/dist/inject.d.ts.map +1 -0
  87. package/dist/inject.js +33 -0
  88. package/dist/inject.js.map +1 -0
  89. package/dist/providers.d.ts +24 -0
  90. package/dist/providers.d.ts.map +1 -1
  91. package/dist/providers.js +44 -3
  92. package/dist/providers.js.map +1 -1
  93. package/dist/services/change-password.service.d.ts +4 -1
  94. package/dist/services/change-password.service.d.ts.map +1 -1
  95. package/dist/services/change-password.service.js +3 -0
  96. package/dist/services/change-password.service.js.map +1 -1
  97. package/dist/services/password-reset.service.d.ts +4 -1
  98. package/dist/services/password-reset.service.d.ts.map +1 -1
  99. package/dist/services/password-reset.service.js +3 -0
  100. package/dist/services/password-reset.service.js.map +1 -1
  101. package/dist/session-ready.d.ts +41 -0
  102. package/dist/session-ready.d.ts.map +1 -0
  103. package/dist/session-ready.js +79 -0
  104. package/dist/session-ready.js.map +1 -0
  105. package/dist/site.d.ts +51 -0
  106. package/dist/site.d.ts.map +1 -0
  107. package/dist/site.js +69 -0
  108. package/dist/site.js.map +1 -0
  109. package/dist/tokens.d.ts +15 -0
  110. package/dist/tokens.d.ts.map +1 -1
  111. package/dist/tokens.js +12 -0
  112. package/dist/tokens.js.map +1 -1
  113. package/dist/types.d.ts +14 -1
  114. package/dist/types.d.ts.map +1 -1
  115. package/package.json +6 -6
@@ -0,0 +1,189 @@
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, ElementRef, inject } from '@angular/core';
14
+ import { createOptimisticValue, shallowEqual } from '@molecule/app-state';
15
+ import { adoptLane, captureSite, parkLane } from '../site.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
+ * Like React — whose component instance survives an argument change — the
143
+ * controller survives this site's re-creation (an input change to the hook):
144
+ * the destroyed instance parks it at the site and the next instance adopts it,
145
+ * feeding the new server value through `sync()`. See `site.ts`.
146
+ *
147
+ * @param options - The server's current value and how to save a change.
148
+ * @returns The value to render, whether a save is pending, the newest failure,
149
+ * and `set`/`update`.
150
+ */
151
+ export const useOptimisticValue = (options) => {
152
+ const destroyRef = inject(DestroyRef);
153
+ const host = inject(ElementRef).nativeElement;
154
+ // The site's container, recorded once the host is attached (see captureSite);
155
+ // the lane parks only while that container is still in the document.
156
+ let site = null;
157
+ captureSite(host, (captured) => {
158
+ site = captured;
159
+ });
160
+ const adopted = adoptLane('useOptimisticValue');
161
+ const controller = adopted?.controller ??
162
+ createOptimisticValue({
163
+ value: options.value,
164
+ commit: (next, previous, confirm) => options.commit(next, previous, confirm),
165
+ equals: (a, b) => (options.equals ?? shallowEqual)(a, b),
166
+ onError: (error, value) => options.onError?.(error, value),
167
+ });
168
+ // The last server value this site received. The equality check runs on every
169
+ // mount exactly like React's effect: equal → nothing; different → the new
170
+ // server value is synced in (immediately when idle, kept as fallback while
171
+ // saving).
172
+ let received = adopted ? adopted.received : options.value;
173
+ if (!(options.equals ?? shallowEqual)(received, options.value)) {
174
+ received = options.value;
175
+ controller.sync(options.value);
176
+ }
177
+ const state = useExternalStore(() => controller.getState(), (notify) => controller.subscribe(notify));
178
+ destroyRef.onDestroy(() => {
179
+ parkLane('useOptimisticValue', { controller, received }, site);
180
+ });
181
+ return {
182
+ value: computed(() => state().value),
183
+ pending: computed(() => state().pending),
184
+ error: computed(() => state().error),
185
+ set: (next) => controller.set(next),
186
+ update: (change) => controller.update(change),
187
+ };
188
+ };
189
+ //# 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,UAAU,EAAE,MAAM,EAAe,MAAM,eAAe,CAAA;AAGrF,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAGzE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC7D,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,CAAC;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AAgB,CAC5B,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,EAC3B,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CACzC,CAAA;IAED,UAAU,CAAC,SAAS,CAAC,GAAG,EAAE;QACxB,QAAQ,CAAC,oBAAoB,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,IAAI,CAAC,CAAA;IAChE,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,207 @@
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 UsePromiseState } from './use-async.js';
15
+ /**
16
+ * Return type for {@link useLogin}.
17
+ *
18
+ * @template T - The user profile the API returns.
19
+ */
20
+ export interface UseLoginReturn<T = unknown> {
21
+ /** The login state: `'idle'`, `'pending'`, `'resolved'` or `'rejected'`. */
22
+ readonly status: UsePromiseState<AuthResult<T>>['status'];
23
+ /** The resolved session, `null` before the first resolution. */
24
+ readonly value: UsePromiseState<AuthResult<T>>['value'];
25
+ /** The failure of the latest login. */
26
+ readonly error: UsePromiseState<AuthResult<T>>['error'];
27
+ /**
28
+ * Runs one tracked login.
29
+ *
30
+ * @param credentials - The credentials to sign in with.
31
+ * @returns The session.
32
+ */
33
+ login: (credentials: LoginCredentials) => Promise<AuthResult<T>>;
34
+ /** Returns the state to idle. */
35
+ reset: () => void;
36
+ }
37
+ /**
38
+ * Login with async state tracking. Call it in an injection context.
39
+ *
40
+ * Registration is available through `const { register } = useAuth()`;
41
+ * call `register({ email, password, name })` to create an account. There is
42
+ * no separate `useRegister` hook. Use `usePromise(register)` when the form
43
+ * needs the same pending/error tracking as this login hook.
44
+ *
45
+ * @returns Login state and action.
46
+ */
47
+ export declare function useLogin<T = unknown>(): UseLoginReturn<T>;
48
+ /**
49
+ * Return type for {@link useSignup}.
50
+ *
51
+ * @template T - The user profile the API returns.
52
+ * @template TRegister - The app's own registration fields (the second generic
53
+ * of `createJWTAuthClient<T, TRegister>`), so `signup()` is typed like the
54
+ * client's `register()`.
55
+ */
56
+ export interface UseSignupReturn<T = unknown, TRegister extends RegisterExtraShape<TRegister> = Record<never, never>> {
57
+ /** The signup state. */
58
+ readonly status: UsePromiseState<AuthResult<T>>['status'];
59
+ /** The resolved session, `null` before the first resolution. */
60
+ readonly value: UsePromiseState<AuthResult<T>>['value'];
61
+ /** The failure of the latest signup. */
62
+ readonly error: UsePromiseState<AuthResult<T>>['error'];
63
+ /**
64
+ * Runs one tracked registration (and signs the account in).
65
+ *
66
+ * @param data - The registration data.
67
+ * @returns The session.
68
+ */
69
+ signup: (data: RegisterData<TRegister>) => Promise<AuthResult<T>>;
70
+ /** Returns the state to idle. */
71
+ reset: () => void;
72
+ }
73
+ /**
74
+ * Registration with async state tracking. Call it in an injection context.
75
+ *
76
+ * @returns Signup state and action.
77
+ */
78
+ export declare function useSignup<T = unknown, TRegister extends RegisterExtraShape<TRegister> = Record<never, never>>(): UseSignupReturn<T, TRegister>;
79
+ /**
80
+ * Return type for {@link useChangePassword}.
81
+ */
82
+ export interface UseChangePasswordReturn {
83
+ /** The change state. */
84
+ readonly status: UsePromiseState<void>['status'];
85
+ /** The failure of the latest change. */
86
+ readonly error: UsePromiseState<void>['error'];
87
+ /**
88
+ * Runs one tracked password change.
89
+ *
90
+ * @param oldPassword - The current password.
91
+ * @param newPassword - The new password.
92
+ * @returns Resolves once changed.
93
+ */
94
+ changePassword: (oldPassword: string, newPassword: string) => Promise<void>;
95
+ /** Returns the state to idle. */
96
+ reset: () => void;
97
+ }
98
+ /**
99
+ * Changing a password with async state tracking. Call it in an injection
100
+ * context.
101
+ *
102
+ * @returns Change-password state and action.
103
+ */
104
+ export declare function useChangePassword(): UseChangePasswordReturn;
105
+ /**
106
+ * Return type for {@link usePasswordReset}.
107
+ */
108
+ export interface UsePasswordResetReturn {
109
+ /** The request half's state. */
110
+ readonly requestStatus: UsePromiseState<void>['status'];
111
+ /** The request half's failure. */
112
+ readonly requestError: UsePromiseState<void>['error'];
113
+ /** The confirm half's state. */
114
+ readonly confirmStatus: UsePromiseState<void>['status'];
115
+ /** The confirm half's failure. */
116
+ readonly confirmError: UsePromiseState<void>['error'];
117
+ /**
118
+ * Sends the reset email.
119
+ *
120
+ * @param data - The request data.
121
+ * @returns Resolves once sent.
122
+ */
123
+ requestReset: (data: PasswordResetRequest) => Promise<void>;
124
+ /**
125
+ * Submits the token and the new password.
126
+ *
127
+ * @param data - The confirm data.
128
+ * @returns Resolves once confirmed.
129
+ */
130
+ confirmReset: (data: PasswordResetConfirm) => Promise<void>;
131
+ /** Returns both halves to idle. */
132
+ reset: () => void;
133
+ }
134
+ /**
135
+ * The password reset flow with async state tracking, one tracker per step.
136
+ * Call it in an injection context.
137
+ *
138
+ * @returns Password reset state and actions.
139
+ */
140
+ export declare function usePasswordReset(): UsePasswordResetReturn;
141
+ /**
142
+ * Return type for {@link useOAuth}.
143
+ */
144
+ export interface UseOAuthReturn {
145
+ /** The supported provider names. */
146
+ providers: string[];
147
+ /**
148
+ * Builds the initiation URL for one provider.
149
+ *
150
+ * @param provider - The provider name.
151
+ * @returns The URL.
152
+ */
153
+ getOAuthUrl: (provider: string) => string;
154
+ /**
155
+ * Full-page redirect to the provider (default). The opener page navigates
156
+ * away.
157
+ *
158
+ * @param provider - The provider name.
159
+ */
160
+ redirect: (provider: string) => void;
161
+ /**
162
+ * Open the provider in a popup so the opener page does NOT navigate. On
163
+ * success the session is established in the opener in place and
164
+ * `config.onSuccess` fires; on failure `config.onError` fires. Falls back to
165
+ * a full-page {@link redirect} when the popup is blocked.
166
+ *
167
+ * @param provider - The provider name.
168
+ */
169
+ loginViaPopup: (provider: string) => void;
170
+ }
171
+ /**
172
+ * OAuth authentication. Call it in an injection context.
173
+ *
174
+ * Reads OAuth configuration from the provided config and provides helpers to
175
+ * build OAuth URLs and start a login (full-page or popup). Automatically
176
+ * handles OAuth callbacks by detecting `code` and `state` URL parameters and
177
+ * exchanging them for a session — and, when the callback is running inside a
178
+ * popup we opened, relaying the result to the opener instead.
179
+ *
180
+ * Unmounting does not cancel a flow that has started. A popup result or a
181
+ * callback exchange that settles afterwards still establishes the session on
182
+ * the shared auth client, because the user did sign in. `onSuccess` and
183
+ * `onError` are not called after unmount: they belong to the unmounted view.
184
+ *
185
+ * @param config - Optional OAuth configuration override.
186
+ * @param config.baseURL - Base URL for the API server (e.g. "https://api.example.com").
187
+ * @param config.oauthProviders - List of supported OAuth provider names (e.g. ["google", "github"]).
188
+ * @param config.oauthEndpoint - Path prefix for OAuth routes (defaults to "/oauth").
189
+ * @param config.loginEndpoint - Path for the OAuth login POST endpoint (defaults to "/users/log-in/oauth").
190
+ * @param config.onSuccess - Callback after successful OAuth login.
191
+ * @param config.onError - Callback on OAuth login failure.
192
+ * @param config.navigate - How the page leaves for the provider: {@link UseOAuthReturn.redirect}
193
+ * and the blocked-popup fallback call it with the provider URL. Defaults to a
194
+ * full-page navigation (`window.location.href = url`); pass an in-app browser
195
+ * opener on native, or a router's external navigation.
196
+ * @returns OAuth helpers: providers, getOAuthUrl, redirect, and loginViaPopup.
197
+ */
198
+ export declare function useOAuth(config?: {
199
+ baseURL?: string;
200
+ oauthProviders?: string[];
201
+ oauthEndpoint?: string;
202
+ loginEndpoint?: string;
203
+ onSuccess?: () => void;
204
+ onError?: (error: string) => void;
205
+ navigate?: (url: string) => void;
206
+ }): UseOAuthReturn;
207
+ //# 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,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,CAAC,CAAC,QAAQ,CAAC,CAAA;IACzD,gEAAgE;IAChE,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;IACvD,uCAAuC;IACvC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;IACvD;;;;;OAKG;IACH,KAAK,EAAE,CAAC,WAAW,EAAE,gBAAgB,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CA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