@gatwech/core 1.0.0-beta.19 → 1.0.0-beta.21

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.
@@ -1,3 +1,3 @@
1
- import { a as optionsMiddleware, i as createAuthMiddleware, n as AuthMiddleware, r as createAuthEndpoint, t as AuthEndpoint } from "../index-Df0KhQRf.mjs";
1
+ import { a as optionsMiddleware, i as createAuthMiddleware, n as AuthMiddleware, r as createAuthEndpoint, t as AuthEndpoint } from "../index-BL_t8cRp.mjs";
2
2
  import "../index-CNtOUpmF.mjs";
3
3
  export { AuthEndpoint, AuthMiddleware, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
@@ -1,4 +1,4 @@
1
- import { d as AuthContext, nt as DBAdapter, st as DBTransactionAdapter } from "../index-Df0KhQRf.mjs";
1
+ import { d as AuthContext, nt as DBAdapter, st as DBTransactionAdapter } from "../index-BL_t8cRp.mjs";
2
2
  import "../index-CNtOUpmF.mjs";
3
3
  import { t as AsyncLocalStorage } from "../index-CRg-E-VF.mjs";
4
4
  import { EndpointContext, InputContext } from "better-call";
@@ -1,3 +1,3 @@
1
- import { at as DBAdapterInstance, ct as Where, et as CleanedWhere, it as DBAdapterFactoryConfig, nt as DBAdapter, ot as DBAdapterSchemaCreation, rt as DBAdapterDebugLogOption, st as DBTransactionAdapter, tt as CustomAdapter } from "../../index-Df0KhQRf.mjs";
1
+ import { at as DBAdapterInstance, ct as Where, et as CleanedWhere, it as DBAdapterFactoryConfig, nt as DBAdapter, ot as DBAdapterSchemaCreation, rt as DBAdapterDebugLogOption, st as DBTransactionAdapter, tt as CustomAdapter } from "../../index-BL_t8cRp.mjs";
2
2
  import "../../index-CNtOUpmF.mjs";
3
3
  export { CleanedWhere, CustomAdapter, DBAdapter, DBAdapterDebugLogOption, DBAdapterFactoryConfig, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, Where };
@@ -1,3 +1,3 @@
1
- import { At as DBPreservedModels, Ct as rateLimitSchema, Dt as DBFieldAttribute, Et as PayvoAuthPluginDBSchema, Mt as PayvoAuthDBSchema, Nt as SecondaryStorage, Ot as DBFieldAttributeConfig, St as RateLimit, Tt as accountSchema, _t as User, bt as Session, dt as FieldAttributeConfig, ft as FieldType, gt as verificationSchema, ht as Verification, jt as DBPrimitive, kt as DBFieldType, lt as AuthPluginSchema, mt as Primitive, pt as PayvoAuthDbSchema, ut as FieldAttribute, vt as userSchema, wt as Account, xt as sessionSchema, yt as coreSchema } from "../index-Df0KhQRf.mjs";
1
+ import { At as DBPreservedModels, Ct as rateLimitSchema, Dt as DBFieldAttribute, Et as PayvoAuthPluginDBSchema, Mt as PayvoAuthDBSchema, Nt as SecondaryStorage, Ot as DBFieldAttributeConfig, St as RateLimit, Tt as accountSchema, _t as User, bt as Session, dt as FieldAttributeConfig, ft as FieldType, gt as verificationSchema, ht as Verification, jt as DBPrimitive, kt as DBFieldType, lt as AuthPluginSchema, mt as Primitive, pt as PayvoAuthDbSchema, ut as FieldAttribute, vt as userSchema, wt as Account, xt as sessionSchema, yt as coreSchema } from "../index-BL_t8cRp.mjs";
2
2
  import "../index-CNtOUpmF.mjs";
3
3
  export { Account, AuthPluginSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPreservedModels, DBPrimitive, FieldAttribute, FieldAttributeConfig, FieldType, PayvoAuthDBSchema, PayvoAuthDbSchema, PayvoAuthPluginDBSchema, Primitive, RateLimit, SecondaryStorage, Session, User, Verification, accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
@@ -1,3 +1,3 @@
1
- import { a as shouldPublishLog, c as env, d as isDevelopment, f as isProduction, i as logger, l as getBooleanEnvVar, m as nodeENV, n as createLogger, o as getColorDepth, p as isTest, r as levels, s as ENV, t as TTY_COLORS, u as getEnvVar } from "../env-ubiqEEZm.mjs";
1
+ import { a as shouldPublishLog, c as env, d as isDevelopment, f as isProduction, i as logger, l as getBooleanEnvVar, m as nodeENV, n as createLogger, o as getColorDepth, p as isTest, r as levels, s as ENV, t as TTY_COLORS, u as getEnvVar } from "../env-BL9S5k9_.mjs";
2
2
 
3
3
  export { ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
@@ -1,4 +1,4 @@
1
- import "../utils-CTOwq_Nj.mjs";
2
- import { n as BASE_ERROR_CODES, t as PayvoAuthError } from "../error-DKIIiFmH.mjs";
1
+ import "../utils-BFQCAfNW.mjs";
2
+ import { n as BASE_ERROR_CODES, t as PayvoAuthError } from "../error-41YsFQ8b.mjs";
3
3
 
4
4
  export { BASE_ERROR_CODES, PayvoAuthError };
@@ -1,4 +1,4 @@
1
- import { t as defineErrorCodes } from "./utils-CTOwq_Nj.mjs";
1
+ import { t as defineErrorCodes } from "./utils-BFQCAfNW.mjs";
2
2
 
3
3
  //#region src/error/codes.ts
4
4
  const BASE_ERROR_CODES = defineErrorCodes({
@@ -121,7 +121,7 @@ interface SecondaryStorage {
121
121
  * @param key - Key to get
122
122
  * @returns - Value of the key
123
123
  */
124
- get: (key: string) => Awaitable$1<unknown>;
124
+ get: (key: string) => Awaitable<unknown>;
125
125
  /**
126
126
  * Atomically get a value and delete it from storage.
127
127
  *
@@ -133,7 +133,7 @@ interface SecondaryStorage {
133
133
  * breaking release, or require database-backed verification storage for
134
134
  * security-sensitive consume paths.
135
135
  */
136
- getAndDelete?: (key: string) => Awaitable$1<unknown>;
136
+ getAndDelete?: (key: string) => Awaitable<unknown>;
137
137
  /**
138
138
  * Atomically increment the counter at `key` by one, returning the
139
139
  * post-increment value.
@@ -148,7 +148,7 @@ interface SecondaryStorage {
148
148
  * this required for secondary-storage-backed rate limiting in the next minor
149
149
  * on `next`.
150
150
  */
151
- increment?: (key: string, ttl: number) => Awaitable$1<number>;
151
+ increment?: (key: string, ttl: number) => Awaitable<number>;
152
152
  set: (
153
153
  /**
154
154
  * Key to store
@@ -161,12 +161,12 @@ interface SecondaryStorage {
161
161
  /**
162
162
  * Time to live in seconds
163
163
  */
164
- ttl?: number | undefined) => Awaitable$1<void | null | unknown>;
164
+ ttl?: number | undefined) => Awaitable<void | null | unknown>;
165
165
  /**
166
166
  *
167
167
  * @param key - Key to delete
168
168
  */
169
- delete: (key: string) => Awaitable$1<void | null | string>;
169
+ delete: (key: string) => Awaitable<void | null | string>;
170
170
  }
171
171
  //#endregion
172
172
  //#region src/db/plugin.d.ts
@@ -1078,8 +1078,8 @@ type PayvoAuthCookies = {
1078
1078
  //#endregion
1079
1079
  //#region src/types/helper.d.ts
1080
1080
  type Primitive = string | number | symbol | bigint | boolean | null | undefined;
1081
- type Awaitable$1<T> = T | Promise<T>;
1082
- type AwaitableFunction<T> = T | (() => Awaitable$1<T>);
1081
+ type Awaitable<T> = T | Promise<T>;
1082
+ type AwaitableFunction<T> = T | (() => Awaitable<T>);
1083
1083
  type LiteralString = "" | (string & Record<never, never>);
1084
1084
  type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
1085
1085
  type Prettify<T> = { [K in keyof T]: T[K] } & {};
@@ -1387,7 +1387,7 @@ type SocialProviders = { [K in SocialProviderList[number]]?: Parameters<(typeof
1387
1387
  type SocialProviderList = typeof socialProviderList;
1388
1388
  //#endregion
1389
1389
  //#region src/types/plugin.d.ts
1390
- type Awaitable<T> = T | Promise<T>;
1390
+ type Awaitable$1<T> = T | Promise<T>;
1391
1391
  type DeepPartial<T> = T extends Function ? T : T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } : T;
1392
1392
  type HookEndpointContext = Partial<EndpointContext<string, any> & Omit<InputContext<string, any>, "method">> & {
1393
1393
  path: string;
@@ -1403,7 +1403,7 @@ type PayvoAuthPlugin = {
1403
1403
  * The init function is called when the plugin is initialized.
1404
1404
  * You can return a new context or modify the existing context.
1405
1405
  */
1406
- init?: ((ctx: AuthContext) => Awaitable<{
1406
+ init?: ((ctx: AuthContext) => Awaitable$1<{
1407
1407
  context?: DeepPartial<Omit<AuthContext, "options">>;
1408
1408
  options?: Partial<PayvoAuthOptions>;
1409
1409
  }> | void | Promise<void>) | undefined;
@@ -1624,6 +1624,27 @@ type PayvoAuthAdvancedOptions = {
1624
1624
  * Payvo Auth. And could lead to security vulnerabilities.
1625
1625
  */
1626
1626
  disableOriginCheck?: boolean | undefined;
1627
+ /**
1628
+ * Run deferred work, such as sending events to a remote service, after the
1629
+ * response is sent. On serverless platforms, pass the platform's hook so
1630
+ * the function stays alive until the work finishes.
1631
+ *
1632
+ * @example
1633
+ * // Vercel
1634
+ * import { waitUntil } from "@vercel/functions";
1635
+ * advanced: { backgroundTasks: { handler: waitUntil } }
1636
+ *
1637
+ * @example
1638
+ * // Cloudflare Workers, with the execution context kept in AsyncLocalStorage
1639
+ * advanced: {
1640
+ * backgroundTasks: {
1641
+ * handler: (promise) => executionContext.getStore()?.waitUntil(promise),
1642
+ * },
1643
+ * }
1644
+ */
1645
+ backgroundTasks?: {
1646
+ handler: (promise: Promise<unknown>) => void;
1647
+ } | undefined;
1627
1648
  /**
1628
1649
  * Configure cookies to be cross subdomains
1629
1650
  */
@@ -2369,9 +2390,10 @@ type PayvoAuthOptions = {
2369
2390
  data: Optional<User & Record<string, any>>;
2370
2391
  }>;
2371
2392
  /**
2372
- * Hook that is called after a user is updated.
2393
+ * Hook that is called after a user is updated. `data` holds the
2394
+ * fields that were written, after every `before` hook ran.
2373
2395
  */
2374
- after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2396
+ after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext, data?: Partial<User> & Record<string, unknown>) => Promise<void>;
2375
2397
  };
2376
2398
  delete?: {
2377
2399
  /**
@@ -2416,9 +2438,10 @@ type PayvoAuthOptions = {
2416
2438
  data: Optional<Session & Record<string, any>>;
2417
2439
  }>;
2418
2440
  /**
2419
- * Hook that is called after a session is updated.
2441
+ * Hook that is called after a session is updated. `data` holds the
2442
+ * fields that were written, after every `before` hook ran.
2420
2443
  */
2421
- after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2444
+ after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext, data?: Partial<Session> & Record<string, unknown>) => Promise<void>;
2422
2445
  };
2423
2446
  delete?: {
2424
2447
  /**
@@ -2463,9 +2486,10 @@ type PayvoAuthOptions = {
2463
2486
  data: Optional<Account & Record<string, any>>;
2464
2487
  }>;
2465
2488
  /**
2466
- * Hook that is called after a account is updated.
2489
+ * Hook that is called after a account is updated. `data` holds the
2490
+ * fields that were written, after every `before` hook ran.
2467
2491
  */
2468
- after?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2492
+ after?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext, data?: Partial<Account> & Record<string, unknown>) => Promise<void>;
2469
2493
  };
2470
2494
  delete?: {
2471
2495
  /**
@@ -2507,9 +2531,11 @@ type PayvoAuthOptions = {
2507
2531
  data: Optional<Verification & Record<string, any>>;
2508
2532
  }>;
2509
2533
  /**
2510
- * Hook that is called after a verification is updated.
2534
+ * Hook that is called after a verification is updated. `data`
2535
+ * holds the fields that were written, after every `before` hook
2536
+ * ran.
2511
2537
  */
2512
- after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2538
+ after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext, data?: Partial<Verification> & Record<string, unknown>) => Promise<void>;
2513
2539
  };
2514
2540
  delete?: {
2515
2541
  /**
@@ -2793,6 +2819,19 @@ type AuthContext<Options extends PayvoAuthOptions = PayvoAuthOptions> = {
2793
2819
  * @default false
2794
2820
  */
2795
2821
  skipCSRFCheck: boolean;
2822
+ /**
2823
+ * Runs work after the response without blocking it, e.g. sending an
2824
+ * event to a remote service.
2825
+ *
2826
+ * This is inferred from the `options.advanced?.backgroundTasks?.handler`
2827
+ * option. Without one, the promise runs on its own.
2828
+ */
2829
+ runInBackground: (promise: Promise<unknown>) => void;
2830
+ /**
2831
+ * Runs work in the background when `advanced.backgroundTasks` is
2832
+ * configured, and awaits it otherwise, for work that must finish
2833
+ */
2834
+ runInBackgroundOrAwait: (promise: Promise<unknown> | void) => Awaitable<unknown>;
2796
2835
  };
2797
2836
  //#endregion
2798
2837
  //#region src/types/plugin-client.d.ts
@@ -2999,4 +3038,4 @@ declare const createAuthEndpoint: <Path extends string, Opts extends EndpointOpt
2999
3038
  type AuthEndpoint = ReturnType<typeof createAuthEndpoint>;
3000
3039
  type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;
3001
3040
  //#endregion
3002
- export { ProviderOptions as $, GithubProfile as A, DBPreservedModels as At, createAuthorizationCodeRequest as B, SocialProviders as C, rateLimitSchema as Ct, GoogleProfile as D, DBFieldAttribute as Dt, GoogleOptions as E, PayvoAuthPluginDBSchema as Et, LiteralUnion as F, createRefreshAccessTokenRequest as G, validateToken as H, Prettify as I, clientCredentialsToken as J, refreshAccessToken as K, Primitive as L, Awaitable$1 as M, PayvoAuthDBSchema as Mt, AwaitableFunction as N, SecondaryStorage as Nt, google as O, DBFieldAttributeConfig as Ot, LiteralString as P, OAuthProvider as Q, UnionToIntersection as R, SocialProviderListEnum as S, RateLimit as St, socialProviders as T, accountSchema as Tt, generateCodeChallenge as U, validateAuthorizationCode as V, getOAuth2Tokens as W, OAuth2Tokens as X, createClientCredentialsTokenRequest as Y, OAuth2UserInfo as Z, PayvoAuthRateLimitOptions as _, User as _t, optionsMiddleware as a, DBAdapterInstance as at, SocialProvider as b, Session as bt, ClientStore as c, Where as ct, AuthContext as d, FieldAttributeConfig as dt, CleanedWhere as et, GenericEndpointContext as f, FieldType as ft, PayvoAuthOptions as g, verificationSchema as gt, PayvoAuthAdvancedOptions as h, Verification as ht, createAuthMiddleware as i, DBAdapterFactoryConfig as it, github as j, DBPrimitive as jt, GithubOptions as k, DBFieldType as kt, PayvoAuthClientOptions as l, AuthPluginSchema as lt, GenerateIdFn as m, Primitive$1 as mt, AuthMiddleware as n, DBAdapter as nt, StandardSchemaV1$1 as o, DBAdapterSchemaCreation as ot, InternalAdapter as p, PayvoAuthDbSchema as pt, createAuthorizationURL as q, createAuthEndpoint as r, DBAdapterDebugLogOption as rt, ClientAtomListener as s, DBTransactionAdapter as st, AuthEndpoint as t, CustomAdapter as tt, PayvoAuthClientPlugin as u, FieldAttribute as ut, HookEndpointContext as v, userSchema as vt, socialProviderList as w, Account as wt, SocialProviderList as x, sessionSchema as xt, PayvoAuthPlugin as y, coreSchema as yt, PayvoAuthCookies as z };
3041
+ export { ProviderOptions as $, GithubProfile as A, DBPreservedModels as At, createAuthorizationCodeRequest as B, SocialProviders as C, rateLimitSchema as Ct, GoogleProfile as D, DBFieldAttribute as Dt, GoogleOptions as E, PayvoAuthPluginDBSchema as Et, LiteralUnion as F, createRefreshAccessTokenRequest as G, validateToken as H, Prettify as I, clientCredentialsToken as J, refreshAccessToken as K, Primitive as L, Awaitable as M, PayvoAuthDBSchema as Mt, AwaitableFunction as N, SecondaryStorage as Nt, google as O, DBFieldAttributeConfig as Ot, LiteralString as P, OAuthProvider as Q, UnionToIntersection as R, SocialProviderListEnum as S, RateLimit as St, socialProviders as T, accountSchema as Tt, generateCodeChallenge as U, validateAuthorizationCode as V, getOAuth2Tokens as W, OAuth2Tokens as X, createClientCredentialsTokenRequest as Y, OAuth2UserInfo as Z, PayvoAuthRateLimitOptions as _, User as _t, optionsMiddleware as a, DBAdapterInstance as at, SocialProvider as b, Session as bt, ClientStore as c, Where as ct, AuthContext as d, FieldAttributeConfig as dt, CleanedWhere as et, GenericEndpointContext as f, FieldType as ft, PayvoAuthOptions as g, verificationSchema as gt, PayvoAuthAdvancedOptions as h, Verification as ht, createAuthMiddleware as i, DBAdapterFactoryConfig as it, github as j, DBPrimitive as jt, GithubOptions as k, DBFieldType as kt, PayvoAuthClientOptions as l, AuthPluginSchema as lt, GenerateIdFn as m, Primitive$1 as mt, AuthMiddleware as n, DBAdapter as nt, StandardSchemaV1$1 as o, DBAdapterSchemaCreation as ot, InternalAdapter as p, PayvoAuthDbSchema as pt, createAuthorizationURL as q, createAuthEndpoint as r, DBAdapterDebugLogOption as rt, ClientAtomListener as s, DBTransactionAdapter as st, AuthEndpoint as t, CustomAdapter as tt, PayvoAuthClientPlugin as u, FieldAttribute as ut, HookEndpointContext as v, userSchema as vt, socialProviderList as w, Account as wt, SocialProviderList as x, sessionSchema as xt, PayvoAuthPlugin as y, coreSchema as yt, PayvoAuthCookies as z };
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { F as LiteralUnion, I as Prettify, L as Primitive, M as Awaitable, N as AwaitableFunction, P as LiteralString, R as UnionToIntersection, _ as PayvoAuthRateLimitOptions, c as ClientStore, d as AuthContext, f as GenericEndpointContext, g as PayvoAuthOptions, h as PayvoAuthAdvancedOptions, l as PayvoAuthClientOptions, m as GenerateIdFn, o as StandardSchemaV1, p as InternalAdapter, s as ClientAtomListener, u as PayvoAuthClientPlugin, v as HookEndpointContext, y as PayvoAuthPlugin, z as PayvoAuthCookies } from "./index-Df0KhQRf.mjs";
1
+ import { F as LiteralUnion, I as Prettify, L as Primitive, M as Awaitable, N as AwaitableFunction, P as LiteralString, R as UnionToIntersection, _ as PayvoAuthRateLimitOptions, c as ClientStore, d as AuthContext, f as GenericEndpointContext, g as PayvoAuthOptions, h as PayvoAuthAdvancedOptions, l as PayvoAuthClientOptions, m as GenerateIdFn, o as StandardSchemaV1, p as InternalAdapter, s as ClientAtomListener, u as PayvoAuthClientPlugin, v as HookEndpointContext, y as PayvoAuthPlugin, z as PayvoAuthCookies } from "./index-BL_t8cRp.mjs";
2
2
  import "./index-CNtOUpmF.mjs";
3
3
  export { AuthContext, Awaitable, AwaitableFunction, ClientAtomListener, ClientStore, GenerateIdFn, GenericEndpointContext, HookEndpointContext, InternalAdapter, LiteralString, LiteralUnion, PayvoAuthAdvancedOptions, PayvoAuthClientOptions, PayvoAuthClientPlugin, PayvoAuthCookies, PayvoAuthOptions, PayvoAuthPlugin, PayvoAuthRateLimitOptions, Prettify, Primitive, StandardSchemaV1, UnionToIntersection };
@@ -1,3 +1,3 @@
1
- import { $ as ProviderOptions, B as createAuthorizationCodeRequest, G as createRefreshAccessTokenRequest, H as validateToken, J as clientCredentialsToken, K as refreshAccessToken, Q as OAuthProvider, U as generateCodeChallenge, V as validateAuthorizationCode, W as getOAuth2Tokens, X as OAuth2Tokens, Y as createClientCredentialsTokenRequest, Z as OAuth2UserInfo, q as createAuthorizationURL } from "../index-Df0KhQRf.mjs";
1
+ import { $ as ProviderOptions, B as createAuthorizationCodeRequest, G as createRefreshAccessTokenRequest, H as validateToken, J as clientCredentialsToken, K as refreshAccessToken, Q as OAuthProvider, U as generateCodeChallenge, V as validateAuthorizationCode, W as getOAuth2Tokens, X as OAuth2Tokens, Y as createClientCredentialsTokenRequest, Z as OAuth2UserInfo, q as createAuthorizationURL } from "../index-BL_t8cRp.mjs";
2
2
  import "../index-CNtOUpmF.mjs";
3
3
  export { OAuth2Tokens, OAuth2UserInfo, OAuthProvider, ProviderOptions, clientCredentialsToken, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getOAuth2Tokens, refreshAccessToken, validateAuthorizationCode, validateToken };
@@ -1,3 +1,3 @@
1
- import { A as GithubProfile, C as SocialProviders, D as GoogleProfile, E as GoogleOptions, O as google, S as SocialProviderListEnum, T as socialProviders, b as SocialProvider, j as github, k as GithubOptions, w as socialProviderList, x as SocialProviderList } from "../index-Df0KhQRf.mjs";
1
+ import { A as GithubProfile, C as SocialProviders, D as GoogleProfile, E as GoogleOptions, O as google, S as SocialProviderListEnum, T as socialProviders, b as SocialProvider, j as github, k as GithubOptions, w as socialProviderList, x as SocialProviderList } from "../index-BL_t8cRp.mjs";
2
2
  import "../index-CNtOUpmF.mjs";
3
3
  export { GithubOptions, GithubProfile, GoogleOptions, GoogleProfile, SocialProvider, SocialProviderList, SocialProviderListEnum, SocialProviders, github, google, socialProviderList, socialProviders };
@@ -1,6 +1,6 @@
1
- import "../utils-CTOwq_Nj.mjs";
2
- import { t as PayvoAuthError } from "../error-DKIIiFmH.mjs";
3
- import { i as logger } from "../env-ubiqEEZm.mjs";
1
+ import { i as logger } from "../env-BL9S5k9_.mjs";
2
+ import "../utils-BFQCAfNW.mjs";
3
+ import { t as PayvoAuthError } from "../error-41YsFQ8b.mjs";
4
4
  import { a as refreshAccessToken, n as validateAuthorizationCode, o as createAuthorizationURL } from "../oauth2-DyI7_CNv.mjs";
5
5
  import * as z$1 from "zod";
6
6
  import { betterFetch } from "@better-fetch/fetch";
@@ -4,7 +4,7 @@ import type { DBAdapter, Where } from "../db/adapter";
4
4
  import { createLogger } from "../env";
5
5
  import type { OAuthProvider } from "../oauth2";
6
6
  import type { PayvoAuthCookies } from "./cookie";
7
- import type { LiteralUnion } from "./helper";
7
+ import type { Awaitable, LiteralUnion } from "./helper";
8
8
  import type { PayvoAuthOptions, PayvoAuthRateLimitOptions } from "./init-options";
9
9
  export type GenericEndpointContext<Options extends PayvoAuthOptions = PayvoAuthOptions> = EndpointContext<string, any> & {
10
10
  context: AuthContext<Options>;
@@ -173,5 +173,18 @@ export type AuthContext<Options extends PayvoAuthOptions = PayvoAuthOptions> = {
173
173
  * @default false
174
174
  */
175
175
  skipCSRFCheck: boolean;
176
+ /**
177
+ * Runs work after the response without blocking it, e.g. sending an
178
+ * event to a remote service.
179
+ *
180
+ * This is inferred from the `options.advanced?.backgroundTasks?.handler`
181
+ * option. Without one, the promise runs on its own.
182
+ */
183
+ runInBackground: (promise: Promise<unknown>) => void;
184
+ /**
185
+ * Runs work in the background when `advanced.backgroundTasks` is
186
+ * configured, and awaits it otherwise, for work that must finish
187
+ */
188
+ runInBackgroundOrAwait: (promise: Promise<unknown> | void) => Awaitable<unknown>;
176
189
  };
177
190
  export {};
@@ -137,6 +137,27 @@ export type PayvoAuthAdvancedOptions = {
137
137
  * Payvo Auth. And could lead to security vulnerabilities.
138
138
  */
139
139
  disableOriginCheck?: boolean | undefined;
140
+ /**
141
+ * Run deferred work, such as sending events to a remote service, after the
142
+ * response is sent. On serverless platforms, pass the platform's hook so
143
+ * the function stays alive until the work finishes.
144
+ *
145
+ * @example
146
+ * // Vercel
147
+ * import { waitUntil } from "@vercel/functions";
148
+ * advanced: { backgroundTasks: { handler: waitUntil } }
149
+ *
150
+ * @example
151
+ * // Cloudflare Workers, with the execution context kept in AsyncLocalStorage
152
+ * advanced: {
153
+ * backgroundTasks: {
154
+ * handler: (promise) => executionContext.getStore()?.waitUntil(promise),
155
+ * },
156
+ * }
157
+ */
158
+ backgroundTasks?: {
159
+ handler: (promise: Promise<unknown>) => void;
160
+ } | undefined;
140
161
  /**
141
162
  * Configure cookies to be cross subdomains
142
163
  */
@@ -882,9 +903,10 @@ export type PayvoAuthOptions = {
882
903
  data: Optional<User & Record<string, any>>;
883
904
  }>;
884
905
  /**
885
- * Hook that is called after a user is updated.
906
+ * Hook that is called after a user is updated. `data` holds the
907
+ * fields that were written, after every `before` hook ran.
886
908
  */
887
- after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
909
+ after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext, data?: Partial<User> & Record<string, unknown>) => Promise<void>;
888
910
  };
889
911
  delete?: {
890
912
  /**
@@ -929,9 +951,10 @@ export type PayvoAuthOptions = {
929
951
  data: Optional<Session & Record<string, any>>;
930
952
  }>;
931
953
  /**
932
- * Hook that is called after a session is updated.
954
+ * Hook that is called after a session is updated. `data` holds the
955
+ * fields that were written, after every `before` hook ran.
933
956
  */
934
- after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
957
+ after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext, data?: Partial<Session> & Record<string, unknown>) => Promise<void>;
935
958
  };
936
959
  delete?: {
937
960
  /**
@@ -976,9 +999,10 @@ export type PayvoAuthOptions = {
976
999
  data: Optional<Account & Record<string, any>>;
977
1000
  }>;
978
1001
  /**
979
- * Hook that is called after a account is updated.
1002
+ * Hook that is called after a account is updated. `data` holds the
1003
+ * fields that were written, after every `before` hook ran.
980
1004
  */
981
- after?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1005
+ after?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext, data?: Partial<Account> & Record<string, unknown>) => Promise<void>;
982
1006
  };
983
1007
  delete?: {
984
1008
  /**
@@ -1020,9 +1044,11 @@ export type PayvoAuthOptions = {
1020
1044
  data: Optional<Verification & Record<string, any>>;
1021
1045
  }>;
1022
1046
  /**
1023
- * Hook that is called after a verification is updated.
1047
+ * Hook that is called after a verification is updated. `data`
1048
+ * holds the fields that were written, after every `before` hook
1049
+ * ran.
1024
1050
  */
1025
- after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1051
+ after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext, data?: Partial<Verification> & Record<string, unknown>) => Promise<void>;
1026
1052
  };
1027
1053
  delete?: {
1028
1054
  /**
@@ -1,3 +1,3 @@
1
- import { t as defineErrorCodes } from "../utils-CTOwq_Nj.mjs";
1
+ import { t as defineErrorCodes } from "../utils-BFQCAfNW.mjs";
2
2
 
3
3
  export { defineErrorCodes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gatwech/core",
3
- "version": "1.0.0-beta.19",
3
+ "version": "1.0.0-beta.21",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "publishConfig": {
File without changes
File without changes