@niledatabase/react 3.1.0-alpha.0 → 4.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import * as React$1 from 'react';
1
+ import * as React from 'react';
2
2
  import React__default from 'react';
3
3
  import * as _tanstack_react_query from '@tanstack/react-query';
4
4
  import { QueryClient } from '@tanstack/react-query';
@@ -9,7 +9,6 @@ import { VariantProps } from 'class-variance-authority';
9
9
  import { CreateBasicUserRequest } from '@niledatabase/browser';
10
10
  import { CtxOrReq } from 'next-auth/client/_utils';
11
11
  import { BuiltInProviderType, RedirectableProviderType } from 'next-auth/providers/index';
12
- import * as next_auth_providers from 'next-auth/providers';
13
12
 
14
13
  type EmailSignInInfo = SignInOptions;
15
14
  type SignInSuccess = (response: Response) => void;
@@ -31,7 +30,7 @@ declare const buttonVariants: (props?: ({
31
30
  variant?: "default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
32
31
  size?: "default" | "sm" | "lg" | "icon" | null | undefined;
33
32
  } & class_variance_authority_dist_types.ClassProp) | undefined) => string;
34
- interface ButtonProps extends React$1.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
33
+ interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
35
34
  asChild?: boolean;
36
35
  loading?: boolean;
37
36
  }
@@ -116,67 +115,6 @@ declare const XSignInButton: React__default.ForwardRefExoticComponent<ButtonProp
116
115
  init?: RequestInit;
117
116
  } & React__default.RefAttributes<HTMLButtonElement>>;
118
117
 
