@kaiz11/stack-client 0.0.14

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 (263) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +586 -0
  3. package/dist/accounts/accounts-client.d.ts +188 -0
  4. package/dist/accounts/accounts-client.d.ts.map +1 -0
  5. package/dist/accounts/accounts-client.js +264 -0
  6. package/dist/accounts/accounts-client.js.map +1 -0
  7. package/dist/accounts/index.d.ts +8 -0
  8. package/dist/accounts/index.d.ts.map +1 -0
  9. package/dist/accounts/index.js +8 -0
  10. package/dist/accounts/index.js.map +1 -0
  11. package/dist/accounts/mock-accounts.d.ts +90 -0
  12. package/dist/accounts/mock-accounts.d.ts.map +1 -0
  13. package/dist/accounts/mock-accounts.js +434 -0
  14. package/dist/accounts/mock-accounts.js.map +1 -0
  15. package/dist/accounts/types.d.ts +180 -0
  16. package/dist/accounts/types.d.ts.map +1 -0
  17. package/dist/accounts/types.js +59 -0
  18. package/dist/accounts/types.js.map +1 -0
  19. package/dist/auth/auth-client.d.ts +224 -0
  20. package/dist/auth/auth-client.d.ts.map +1 -0
  21. package/dist/auth/auth-client.js +230 -0
  22. package/dist/auth/auth-client.js.map +1 -0
  23. package/dist/auth/base-auth.d.ts +44 -0
  24. package/dist/auth/base-auth.d.ts.map +1 -0
  25. package/dist/auth/base-auth.js +55 -0
  26. package/dist/auth/base-auth.js.map +1 -0
  27. package/dist/auth/index.d.ts +11 -0
  28. package/dist/auth/index.d.ts.map +1 -0
  29. package/dist/auth/index.js +11 -0
  30. package/dist/auth/index.js.map +1 -0
  31. package/dist/auth/methods/admin.d.ts +59 -0
  32. package/dist/auth/methods/admin.d.ts.map +1 -0
  33. package/dist/auth/methods/admin.js +55 -0
  34. package/dist/auth/methods/admin.js.map +1 -0
  35. package/dist/auth/methods/index.d.ts +9 -0
  36. package/dist/auth/methods/index.d.ts.map +1 -0
  37. package/dist/auth/methods/index.js +8 -0
  38. package/dist/auth/methods/index.js.map +1 -0
  39. package/dist/auth/methods/magic-link.d.ts +27 -0
  40. package/dist/auth/methods/magic-link.d.ts.map +1 -0
  41. package/dist/auth/methods/magic-link.js +37 -0
  42. package/dist/auth/methods/magic-link.js.map +1 -0
  43. package/dist/auth/methods/mfa.d.ts +92 -0
  44. package/dist/auth/methods/mfa.d.ts.map +1 -0
  45. package/dist/auth/methods/mfa.js +153 -0
  46. package/dist/auth/methods/mfa.js.map +1 -0
  47. package/dist/auth/methods/oauth.d.ts +62 -0
  48. package/dist/auth/methods/oauth.d.ts.map +1 -0
  49. package/dist/auth/methods/oauth.js +165 -0
  50. package/dist/auth/methods/oauth.js.map +1 -0
  51. package/dist/auth/methods/otp.d.ts +43 -0
  52. package/dist/auth/methods/otp.d.ts.map +1 -0
  53. package/dist/auth/methods/otp.js +66 -0
  54. package/dist/auth/methods/otp.js.map +1 -0
  55. package/dist/auth/methods/password.d.ts +64 -0
  56. package/dist/auth/methods/password.d.ts.map +1 -0
  57. package/dist/auth/methods/password.js +116 -0
  58. package/dist/auth/methods/password.js.map +1 -0
  59. package/dist/auth/methods/recovery.d.ts +62 -0
  60. package/dist/auth/methods/recovery.d.ts.map +1 -0
  61. package/dist/auth/methods/recovery.js +100 -0
  62. package/dist/auth/methods/recovery.js.map +1 -0
  63. package/dist/auth/mock-auth.d.ts +135 -0
  64. package/dist/auth/mock-auth.d.ts.map +1 -0
  65. package/dist/auth/mock-auth.js +417 -0
  66. package/dist/auth/mock-auth.js.map +1 -0
  67. package/dist/auth/server/helpers.d.ts +215 -0
  68. package/dist/auth/server/helpers.d.ts.map +1 -0
  69. package/dist/auth/server/helpers.js +241 -0
  70. package/dist/auth/server/helpers.js.map +1 -0
  71. package/dist/auth/server/index.d.ts +24 -0
  72. package/dist/auth/server/index.d.ts.map +1 -0
  73. package/dist/auth/server/index.js +40 -0
  74. package/dist/auth/server/index.js.map +1 -0
  75. package/dist/auth/server/middleware.d.ts +305 -0
  76. package/dist/auth/server/middleware.d.ts.map +1 -0
  77. package/dist/auth/server/middleware.js +405 -0
  78. package/dist/auth/server/middleware.js.map +1 -0
  79. package/dist/auth/server/verify.d.ts +184 -0
  80. package/dist/auth/server/verify.d.ts.map +1 -0
  81. package/dist/auth/server/verify.js +222 -0
  82. package/dist/auth/server/verify.js.map +1 -0
  83. package/dist/auth/token-manager.d.ts +94 -0
  84. package/dist/auth/token-manager.d.ts.map +1 -0
  85. package/dist/auth/token-manager.js +231 -0
  86. package/dist/auth/token-manager.js.map +1 -0
  87. package/dist/auth/types.d.ts +412 -0
  88. package/dist/auth/types.d.ts.map +1 -0
  89. package/dist/auth/types.js +66 -0
  90. package/dist/auth/types.js.map +1 -0
  91. package/dist/auth/user/identities.d.ts +62 -0
  92. package/dist/auth/user/identities.d.ts.map +1 -0
  93. package/dist/auth/user/identities.js +88 -0
  94. package/dist/auth/user/identities.js.map +1 -0
  95. package/dist/auth/user/index.d.ts +4 -0
  96. package/dist/auth/user/index.d.ts.map +1 -0
  97. package/dist/auth/user/index.js +4 -0
  98. package/dist/auth/user/index.js.map +1 -0
  99. package/dist/auth/user/user.d.ts +64 -0
  100. package/dist/auth/user/user.d.ts.map +1 -0
  101. package/dist/auth/user/user.js +105 -0
  102. package/dist/auth/user/user.js.map +1 -0
  103. package/dist/auth/user/verification.d.ts +49 -0
  104. package/dist/auth/user/verification.d.ts.map +1 -0
  105. package/dist/auth/user/verification.js +71 -0
  106. package/dist/auth/user/verification.js.map +1 -0
  107. package/dist/cli/browser.d.ts +11 -0
  108. package/dist/cli/browser.d.ts.map +1 -0
  109. package/dist/cli/browser.js +35 -0
  110. package/dist/cli/browser.js.map +1 -0
  111. package/dist/cli/callback-server.d.ts +30 -0
  112. package/dist/cli/callback-server.d.ts.map +1 -0
  113. package/dist/cli/callback-server.js +100 -0
  114. package/dist/cli/callback-server.js.map +1 -0
  115. package/dist/cli/file-token-store.d.ts +79 -0
  116. package/dist/cli/file-token-store.d.ts.map +1 -0
  117. package/dist/cli/file-token-store.js +138 -0
  118. package/dist/cli/file-token-store.js.map +1 -0
  119. package/dist/cli/index.d.ts +33 -0
  120. package/dist/cli/index.d.ts.map +1 -0
  121. package/dist/cli/index.js +38 -0
  122. package/dist/cli/index.js.map +1 -0
  123. package/dist/cli/oauth.d.ts +67 -0
  124. package/dist/cli/oauth.d.ts.map +1 -0
  125. package/dist/cli/oauth.js +101 -0
  126. package/dist/cli/oauth.js.map +1 -0
  127. package/dist/cli/pkce.d.ts +35 -0
  128. package/dist/cli/pkce.d.ts.map +1 -0
  129. package/dist/cli/pkce.js +43 -0
  130. package/dist/cli/pkce.js.map +1 -0
  131. package/dist/client.d.ts +22 -0
  132. package/dist/client.d.ts.map +1 -0
  133. package/dist/client.js +99 -0
  134. package/dist/client.js.map +1 -0
  135. package/dist/db/client.d.ts +9 -0
  136. package/dist/db/client.d.ts.map +1 -0
  137. package/dist/db/client.js +19 -0
  138. package/dist/db/client.js.map +1 -0
  139. package/dist/db/errors.d.ts +19 -0
  140. package/dist/db/errors.d.ts.map +1 -0
  141. package/dist/db/errors.js +57 -0
  142. package/dist/db/errors.js.map +1 -0
  143. package/dist/db/index.d.ts +7 -0
  144. package/dist/db/index.d.ts.map +1 -0
  145. package/dist/db/index.js +5 -0
  146. package/dist/db/index.js.map +1 -0
  147. package/dist/db/mock.d.ts +28 -0
  148. package/dist/db/mock.d.ts.map +1 -0
  149. package/dist/db/mock.js +459 -0
  150. package/dist/db/mock.js.map +1 -0
  151. package/dist/db/types.d.ts +73 -0
  152. package/dist/db/types.d.ts.map +1 -0
  153. package/dist/db/types.js +2 -0
  154. package/dist/db/types.js.map +1 -0
  155. package/dist/index.d.ts +21 -0
  156. package/dist/index.d.ts.map +1 -0
  157. package/dist/index.js +20 -0
  158. package/dist/index.js.map +1 -0
  159. package/dist/lib/errors.d.ts +33 -0
  160. package/dist/lib/errors.d.ts.map +1 -0
  161. package/dist/lib/errors.js +76 -0
  162. package/dist/lib/errors.js.map +1 -0
  163. package/dist/lib/http.d.ts +81 -0
  164. package/dist/lib/http.d.ts.map +1 -0
  165. package/dist/lib/http.js +163 -0
  166. package/dist/lib/http.js.map +1 -0
  167. package/dist/lib/keys.d.ts +87 -0
  168. package/dist/lib/keys.d.ts.map +1 -0
  169. package/dist/lib/keys.js +147 -0
  170. package/dist/lib/keys.js.map +1 -0
  171. package/dist/lib/paths.d.ts +37 -0
  172. package/dist/lib/paths.d.ts.map +1 -0
  173. package/dist/lib/paths.js +49 -0
  174. package/dist/lib/paths.js.map +1 -0
  175. package/dist/lib/token-store.d.ts +42 -0
  176. package/dist/lib/token-store.d.ts.map +1 -0
  177. package/dist/lib/token-store.js +75 -0
  178. package/dist/lib/token-store.js.map +1 -0
  179. package/dist/mocks/handlers.d.ts +29 -0
  180. package/dist/mocks/handlers.d.ts.map +1 -0
  181. package/dist/mocks/handlers.js +79 -0
  182. package/dist/mocks/handlers.js.map +1 -0
  183. package/dist/mocks/index.d.ts +5 -0
  184. package/dist/mocks/index.d.ts.map +1 -0
  185. package/dist/mocks/index.js +9 -0
  186. package/dist/mocks/index.js.map +1 -0
  187. package/dist/mocks/responses.d.ts +76 -0
  188. package/dist/mocks/responses.d.ts.map +1 -0
  189. package/dist/mocks/responses.js +91 -0
  190. package/dist/mocks/responses.js.map +1 -0
  191. package/dist/mocks/server.d.ts +7 -0
  192. package/dist/mocks/server.d.ts.map +1 -0
  193. package/dist/mocks/server.js +9 -0
  194. package/dist/mocks/server.js.map +1 -0
  195. package/dist/mocks/state.d.ts +86 -0
  196. package/dist/mocks/state.d.ts.map +1 -0
  197. package/dist/mocks/state.js +77 -0
  198. package/dist/mocks/state.js.map +1 -0
  199. package/dist/storage/bucket-ref.d.ts +183 -0
  200. package/dist/storage/bucket-ref.d.ts.map +1 -0
  201. package/dist/storage/bucket-ref.js +529 -0
  202. package/dist/storage/bucket-ref.js.map +1 -0
  203. package/dist/storage/errors.d.ts +27 -0
  204. package/dist/storage/errors.d.ts.map +1 -0
  205. package/dist/storage/errors.js +89 -0
  206. package/dist/storage/errors.js.map +1 -0
  207. package/dist/storage/index.d.ts +13 -0
  208. package/dist/storage/index.d.ts.map +1 -0
  209. package/dist/storage/index.js +11 -0
  210. package/dist/storage/index.js.map +1 -0
  211. package/dist/storage/interface.d.ts +245 -0
  212. package/dist/storage/interface.d.ts.map +1 -0
  213. package/dist/storage/interface.js +2 -0
  214. package/dist/storage/interface.js.map +1 -0
  215. package/dist/storage/mock-storage.d.ts +67 -0
  216. package/dist/storage/mock-storage.d.ts.map +1 -0
  217. package/dist/storage/mock-storage.js +478 -0
  218. package/dist/storage/mock-storage.js.map +1 -0
  219. package/dist/storage/policies-client.d.ts +77 -0
  220. package/dist/storage/policies-client.d.ts.map +1 -0
  221. package/dist/storage/policies-client.js +115 -0
  222. package/dist/storage/policies-client.js.map +1 -0
  223. package/dist/storage/policy-templates.d.ts +6 -0
  224. package/dist/storage/policy-templates.d.ts.map +1 -0
  225. package/dist/storage/policy-templates.js +290 -0
  226. package/dist/storage/policy-templates.js.map +1 -0
  227. package/dist/storage/policy-types.d.ts +98 -0
  228. package/dist/storage/policy-types.d.ts.map +1 -0
  229. package/dist/storage/policy-types.js +20 -0
  230. package/dist/storage/policy-types.js.map +1 -0
  231. package/dist/storage/storage-client.d.ts +32 -0
  232. package/dist/storage/storage-client.d.ts.map +1 -0
  233. package/dist/storage/storage-client.js +94 -0
  234. package/dist/storage/storage-client.js.map +1 -0
  235. package/dist/storage/tus-upload.d.ts +56 -0
  236. package/dist/storage/tus-upload.d.ts.map +1 -0
  237. package/dist/storage/tus-upload.js +236 -0
  238. package/dist/storage/tus-upload.js.map +1 -0
  239. package/dist/storage/types.d.ts +335 -0
  240. package/dist/storage/types.d.ts.map +1 -0
  241. package/dist/storage/types.js +39 -0
  242. package/dist/storage/types.js.map +1 -0
  243. package/dist/test/auth/helpers.d.ts +33 -0
  244. package/dist/test/auth/helpers.d.ts.map +1 -0
  245. package/dist/test/auth/helpers.js +80 -0
  246. package/dist/test/auth/helpers.js.map +1 -0
  247. package/dist/test/helpers/jwt.d.ts +61 -0
  248. package/dist/test/helpers/jwt.d.ts.map +1 -0
  249. package/dist/test/helpers/jwt.js +132 -0
  250. package/dist/test/helpers/jwt.js.map +1 -0
  251. package/dist/test/helpers/mailpit.d.ts +61 -0
  252. package/dist/test/helpers/mailpit.d.ts.map +1 -0
  253. package/dist/test/helpers/mailpit.js +107 -0
  254. package/dist/test/helpers/mailpit.js.map +1 -0
  255. package/dist/test/setup.d.ts +2 -0
  256. package/dist/test/setup.d.ts.map +1 -0
  257. package/dist/test/setup.js +17 -0
  258. package/dist/test/setup.js.map +1 -0
  259. package/dist/types.d.ts +96 -0
  260. package/dist/types.d.ts.map +1 -0
  261. package/dist/types.js +5 -0
  262. package/dist/types.js.map +1 -0
  263. package/package.json +78 -0
