@niledatabase/server 5.0.0-alpha.2 → 5.0.0-alpha.3

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
@@ -348,10 +348,10 @@ declare class Users {
348
348
  emailVerified: boolean;
349
349
  }>, rawResponse?: boolean): Promise<T>;
350
350
  removeSelf(): Promise<Response>;
351
- getSelf(rawResponse?: true): Promise<Response>;
352
351
  getSelf<T = User | Response>(): Promise<T>;
353
- verifySelf(rawResponse?: true): Promise<Response>;
352
+ getSelf(rawResponse?: true): Promise<Response>;
354
353
  verifySelf<T = Response | void>(): Promise<T>;
354
+ verifySelf(rawResponse?: true): Promise<Response>;
355
355
  }
356
356
 
357
357
  type ReqContext = {
@@ -373,25 +373,25 @@ declare class Tenants {
373
373
  delete<T = Response>(payload: {
374
374
  id: string;
375
375
  }): Promise<T>;
376
- get(rawResponse: true): Promise<Response>;
377
376
  get<T = Tenant | Response>(id: string, rawResponse?: boolean): Promise<T>;
377
+ get(rawResponse: true): Promise<Response>;
378
378
  get<T = Tenant | Response>(payload: {
379
379
  id: string;
380
380
  }, rawResponse?: boolean): Promise<T>;
381
381
  update(req: Partial<Tenant>, rawResponse: true): Promise<Response>;
382
382
  update<T = Tenant | Response | undefined>(req: Partial<Tenant>, rawResponse?: boolean): Promise<T>;
383
- list(rawResponse: true): Promise<Response>;
384
383
  list<T = Tenant[] | Response>(): Promise<T>;
384
+ list(rawResponse: true): Promise<Response>;
385
385
  leaveTenant<T = Response>(req?: string | {
386
386
  tenantId: string;
387
387
  }): Promise<T>;
388
388
  addMember(req: JoinTenantRequest, rawResponse: true): Promise<Response>;
389
389
  addMember<T = User | Response>(req: JoinTenantRequest, rawResponse?: boolean): Promise<T>;
390
390
  removeMember(req: JoinTenantRequest, rawResponse?: boolean): Promise<Response>;
391
- users(req: boolean): Promise<Response>;
392
391
  users<T = User[] | Response>(req?: boolean | {
393
392
  tenantId?: string;
394
393
  }, rawResponse?: boolean): Promise<T>;
394
+ users(req: true): Promise<Response>;
395
395
  }
396
396
 
397
397
  type SignUpPayload = {
@@ -403,10 +403,10 @@ type SignUpPayload = {
403
403
  declare class Auth {
404
404
  #private;
405
405
  constructor(config: Config);
406
- getSession(rawResponse: true): Promise<Response>;
407
406
  getSession<T = JWT | ActiveSession | undefined>(rawResponse?: false): Promise<T>;
408
- getCsrf(rawResponse: true): Promise<Response>;
407
+ getSession(rawResponse: true): Promise<Response>;
409
408
  getCsrf<T = Response | JSON>(rawResponse?: false): Promise<T>;
409
+ getCsrf(rawResponse: true): Promise<Response>;
410
410
  listProviders(rawResponse: true): Promise<Response>;
411
411
  listProviders<T = {
412
412
  [key: string]: Provider;
@@ -419,6 +419,11 @@ declare class Auth {
419
419
  */
420
420
  signUp(payload: SignUpPayload, rawResponse: true): Promise<Response>;
421
421
  signUp<T = User | Response>(payload: SignUpPayload): Promise<T>;
422
+ forgotPassword(req: {
423
+ email: string;
424
+ callbackUrl?: string;
425
+ redirectUrl?: string;
426
+ }): Promise<Response>;
422
427
  resetPassword(req: Request | {
423
428
  email: string;
424
429
  password: string;
package/dist/index.d.ts CHANGED
@@ -348,10 +348,10 @@ declare class Users {
348
348
  emailVerified: boolean;
349
349
  }>, rawResponse?: boolean): Promise<T>;
350
350
  removeSelf(): Promise<Response>;
351
- getSelf(rawResponse?: true): Promise<Response>;
352
351
  getSelf<T = User | Response>(): Promise<T>;
353
- verifySelf(rawResponse?: true): Promise<Response>;
352
+ getSelf(rawResponse?: true): Promise<Response>;
354
353
  verifySelf<T = Response | void>(): Promise<T>;
354
+ verifySelf(rawResponse?: true): Promise<Response>;
355
355
  }
356
356
 
357
357
  type ReqContext = {
@@ -373,25 +373,25 @@ declare class Tenants {
373
373
  delete<T = Response>(payload: {
374
374
  id: string;
375
375
  }): Promise<T>;
376
- get(rawResponse: true): Promise<Response>;
377
376
  get<T = Tenant | Response>(id: string, rawResponse?: boolean): Promise<T>;
377
+ get(rawResponse: true): Promise<Response>;
378
378
  get<T = Tenant | Response>(payload: {
379
379
  id: string;
380
380
  }, rawResponse?: boolean): Promise<T>;
381
381
  update(req: Partial<Tenant>, rawResponse: true): Promise<Response>;
382
382
  update<T = Tenant | Response | undefined>(req: Partial<Tenant>, rawResponse?: boolean): Promise<T>;
383
- list(rawResponse: true): Promise<Response>;
384
383
  list<T = Tenant[] | Response>(): Promise<T>;
384
+ list(rawResponse: true): Promise<Response>;
385
385
  leaveTenant<T = Response>(req?: string | {
386
386
  tenantId: string;
387
387
  }): Promise<T>;
388
388
  addMember(req: JoinTenantRequest, rawResponse: true): Promise<Response>;
389
389
  addMember<T = User | Response>(req: JoinTenantRequest, rawResponse?: boolean): Promise<T>;
390
390
  removeMember(req: JoinTenantRequest, rawResponse?: boolean): Promise<Response>;
391
- users(req: boolean): Promise<Response>;
392
391
  users<T = User[] | Response>(req?: boolean | {
393
392
  tenantId?: string;
394
393
  }, rawResponse?: boolean): Promise<T>;
394
+ users(req: true): Promise<Response>;
395
395
  }
396
396
 
397
397
  type SignUpPayload = {
@@ -403,10 +403,10 @@ type SignUpPayload = {
403
403
  declare class Auth {
404
404
  #private;
405
405
  constructor(config: Config);
406
- getSession(rawResponse: true): Promise<Response>;
407
406
  getSession<T = JWT | ActiveSession | undefined>(rawResponse?: false): Promise<T>;
408
- getCsrf(rawResponse: true): Promise<Response>;
407
+ getSession(rawResponse: true): Promise<Response>;
409
408
  getCsrf<T = Response | JSON>(rawResponse?: false): Promise<T>;
409
+ getCsrf(rawResponse: true): Promise<Response>;
410
410
  listProviders(rawResponse: true): Promise<Response>;
411
411
  listProviders<T = {
412
412
  [key: string]: Provider;
@@ -419,6 +419,11 @@ declare class Auth {
419
419
  */
420
420
  signUp(payload: SignUpPayload, rawResponse: true): Promise<Response>;
421
421
  signUp<T = User | Response>(payload: SignUpPayload): Promise<T>;
422
+ forgotPassword(req: {
423
+ email: string;
424
+ callbackUrl?: string;
425
+ redirectUrl?: string;
426
+ }): Promise<Response>;
422
427
  resetPassword(req: Request | {
423
428
  email: string;
424
429
  password: string;
package/dist/index.js CHANGED
@@ -910,9 +910,11 @@ async function route13(req, config) {
910
910
  function matches13(configRoutes, request2) {
911
911
  return urlMatches(request2.url, configRoutes.PASSWORD_RESET);
912
912
  }
913
- async function fetchResetPassword(config, method, body, params) {
913
+ async function fetchResetPassword(config, method, body, params, useJson = true) {
914
914
  const authParams = new URLSearchParams(params ?? {});
915
- authParams?.set("json", "true");
915
+ if (useJson) {
916
+ authParams?.set("json", "true");
917
+ }
916
918
  const clientUrl = `${config.serverOrigin}${config.routePrefix}${"/auth/reset-password" /* PASSWORD_RESET */}?${authParams?.toString()}`;
917
919
  const init = {
918
920
  method,
@@ -1942,11 +1944,42 @@ var Auth = class {
1942
1944
  return res;
1943
1945
  }
1944
1946
  }
1947
+ async forgotPassword(req) {
1948
+ let email = "";
1949
+ const defaults = defaultCallbackUrl({
1950
+ config: this.#config
1951
+ });
1952
+ let callbackUrl = defaults.callbackUrl;
1953
+ let redirectUrl = defaults.redirectUrl;
1954
+ if ("email" in req) {
1955
+ email = req.email;
1956
+ }
1957
+ if ("callbackUrl" in req) {
1958
+ callbackUrl = req.callbackUrl ? req.callbackUrl : null;
1959
+ }
1960
+ if ("redirectUrl" in req) {
1961
+ redirectUrl = req.redirectUrl ? req.redirectUrl : null;
1962
+ }
1963
+ const body = JSON.stringify({
1964
+ email,
1965
+ redirectUrl,
1966
+ callbackUrl
1967
+ });
1968
+ const data = await fetchResetPassword(
1969
+ this.#config,
1970
+ "POST",
1971
+ body,
1972
+ new URLSearchParams(),
1973
+ false
1974
+ );
1975
+ return data;
1976
+ }
1945
1977
  async resetPassword(req) {
1946
1978
  let email = "";
1947
1979
  let password = "";
1948
- let callbackUrl = null;
1949
- let redirectUrl = null;
1980
+ const defaults = defaultCallbackUrl({ config: this.#config });
1981
+ let callbackUrl = defaults.callbackUrl;
1982
+ let redirectUrl = defaults.redirectUrl;
1950
1983
  if (req instanceof Request) {
1951
1984
  const body2 = await req.json();
1952
1985
  email = body2.email;
@@ -1975,19 +2008,6 @@ var Auth = class {
1975
2008
  redirectUrl = req.redirectUrl ? req.redirectUrl : null;
1976
2009
  }
1977
2010
  }
1978
- const fallbackCb = parseCallback(this.#config.headers);
1979
- if (fallbackCb) {
1980
- const [, value] = fallbackCb.split("=");
1981
- if (value) {
1982
- const parsedUrl = decodeURIComponent(value);
1983
- if (!redirectUrl) {
1984
- redirectUrl = `${new URL(parsedUrl).origin}${"/auth/reset-password" /* PASSWORD_RESET */}`;
1985
- }
1986
- }
1987
- if (!callbackUrl) {
1988
- callbackUrl = value;
1989
- }
1990
- }
1991
2011
  await this.getCsrf();
1992
2012
  const body = JSON.stringify({
1993
2013
  email,
@@ -2206,6 +2226,19 @@ function parseResetToken(headers) {
2206
2226
  const [, token] = /((__Secure-)?nile\.reset=[^;]+)/.exec(authCookie) ?? [];
2207
2227
  return token;
2208
2228
  }
2229
+ function defaultCallbackUrl({ config }) {
2230
+ let cb = null;
2231
+ let redirect = null;
2232
+ const fallbackCb = parseCallback(config.headers);
2233
+ if (fallbackCb) {
2234
+ const [, value] = fallbackCb.split("=");
2235
+ cb = decodeURIComponent(value);
2236
+ if (value) {
2237
+ redirect = `${new URL(cb).origin}${"/auth/reset-password" /* PASSWORD_RESET */}`;
2238
+ }
2239
+ }
2240
+ return { callbackUrl: cb, redirectUrl: redirect };
2241
+ }
2209
2242
 
2210
2243
  // src/auth/getCsrf.ts
2211
2244
  async function getCsrf(config, rawResponse = false) {