119
- type ComponentFetchProps = {
120
- init?: RequestInit;
121
- };
122
- type PrefetchParams = {
123
- baseUrl?: string;
124
- disableQuery?: boolean;
125
- init?: RequestInit;
126
- client?: QueryClient;
127
- fetchUrl?: string;
128
- };
129
-
130
- type SignUpInfo = CreateBasicUserRequest & {
131
- tenantId?: string;
132
- fetchUrl?: string;
133
- callbackUrl?: string;
134
- newTenantName?: string;
135
- };
136
- type AllowedAny$2 = any;
137
- type Props$3 = PrefetchParams & {
138
- onSuccess?: (response: Response, formValues: SignUpInfo) => void;
139
- onError?: (e: Error, info: SignUpInfo) => void;
140
- beforeMutate?: (data: AllowedAny$2) => AllowedAny$2;
141
- buttonText?: string;
142
- callbackUrl?: string;
143
- createTenant?: string | boolean;
144
- className?: string;
145
- };
146
-
147
- declare function SigningUp({ className, ...props }: Props$3): React__default.JSX.Element;
148
-
149
- declare function useSignUp<T extends SignUpInfo>(params: Props$3, client?: QueryClient): _tanstack_react_query.UseMutateFunction<Response, Error, SignUpInfo, unknown>;
150
-
151
- type AllowedAny$1 = any;
152
- type LoginInfo = {
153
- email: string;
154
- password: string;
155
- };
156
- type LoginSuccess = (response: AllowedAny$1, formValues: LoginInfo, ...args: AllowedAny$1) => void;
157
- interface Props$2 {
158
- beforeMutate?: (data: AllowedAny$1) => AllowedAny$1;
159
- onSuccess?: LoginSuccess;
160
- onError?: (error: Error, data: AllowedAny$1) => void;
161
- callbackUrl?: string;
162
- client?: QueryClient;
163
- className?: string;
164
- init?: RequestInit;
165
- baseUrl?: string;
166
- fetchUrl?: string;
167
- }
168
-
169
- declare function SigningIn({ className, ...props }: Props$2): React__default.JSX.Element;
170
-
171
- declare function useSignIn(params?: Props$2): _tanstack_react_query.UseMutateFunction<next_auth_react.SignInResponse | undefined, Error, LoginInfo, any>;
172
-
173
- declare const SignOutButton: React__default.ForwardRefExoticComponent<ButtonProps & ComponentFetchProps & {
174
- redirect?: boolean;
175
- callbackUrl?: string;
176
- buttonText?: string;
177
- baseUrl?: string;
178
- } & React__default.RefAttributes<HTMLButtonElement>>;
179
-
180
118
  type JWT = {
181
119
  email: string;
182
120
  sub: string;
@@ -216,10 +154,24 @@ type ListenerParams = {
216
154
  };
217
155
  type Listener = (callback: ListenerParams) => void;
218
156
  type ListenerKeys = 'basePath' | 'baseUrl' | 'lastSync' | 'getSession' | 'session' | 'loading';
219
- type AuthConfig = {
220
- basePath: string;
221
- baseUrl: string;
222
- listenerKeys: Array<ListenerKeys>;
157
+ type AuthConfig = Config & {
158
+ listenerKeys?: Array<ListenerKeys>;
159
+ };
160
+ type Config = {
161
+ basePath?: string;
162
+ baseUrl?: string;
163
+ init?: RequestInit;
164
+ };
165
+ type PartialAuthorizer = null | {
166
+ state?: {
167
+ baseUrl?: string;
168
+ session?: {
169
+ user?: {
170
+ email?: string | undefined;
171
+ };
172
+ };
173
+ };
174
+ requestInit?: RequestInit | undefined;
223
175
  };
224
176
 
225
177
  type WarningCode = 'NEXTAUTH_URL' | 'NO_SECRET' | 'TWITTER_OAUTH_2_BETA' | 'DEBUG_ENABLED';
@@ -243,9 +195,6 @@ interface LoggerInstance extends Record<string, (...args: any) => any> {
243
195
  debug: (code: string, metadata: unknown) => void;
244
196
  }
245
197
 
246
- type FetchInit = CtxOrReq & {
247
- init?: RequestInit;
248
- };
249
198
  type GetSessionParams = CtxOrReq & {
250
199
  event?: 'storage' | 'timer' | 'hidden' | string;
251
200
  triggerEvent?: boolean;
@@ -253,47 +202,28 @@ type GetSessionParams = CtxOrReq & {
253
202
  baseUrl?: string;
254
203
  init?: RequestInit;
255
204
  };
256
- interface SessionProviderProps {
257
- children: React.ReactNode;
258
- session?: NileSession;
259
- baseUrl?: string;
260
- basePath?: string;
261
- /**
262
- * A time interval (in seconds) after which the session will be re-fetched.
263
- * If set to `0` (default), the session is not polled.
264
- */
265
- refetchInterval?: number;
266
- /**
267
- * `SessionProvider` automatically refetches the session when the user switches between windows.
268
- * This option activates this behaviour if set to `true` (default).
269
- */
270
- refetchOnWindowFocus?: boolean;
271
- /**
272
- * Set to `false` to stop polling when the device has no internet access offline (determined by `navigator.onLine`)
273
- *
274
- * [`navigator.onLine` documentation](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine)
275
- */
276
- refetchWhenOffline?: false;
277
- }
278
205
  declare enum State {
279
206
  SESSION = "getSession"
280
207
  }
281
208
  declare class Authorizer {
282
209
  state: AuthState;
283
210
  logger: LoggerInstance;
284
- init?: RequestInit;
211
+ requestInit?: RequestInit;
285
212
  addListener: (cb: Listener) => void;
286
213
  removeListener: (cb: Listener) => void;
287
214
  status: null | State;
288
215
  constructor(config?: AuthConfig);
289
216
  sync(event?: 'storage' | 'timer' | 'hidden' | 'poll' | 'visibilitychange'): Promise<void>;
290
217
  set baseUrl(val: string);
218
+ get baseUrl(): string;
219
+ configure(config?: Config): this;
220
+ sanitize(): PartialAuthorizer;
291
221
  initialize(params?: {
292
222
  baseUrl?: string;
293
223
  session?: NonErrorSession | null | undefined;
294
224
  }): Promise<void>;
295
225
  get apiBaseUrl(): string;
296
- fetchData<T = any>(path: string, { ctx, req, init }?: FetchInit): Promise<T | undefined>;
226
+ fetchData<T = any>(url: string, init?: RequestInit): Promise<T | undefined>;
297
227
  fetchFormData<T = {
298
228
  url: string;
299
229
  }>(url: string, init: RequestInit): Promise<{
@@ -302,21 +232,175 @@ declare class Authorizer {
302
232
  ok: boolean;
303
233
  url: string;
304
234
  } | undefined>;
305
- getProviders(params?: FetchInit): Promise<Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider> | undefined>;
306
- getCsrfToken(params?: FetchInit): Promise<string | undefined>;
235
+ getProviders(): Promise<Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider> | undefined>;
236
+ getCsrfToken(): Promise<string | undefined>;
307
237
  getSession(params?: GetSessionParams): Promise<NonErrorSession>;
308
- refreshSession(params: any): Promise<NonErrorSession>;
238
+ refreshSession(): Promise<NonErrorSession>;
309
239
  signOut<R extends boolean = true>(options?: SignOutParams<R> & {
310
240
  baseUrl?: string;
311
- init?: RequestInit;
241
+ auth?: Authorizer | PartialAuthorizer;
312
242
  fetchUrl?: string;
313
243
  }): Promise<R extends true ? undefined : SignOutResponse>;
314
244
  signIn<P extends RedirectableProviderType | undefined = undefined>(provider?: LiteralUnion<P extends RedirectableProviderType ? P | BuiltInProviderType : BuiltInProviderType>, options?: SignInOptions & {
315
245
  baseUrl?: string;
316
246
  init?: ResponseInit;
317
247
  fetchUrl?: string;
248
+ auth?: Authorizer | PartialAuthorizer;
318
249
  }, authorizationParams?: SignInAuthorizationParams): Promise<P extends RedirectableProviderType ? SignInResponse | undefined : undefined>;
250
+ signUp(options: {
251
+ baseUrl?: string;
252
+ init?: ResponseInit;
253
+ fetchUrl?: string;
254
+ newTenantName?: string;
255
+ createTenant?: string | boolean;
256
+ email: string;
257
+ password: string;
258
+ auth?: Authorizer | PartialAuthorizer;
259
+ tenantId?: string;
260
+ callbackUrl?: string;
261
+ redirect?: boolean;
262
+ }): Promise<any>;
263
+ }
264
+ declare const authorizer: Authorizer;
265
+ declare const auth: Authorizer;
266
+ declare const getSession: (params?: GetSessionParams) => Promise<NonErrorSession>;
267
+ declare const getCsrfToken: () => Promise<string | undefined>;
268
+ declare const getProviders: () => Promise<Record<LiteralUnion<BuiltInProviderType>, ClientSafeProvider> | undefined>;
269
+ declare const signOut: typeof authorizer.signOut;
270
+ declare const signIn: typeof authorizer.signIn;
271
+
272
+ type ComponentFetchProps = {
273
+ auth?: Authorizer | PartialAuthorizer;
274
+ init?: RequestInit;
275
+ };
276
+ type PrefetchParams = {
277
+ baseUrl?: string;
278
+ disableQuery?: boolean;
279
+ init?: RequestInit;
280
+ client?: QueryClient;
281
+ fetchUrl?: string;
282
+ };
283
+
284
+ type SignUpInfo = CreateBasicUserRequest & {
285
+ tenantId?: string;
286
+ fetchUrl?: string;
287
+ callbackUrl?: string;
288
+ newTenantName?: string;
289
+ };
290
+ type AllowedAny$2 = any;
291
+ type Props$3 = PrefetchParams & {
292
+ onSuccess?: (response: Response, formValues: SignUpInfo) => void;
293
+ onError?: (e: Error, info: SignUpInfo) => void;
294
+ beforeMutate?: (data: AllowedAny$2) => AllowedAny$2;
295
+ buttonText?: string;
296
+ callbackUrl?: string;
297
+ createTenant?: string | boolean;
298
+ className?: string;
299
+ redirect?: boolean;
300
+ };
301
+
302
+ declare function SigningUp({ className, ...props }: Props$3): React__default.JSX.Element;
303
+
304
+ declare function useSignUp<T extends SignUpInfo>(params: Props$3, client?: QueryClient): _tanstack_react_query.UseMutateFunction<any, Error, SignUpInfo, unknown>;
305
+
306
+ type AllowedAny$1 = any;
307
+ type LoginInfo = {
308
+ email: string;
309
+ password: string;
310
+ };
311
+ type LoginSuccess = (response: AllowedAny$1, formValues: LoginInfo, ...args: AllowedAny$1) => void;
312
+ type Props$2 = ComponentFetchProps & {
313
+ beforeMutate?: (data: AllowedAny$1) => AllowedAny$1;
314
+ onSuccess?: LoginSuccess;
315
+ onError?: (error: Error, data: AllowedAny$1) => void;
316
+ callbackUrl?: string;
317
+ client?: QueryClient;
318
+ className?: string;
319
+ baseUrl?: string;
320
+ fetchUrl?: string;
321
+ };
322
+
323
+ declare function SigningIn({ className, ...props }: Props$2): React__default.JSX.Element;
324
+
325
+ declare function useSignIn(params?: Props$2): _tanstack_react_query.UseMutateFunction<next_auth_react.SignInResponse | undefined, Error, LoginInfo, any>;
326
+
327
+ declare const SignOutButton: React__default.ForwardRefExoticComponent<ButtonProps & ComponentFetchProps & {
328
+ redirect?: boolean;
329
+ callbackUrl?: string;
330
+ buttonText?: string;
331
+ baseUrl?: string;
332
+ } & React__default.RefAttributes<HTMLButtonElement>>;
333
+
334
+ interface SessionProviderProps {
335
+ children: React__default.ReactNode;
336
+ session?: NileSession;
337
+ baseUrl?: string;
338
+ basePath?: string;
339
+ /**
340
+ * A time interval (in seconds) after which the session will be re-fetched.
341
+ * If set to `0` (default), the session is not polled.
342
+ */
343
+ refetchInterval?: number;
344
+ /**
345
+ * `SessionProvider` automatically refetches the session when the user switches between windows.
346
+ * This option activates this behaviour if set to `true` (default).
347
+ */
348
+ refetchOnWindowFocus?: boolean;
349
+ /**
350
+ * Set to `false` to stop polling when the device has no internet access offline (determined by `navigator.onLine`)
351
+ *
352
+ * [`navigator.onLine` documentation](https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine)
353
+ */
354
+ refetchWhenOffline?: false;
319
355
  }
356
+ type UpdateSession = (data?: any) => Promise<NonErrorSession | null | undefined>;
357
+ type SessionContextValue<R extends boolean = false> = R extends true ? {
358
+ update: UpdateSession;
359
+ data: NonErrorSession;
360
+ status: 'authenticated';
361
+ } | {
362
+ update: UpdateSession;
363
+ data: null | undefined;
364
+ status: 'loading';
365
+ } : {
366
+ update: UpdateSession;
367
+ data: NonErrorSession;
368
+ status: 'authenticated';
369
+ } | {
370
+ update: UpdateSession;
371
+ data: null | undefined;
372
+ status: 'unauthenticated' | 'loading';
373
+ };
374
+ declare const SessionContext: React__default.Context<{
375
+ update: UpdateSession;
376
+ data: NonErrorSession;
377
+ status: "authenticated";
378
+ } | {
379
+ update: UpdateSession;
380
+ data: null | undefined;
381
+ status: "unauthenticated" | "loading";
382
+ } | undefined>;
383
+ /**
384
+ * React Hook that gives you access
385
+ * to the logged in user's session data.
386
+ *
387
+ * [Documentation](https://next-auth.js.org/getting-started/client#usesession)
388
+ */
389
+ declare function useSession<R extends boolean>(options?: UseSessionOptions<R>): SessionContextValue<R>;
390
+ /**
391
+ * Signs the user out, by removing the session cookie.
392
+ * Automatically adds the CSRF token to the request.
393
+ *
394
+ * [Documentation](https://next-auth.js.org/getting-started/client#signout)
395
+ */
396
+ /**
397
+ * Provider to wrap the app in to make session data available globally.
398
+ * Can also be used to throttle the number of requests to the endpoint
399
+ * `/api/auth/session`.
400
+ *
401
+ * [Documentation](https://next-auth.js.org/getting-started/client#sessionprovider)
402
+ */
403
+ declare function SessionProvider(props: SessionProviderProps): React__default.JSX.Element;
320
404
 
321
405
  declare function SignedIn({ children, session: startSession, ...props }: SessionProviderProps & {
322
406
  className?: string;
@@ -405,63 +489,7 @@ declare function ResetPasswordForm(params: Params): React__default.JSX.Element;
405
489
 
406
490
  declare function useResetPassword(params?: Params): _tanstack_react_query.UseMutateFunction<Response, Error, MutateFnParams, unknown>;
407
491
 
408
- declare const Email: () => React$1.JSX.Element;
409
- declare const Password: () => React$1.JSX.Element;
410
-
411
- declare const authorizer: Authorizer;
412
- declare const auth: Authorizer;
413
- declare const getSession: (params?: GetSessionParams) => Promise<NonErrorSession>;
414
- declare const getCsrfToken: (params?: FetchInit) => Promise<string | undefined>;
415
- declare const getProviders: (params?: FetchInit) => Promise<Record<next_auth_react.LiteralUnion<next_auth_providers.BuiltInProviderType>, next_auth_react.ClientSafeProvider> | undefined>;
416
- declare const signOut: typeof authorizer.signOut;
417
- declare const signIn: typeof authorizer.signIn;
418
- type UpdateSession = (data?: any) => Promise<NonErrorSession | null | undefined>;
419
- type SessionContextValue<R extends boolean = false> = R extends true ? {
420
- update: UpdateSession;
421
- data: NonErrorSession;
422
- status: 'authenticated';
423
- } | {
424
- update: UpdateSession;
425
- data: null | undefined;
426
- status: 'loading';
427
- } : {
428
- update: UpdateSession;
429
- data: NonErrorSession;
430
- status: 'authenticated';
431
- } | {
432
- update: UpdateSession;
433
- data: null | undefined;
434
- status: 'unauthenticated' | 'loading';
435
- };
436
- declare const SessionContext: React__default.Context<{
437
- update: UpdateSession;
438
- data: NonErrorSession;
439
- status: "authenticated";
440
- } | {
441
- update: UpdateSession;
442
- data: null | undefined;
443
- status: "unauthenticated" | "loading";
444
- } | undefined>;
445
- /**
446
- * React Hook that gives you access
447
- * to the logged in user's session data.
448
- *
449
- * [Documentation](https://next-auth.js.org/getting-started/client#usesession)
450
- */
451
- declare function useSession<R extends boolean>(options?: UseSessionOptions<R>): SessionContextValue<R>;
452
- /**
453
- * Signs the user out, by removing the session cookie.
454
- * Automatically adds the CSRF token to the request.
455
- *
456
- * [Documentation](https://next-auth.js.org/getting-started/client#signout)
457
- */
458
- /**
459
- * Provider to wrap the app in to make session data available globally.
460
- * Can also be used to throttle the number of requests to the endpoint
461
- * `/api/auth/session`.
462
- *
463
- * [Documentation](https://next-auth.js.org/getting-started/client#sessionprovider)
464
- */
465
- declare function SessionProvider(props: SessionProviderProps): React__default.JSX.Element;
492
+ declare const Email: () => React.JSX.Element;
493
+ declare const Password: () => React.JSX.Element;
466
494
 
467
- export { AzureSignInButton as Azure, DiscordSignInButton as Discord, Email, EmailSigningIn as EmailSignIn, EmailSignInButton, GitHubSignInButton as GitHub, GoogleSSOButton as Google, HubSpotSignInButton as HubSpot, LinkedInSignInButton as LinkedIn, Password, ResetPasswordForm as PasswordResetForm, ResetPasswordForm$1 as PasswordResetRequestForm, SessionContext, SessionProvider, SigningIn as SignInForm, SignOutButton, SigningUp as SignUpForm, SignedIn, SignedOut, SlackSignInButton as Slack, TenantSelector, UserInfo, XSignInButton as X, auth, getCsrfToken, getProviders, getSession, signIn, signOut, useEmailSignIn, useMe, useResetPassword, useSession, useSignIn, useSignUp, useTenantId, useTenants };
495
+ export { type ActiveSession, type AuthConfig, type AuthState, Authorizer, AzureSignInButton as Azure, DiscordSignInButton as Discord, Email, EmailSigningIn as EmailSignIn, EmailSignInButton, GitHubSignInButton as GitHub, GoogleSSOButton as Google, HubSpotSignInButton as HubSpot, type JWT, LinkedInSignInButton as LinkedIn, type Listener, type ListenerKeys, type ListenerParams, Password, ResetPasswordForm as PasswordResetForm, ResetPasswordForm$1 as PasswordResetRequestForm, type NonErrorSession as Session, SessionContext, SessionProvider, SigningIn as SignInForm, SignOutButton, SigningUp as SignUpForm, SignedIn, SignedOut, SlackSignInButton as Slack, TenantSelector, UserInfo, XSignInButton as X, auth, getCsrfToken, getProviders, getSession, signIn, signOut, useEmailSignIn, useMe, useResetPassword, useSession, useSignIn, useSignUp, useTenantId, useTenants };