@@ -0,0 +1,165 @@
1
+ import { authPath } from "../../lib/paths.js";
2
+ import { normalizeSession } from "../types.js";
3
+ /**
4
+ * OAuth authentication methods
5
+ */
6
+ export class OAuthMethods {
7
+ http;
8
+ tokenManager;
9
+ tenantId;
10
+ constructor(http, tokenManager, tenantId) {
11
+ this.http = http;
12
+ this.tokenManager = tokenManager;
13
+ this.tenantId = tenantId;
14
+ }
15
+ /**
16
+ * Get the base URL for OAuth redirects
17
+ */
18
+ getBaseUrl() {
19
+ return this.http.getBaseUrl();
20
+ }
21
+ /**
22
+ * Sign in with OAuth provider
23
+ *
24
+ * In browser: Redirects to provider's auth page
25
+ * With skipBrowserRedirect: Returns URL for manual redirect
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * // Browser redirect
30
+ * await client.auth.signInWithOAuth({
31
+ * provider: "google",
32
+ * redirectTo: "https://myapp.com/auth/callback",
33
+ * });
34
+ *
35
+ * // Get URL without redirect
36
+ * const { url } = await client.auth.signInWithOAuth({
37
+ * provider: "github",
38
+ * skipBrowserRedirect: true,
39
+ * });
40
+ * ```
41
+ */
42
+ async signInWithOAuth(options) {
43
+ const { provider, redirectTo, scopes, queryParams, skipBrowserRedirect } = options;
44
+ // Build authorization URL
45
+ const params = new URLSearchParams();
46
+ if (redirectTo)
47
+ params.set("redirect_to", redirectTo);
48
+ if (scopes)
49
+ params.set("scopes", scopes);
50
+ if (queryParams) {
51
+ for (const [key, value] of Object.entries(queryParams)) {
52
+ params.set(key, value);
53
+ }
54
+ }
55
+ const baseUrl = this.getBaseUrl();
56
+ const authorizePath = authPath(this.tenantId, `/authorize`);
57
+ const queryString = params.toString();
58
+ const url = `${baseUrl}${authorizePath}?provider=${provider}${queryString ? `&${queryString}` : ""}`;
59
+ // Redirect in browser unless skipped
60
+ if (!skipBrowserRedirect && typeof window !== "undefined") {
61
+ window.location.href = url;
62
+ }
63
+ return { url, provider };
64
+ }
65
+ /**
66
+ * Handle OAuth callback
67
+ *
68
+ * Call this on your callback page to exchange the authorization code for a session.
69
+ * Also handles email verification callbacks which use URL hash fragments.
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * // On /auth/callback page or in AuthProvider on mount
74
+ * const session = await client.auth.handleOAuthCallback();
75
+ * if (session) {
76
+ * router.push("/dashboard");
77
+ * }
78
+ * ```
79
+ */
80
+ async handleOAuthCallback() {
81
+ // Parse URL parameters
82
+ if (typeof window === "undefined") {
83
+ throw new Error("handleOAuthCallback can only be called in browser");
84
+ }
85
+ let params = new URLSearchParams(window.location.search);
86
+ // Check for hash fragment (email verification and some OAuth flows use fragment)
87
+ if (window.location.hash) {
88
+ const hashParams = new URLSearchParams(window.location.hash.substring(1));
89
+ if (hashParams.get("access_token")) {
90
+ params = hashParams;
91
+ }
92
+ }
93
+ const accessToken = params.get("access_token");
94
+ const refreshToken = params.get("refresh_token");
95
+ const expiresIn = params.get("expires_in");
96
+ const expiresAt = params.get("expires_at");
97
+ // Check for authorization code flow
98
+ const code = params.get("code");
99
+ if (code) {
100
+ return this.exchangeCodeForSession(code);
101
+ }
102
+ // Check for implicit flow tokens
103
+ if (accessToken && refreshToken) {
104
+ // Fetch user info to complete session
105
+ const path = authPath(this.tenantId, "/user");
106
+ const response = await this.http.get(path, {
107
+ headers: { Authorization: `Bearer ${accessToken}` },
108
+ });
109
+ const session = {
110
+ accessToken,
111
+ refreshToken,
112
+ expiresIn: expiresIn ? parseInt(expiresIn, 10) : 3600,
113
+ expiresAt: expiresAt
114
+ ? parseInt(expiresAt, 10)
115
+ : Math.floor(Date.now() / 1000) + 3600,
116
+ tokenType: "bearer",
117
+ user: response.user
118
+ ? {
119
+ id: response.user.id,
120
+ email: response.user.email ?? null,
121
+ phone: response.user.phone ?? null,
122
+ emailConfirmedAt: response.user.email_confirmed_at ?? null,
123
+ phoneConfirmedAt: response.user.phone_confirmed_at ?? null,
124
+ createdAt: response.user.created_at,
125
+ updatedAt: response.user.updated_at,
126
+ appMetadata: response.user.app_metadata,
127
+ userMetadata: response.user.user_metadata,
128
+ }
129
+ : {
130
+ id: "",
131
+ email: null,
132
+ phone: null,
133
+ emailConfirmedAt: null,
134
+ phoneConfirmedAt: null,
135
+ createdAt: new Date().toISOString(),
136
+ updatedAt: new Date().toISOString(),
137
+ appMetadata: {},
138
+ userMetadata: {},
139
+ },
140
+ };
141
+ this.tokenManager.setSession(session);
142
+ return session;
143
+ }
144
+ // Check for error
145
+ const error = params.get("error");
146
+ const errorDescription = params.get("error_description");
147
+ if (error) {
148
+ throw new Error(errorDescription || error);
149
+ }
150
+ return null;
151
+ }
152
+ /**
153
+ * Exchange authorization code for session (PKCE flow)
154
+ */
155
+ async exchangeCodeForSession(code) {
156
+ const path = authPath(this.tenantId, "/token?grant_type=pkce");
157
+ const response = await this.http.post(path, {
158
+ auth_code: code,
159
+ }, { noAuth: true });
160
+ const session = normalizeSession(response);
161
+ this.tokenManager.setSession(session);
162
+ return session;
163
+ }
164
+ }
165
+ //# sourceMappingURL=oauth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth.js","sourceRoot":"","sources":["../../../src/auth/methods/oauth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AA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;CACF"}
@@ -0,0 +1,43 @@
1
+ import type { HttpClient } from "../../lib/http.js";
2
+ import type { TokenManager } from "../token-manager.js";
3
+ import type { OtpSignInOptions, OtpVerifyOptions, Session } from "../types.js";
4
+ /**
5
+ * OTP (one-time password) authentication methods
6
+ */
7
+ export declare class OtpMethods {
8
+ private readonly http;
9
+ private readonly tokenManager;
10
+ private readonly tenantId;
11
+ constructor(http: HttpClient, tokenManager: TokenManager, tenantId: string);
12
+ /**
13
+ * Send an OTP to the user's email or phone
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Email OTP
18
+ * await client.auth.signInWithOtp({
19
+ * email: "user@example.com",
20
+ * });
21
+ *
22
+ * // Phone OTP
23
+ * await client.auth.signInWithOtp({
24
+ * phone: "+1234567890",
25
+ * });
26
+ * ```
27
+ */
28
+ signInWithOtp(options: OtpSignInOptions): Promise<void>;
29
+ /**
30
+ * Verify an OTP code
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * const session = await client.auth.verifyOtp({
35
+ * email: "user@example.com",
36
+ * token: "123456",
37
+ * type: "email",
38
+ * });
39
+ * ```
40
+ */
41
+ verifyOtp(options: OtpVerifyOptions): Promise<Session>;
42
+ }
43
+ //# sourceMappingURL=otp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otp.d.ts","sourceRoot":"","sources":["../../../src/auth/methods/otp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,OAAO,EAER,MAAM,aAAa,CAAC;AAUrB;;GAEG;AACH,qBAAa,UAAU;IAEnB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAFR,IAAI,EAAE,UAAU,EAChB,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,MAAM;IAGnC;;;;;;;;;;;;;;;OAeG;IACG,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB7D;;;;;;;;;;;OAWG;IACG,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;CAkB7D"}
@@ -0,0 +1,66 @@
1
+ import { authPath } from "../../lib/paths.js";
2
+ import { normalizeSession } from "../types.js";
3
+ /**
4
+ * OTP (one-time password) authentication methods
5
+ */
6
+ export class OtpMethods {
7
+ http;
8
+ tokenManager;
9
+ tenantId;
10
+ constructor(http, tokenManager, tenantId) {
11
+ this.http = http;
12
+ this.tokenManager = tokenManager;
13
+ this.tenantId = tenantId;
14
+ }
15
+ /**
16
+ * Send an OTP to the user's email or phone
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * // Email OTP
21
+ * await client.auth.signInWithOtp({
22
+ * email: "user@example.com",
23
+ * });
24
+ *
25
+ * // Phone OTP
26
+ * await client.auth.signInWithOtp({
27
+ * phone: "+1234567890",
28
+ * });
29
+ * ```
30
+ */
31
+ async signInWithOtp(options) {
32
+ const path = authPath(this.tenantId, "/otp");
33
+ await this.http.post(path, {
34
+ email: options.email,
35
+ phone: options.phone,
36
+ redirect_to: options.redirectTo,
37
+ create_user: options.shouldCreateUser ?? false,
38
+ data: options.data,
39
+ }, { noAuth: true });
40
+ }
41
+ /**
42
+ * Verify an OTP code
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * const session = await client.auth.verifyOtp({
47
+ * email: "user@example.com",
48
+ * token: "123456",
49
+ * type: "email",
50
+ * });
51
+ * ```
52
+ */
53
+ async verifyOtp(options) {
54
+ const path = authPath(this.tenantId, "/verify");
55
+ const response = await this.http.post(path, {
56
+ email: options.email,
57
+ phone: options.phone,
58
+ token: options.token,
59
+ type: options.type,
60
+ }, { noAuth: true });
61
+ const session = normalizeSession(response);
62
+ this.tokenManager.setSession(session);
63
+ return session;
64
+ }
65
+ }
66
+ //# sourceMappingURL=otp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"otp.js","sourceRoot":"","sources":["../../../src/auth/methods/otp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAQ9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAS/C;;GAEG;AACH,MAAM,OAAO,UAAU;IAEF;IACA;IACA;IAHnB,YACmB,IAAgB,EAChB,YAA0B,EAC1B,QAAgB;QAFhB,SAAI,GAAJ,IAAI,CAAY;QAChB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAAQ;IAChC,CAAC;IAEJ;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,aAAa,CAAC,OAAyB;QAC3C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAE7C,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAClB,IAAI,EACJ;YACE,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,WAAW,EAAE,OAAO,CAAC,UAAU;YAC/B,WAAW,EAAE,OAAO,CAAC,gBAAgB,IAAI,KAAK;YAC9C,IAAI,EAAE,OAAO,CAAC,IAAI;SACnB,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,SAAS,CAAC,OAAyB;QACvC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;QAEhD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CACnC,IAAI,EACJ;YACE,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,IAAI,EAAE,OAAO,CAAC,IAAI;SACnB,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAC;QAEF,MAAM,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,64 @@
1
+ import type { HttpClient } from "../../lib/http.js";
2
+ import type { TokenManager } from "../token-manager.js";
3
+ import type { EmailPasswordCredentials, SignUpOptions, Session, SignUpResult, LogoutScope } from "../types.js";
4
+ /**
5
+ * Password authentication methods
6
+ */
7
+ export declare class PasswordMethods {
8
+ private readonly http;
9
+ private readonly tokenManager;
10
+ private readonly tenantId;
11
+ constructor(http: HttpClient, tokenManager: TokenManager, tenantId: string);
12
+ /**
13
+ * Sign in with email and password
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const session = await client.auth.signInWithPassword({
18
+ * email: "user@example.com",
19
+ * password: "password123",
20
+ * });
21
+ * ```
22
+ */
23
+ signInWithPassword(credentials: EmailPasswordCredentials): Promise<Session>;
24
+ /**
25
+ * Sign up with email and password
26
+ *
27
+ * Returns a SignUpResult with session (if auto-confirm enabled) or just user info
28
+ * (if email verification required).
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const { session, user } = await client.auth.signUp({
33
+ * email: "newuser@example.com",
34
+ * password: "password123",
35
+ * data: { name: "New User" },
36
+ * });
37
+ *
38
+ * if (session) {
39
+ * // User is signed in (auto-confirm enabled)
40
+ * console.log("Signed in as", session.user.email);
41
+ * } else {
42
+ * // Email verification required
43
+ * console.log("Check your email to verify", user.email);
44
+ * }
45
+ * ```
46
+ */
47
+ signUp(options: SignUpOptions): Promise<SignUpResult>;
48
+ /**
49
+ * Sign out current session
50
+ *
51
+ * @param scope - "local" to clear local session only, "global" to revoke all sessions
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * // Local sign out (fast, no network request)
56
+ * await client.auth.signOut();
57
+ *
58
+ * // Global sign out (revokes all sessions on server)
59
+ * await client.auth.signOut("global");
60
+ * ```
61
+ */
62
+ signOut(scope?: LogoutScope): Promise<void>;
63
+ }
64
+ //# sourceMappingURL=password.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../../../src/auth/methods/password.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,wBAAwB,EACxB,aAAa,EACb,OAAO,EAGP,YAAY,EACZ,WAAW,EACZ,MAAM,aAAa,CAAC;AAGrB;;GAEG;AACH,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAFR,IAAI,EAAE,UAAU,EAChB,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,MAAM;IAGnC;;;;;;;;;;OAUG;IACG,kBAAkB,CACtB,WAAW,EAAE,wBAAwB,GACpC,OAAO,CAAC,OAAO,CAAC;IAgBnB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAwC3D;;;;;;;;;;;;;OAaG;IACG,OAAO,CAAC,KAAK,GAAE,WAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;CAgB3D"}
@@ -0,0 +1,116 @@
1
+ import { authPath } from "../../lib/paths.js";
2
+ import { normalizeSession, normalizeUser } from "../types.js";
3
+ /**
4
+ * Password authentication methods
5
+ */
6
+ export class PasswordMethods {
7
+ http;
8
+ tokenManager;
9
+ tenantId;
10
+ constructor(http, tokenManager, tenantId) {
11
+ this.http = http;
12
+ this.tokenManager = tokenManager;
13
+ this.tenantId = tenantId;
14
+ }
15
+ /**
16
+ * Sign in with email and password
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const session = await client.auth.signInWithPassword({
21
+ * email: "user@example.com",
22
+ * password: "password123",
23
+ * });
24
+ * ```
25
+ */
26
+ async signInWithPassword(credentials) {
27
+ const path = authPath(this.tenantId, "/token?grant_type=password");
28
+ const response = await this.http.post(path, {
29
+ email: credentials.email,
30
+ password: credentials.password,
31
+ }, { noAuth: true });
32
+ const session = normalizeSession(response);
33
+ this.tokenManager.setSession(session);
34
+ return session;
35
+ }
36
+ /**
37
+ * Sign up with email and password
38
+ *
39
+ * Returns a SignUpResult with session (if auto-confirm enabled) or just user info
40
+ * (if email verification required).
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const { session, user } = await client.auth.signUp({
45
+ * email: "newuser@example.com",
46
+ * password: "password123",
47
+ * data: { name: "New User" },
48
+ * });
49
+ *
50
+ * if (session) {
51
+ * // User is signed in (auto-confirm enabled)
52
+ * console.log("Signed in as", session.user.email);
53
+ * } else {
54
+ * // Email verification required
55
+ * console.log("Check your email to verify", user.email);
56
+ * }
57
+ * ```
58
+ */
59
+ async signUp(options) {
60
+ const path = authPath(this.tenantId, "/signup");
61
+ const response = await this.http.post(path, {
62
+ email: options.email,
63
+ password: options.password,
64
+ data: options.data,
65
+ }, { noAuth: true });
66
+ // Check if we got a full token response (auto-confirm enabled)
67
+ if (response.access_token && response.refresh_token) {
68
+ const session = normalizeSession(response);
69
+ this.tokenManager.setSession(session);
70
+ return { session, user: session.user };
71
+ }
72
+ // Email verification required - no session, just user info
73
+ const user = normalizeUser({
74
+ id: response.id,
75
+ aud: "authenticated",
76
+ email: response.email,
77
+ phone: response.phone,
78
+ created_at: response.created_at,
79
+ updated_at: response.updated_at,
80
+ app_metadata: response.app_metadata,
81
+ user_metadata: response.user_metadata,
82
+ identities: response.identities,
83
+ });
84
+ return { session: null, user };
85
+ }
86
+ /**
87
+ * Sign out current session
88
+ *
89
+ * @param scope - "local" to clear local session only, "global" to revoke all sessions
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * // Local sign out (fast, no network request)
94
+ * await client.auth.signOut();
95
+ *
96
+ * // Global sign out (revokes all sessions on server)
97
+ * await client.auth.signOut("global");
98
+ * ```
99
+ */
100
+ async signOut(scope = "local") {
101
+ const accessToken = this.tokenManager.getAccessToken();
102
+ if (accessToken && scope === "global") {
103
+ try {
104
+ const path = authPath(this.tenantId, "/logout?scope=global");
105
+ await this.http.post(path, undefined, {
106
+ headers: { Authorization: `Bearer ${accessToken}` },
107
+ });
108
+ }
109
+ catch {
110
+ // Ignore logout errors, clear local session anyway
111
+ }
112
+ }
113
+ this.tokenManager.clearSession();
114
+ }
115
+ }
116
+ //# sourceMappingURL=password.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password.js","sourceRoot":"","sources":["../../../src/auth/methods/password.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAW9C,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE9D;;GAEG;AACH,MAAM,OAAO,eAAe;IAEP;IACA;IACA;IAHnB,YACmB,IAAgB,EAChB,YAA0B,EAC1B,QAAgB;QAFhB,SAAI,GAAJ,IAAI,CAAY;QAChB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAAQ;IAChC,CAAC;IAEJ;;;;;;;;;;OAUG;IACH,KAAK,CAAC,kBAAkB,CACtB,WAAqC;QAErC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,4BAA4B,CAAC,CAAC;QACnE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CACnC,IAAI,EACJ;YACE,KAAK,EAAE,WAAW,CAAC,KAAK;YACxB,QAAQ,EAAE,WAAW,CAA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C,aAAa;YACrC,UAAU,EAAE,QAAQ,CAAC,UAAU;SAChC,CAAC,CAAC;QAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACjC,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,OAAO,CAAC,QAAqB,OAAO;QACxC,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,CAAC;QAEvD,IAAI,WAAW,IAAI,KAAK,KAAK,QAAQ,EAAE,CAAC;YACtC,IAAI,CAAC;gBACH,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;gBAC7D,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE;oBACpC,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;iBACpD,CAAC,CAAC;YACL,CAAC;YAAC,MAAM,CAAC;gBACP,mDAAmD;YACrD,CAAC;QACH,CAAC;QAED,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1,62 @@
1
+ import type { HttpClient } from "../../lib/http.js";
2
+ import type { TokenManager } from "../token-manager.js";
3
+ import type { PasswordResetOptions, UpdatePasswordOptions, ReauthenticateOptions, Session } from "../types.js";
4
+ /**
5
+ * Password recovery and update methods
6
+ */
7
+ export declare class RecoveryMethods {
8
+ private readonly http;
9
+ private readonly tokenManager;
10
+ private readonly tenantId;
11
+ constructor(http: HttpClient, tokenManager: TokenManager, tenantId: string);
12
+ /**
13
+ * Send a password reset email
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * await client.auth.resetPasswordForEmail({
18
+ * email: "user@example.com",
19
+ * redirectTo: "https://myapp.com/reset-password",
20
+ * });
21
+ * ```
22
+ */
23
+ resetPasswordForEmail(options: PasswordResetOptions): Promise<void>;
24
+ /**
25
+ * Update the user's password
26
+ *
27
+ * For sensitive operations, you may need to reauthenticate first.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * // Simple password update (when user has recovery token)
32
+ * await client.auth.updatePassword({
33
+ * password: "newSecurePassword123",
34
+ * });
35
+ *
36
+ * // With reauthentication nonce
37
+ * const { nonce } = await client.auth.reauthenticate();
38
+ * await client.auth.updatePassword({
39
+ * password: "newSecurePassword123",
40
+ * nonce,
41
+ * });
42
+ * ```
43
+ */
44
+ updatePassword(options: UpdatePasswordOptions): Promise<Session>;
45
+ /**
46
+ * Request reauthentication for sensitive operations
47
+ *
48
+ * Sends an OTP to the user's email or phone. The user must retrieve this OTP
49
+ * and provide it as the `nonce` parameter when performing sensitive operations
50
+ * like password changes.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * await client.auth.reauthenticate();
55
+ * // User receives OTP via email
56
+ * // User provides OTP as nonce
57
+ * await client.auth.updatePassword({ password: "new", nonce: otpFromEmail });
58
+ * ```
59
+ */
60
+ reauthenticate(_options?: ReauthenticateOptions): Promise<void>;
61
+ }
62
+ //# sourceMappingURL=recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../../../src/auth/methods/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,OAAO,EAGR,MAAM,aAAa,CAAC;AAiBrB;;GAEG;AACH,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAFR,IAAI,EAAE,UAAU,EAChB,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,MAAM;IAGnC;;;;;;;;;;OAUG;IACG,qBAAqB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAazE;;;;;;;;;;;;;;;;;;;OAmBG;IACG,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,OAAO,CAAC;IAmCtE;;;;;;;;;;;;;;OAcG;IACG,cAAc,CAAC,QAAQ,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;CAKtE"}
@@ -0,0 +1,100 @@
1
+ import { authPath } from "../../lib/paths.js";
2
+ import { AuthError } from "../../lib/errors.js";
3
+ import { normalizeSession, normalizeUser } from "../types.js";
4
+ /**
5
+ * Password recovery and update methods
6
+ */
7
+ export class RecoveryMethods {
8
+ http;
9
+ tokenManager;
10
+ tenantId;
11
+ constructor(http, tokenManager, tenantId) {
12
+ this.http = http;
13
+ this.tokenManager = tokenManager;
14
+ this.tenantId = tenantId;
15
+ }
16
+ /**
17
+ * Send a password reset email
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * await client.auth.resetPasswordForEmail({
22
+ * email: "user@example.com",
23
+ * redirectTo: "https://myapp.com/reset-password",
24
+ * });
25
+ * ```
26
+ */
27
+ async resetPasswordForEmail(options) {
28
+ const path = authPath(this.tenantId, "/recover");
29
+ await this.http.post(path, {
30
+ email: options.email,
31
+ redirect_to: options.redirectTo,
32
+ }, { noAuth: true });
33
+ }
34
+ /**
35
+ * Update the user's password
36
+ *
37
+ * For sensitive operations, you may need to reauthenticate first.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * // Simple password update (when user has recovery token)
42
+ * await client.auth.updatePassword({
43
+ * password: "newSecurePassword123",
44
+ * });
45
+ *
46
+ * // With reauthentication nonce
47
+ * const { nonce } = await client.auth.reauthenticate();
48
+ * await client.auth.updatePassword({
49
+ * password: "newSecurePassword123",
50
+ * nonce,
51
+ * });
52
+ * ```
53
+ */
54
+ async updatePassword(options) {
55
+ const path = authPath(this.tenantId, "/user");
56
+ const body = {
57
+ password: options.password,
58
+ };
59
+ if (options.nonce) {
60
+ body.nonce = options.nonce;
61
+ }
62
+ const response = await this.http.put(path, body);
63
+ let session;
64
+ if ("user" in response && response.user) {
65
+ session = normalizeSession(response);
66
+ }
67
+ else {
68
+ const currentSession = this.tokenManager.getSession();
69
+ if (!currentSession) {
70
+ throw AuthError.notAuthenticated();
71
+ }
72
+ session = {
73
+ ...currentSession,
74
+ user: normalizeUser(response),
75
+ };
76
+ }
77
+ this.tokenManager.setSession(session, "USER_UPDATED");
78
+ return session;
79
+ }
80
+ /**
81
+ * Request reauthentication for sensitive operations
82
+ *
83
+ * Sends an OTP to the user's email or phone. The user must retrieve this OTP
84
+ * and provide it as the `nonce` parameter when performing sensitive operations
85
+ * like password changes.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * await client.auth.reauthenticate();
90
+ * // User receives OTP via email
91
+ * // User provides OTP as nonce
92
+ * await client.auth.updatePassword({ password: "new", nonce: otpFromEmail });
93
+ * ```
94
+ */
95
+ async reauthenticate(_options) {
96
+ const path = authPath(this.tenantId, "/reauthenticate");
97
+ await this.http.get(path);
98
+ }
99
+ }
100
+ //# sourceMappingURL=recovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery.js","sourceRoot":"","sources":["../../../src/auth/methods/recovery.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAUhD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAgB9D;;GAEG;AACH,MAAM,OAAO,eAAe;IAEP;IACA;IACA;IAHnB,YACmB,IAAgB,EAChB,YAA0B,EAC1B,QAAgB;QAFhB,SAAI,GAAJ,IAAI,CAAY;QAChB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAAQ;IAChC,CAAC;IAEJ;;;;;;;;;;OAUG;IACH,KAAK,CAA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