authhero 1.3.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37513,73 +37513,25 @@ export declare class HttpSamlSigner implements SamlSigner {
37513
37513
  constructor(signUrl: string);
37514
37514
  signSAML(xmlContent: string, privateKey: string, publicCert: string): Promise<string>;
37515
37515
  }
37516
- /**
37517
- * Context passed to all entity hooks
37518
- */
37516
+ /** Context passed to entity hooks */
37519
37517
  export interface EntityHookContext {
37520
- /** The tenant where the operation occurred */
37521
37518
  tenantId: string;
37522
- /** Data adapters for the current tenant */
37523
37519
  adapters: DataAdapters;
37524
37520
  }
37525
- /**
37526
- * CRUD hooks for any entity type.
37527
- *
37528
- * Use these hooks to implement cross-tenant synchronization,
37529
- * audit logging, webhooks, or any other side effects.
37530
- *
37531
- * @example
37532
- * ```typescript
37533
- * const roleHooks: EntityHooks<Role, RoleInsert> = {
37534
- * afterCreate: async (ctx, role) => {
37535
- * // Propagate to other tenants
37536
- * await syncToChildTenants(ctx, role);
37537
- * },
37538
- * afterUpdate: async (ctx, id, role) => {
37539
- * // Log the update
37540
- * await auditLog('role_updated', { id, tenantId: ctx.tenantId });
37541
- * },
37542
- * };
37543
- * ```
37544
- */
37521
+ /** CRUD hooks for entity operations */
37545
37522
  export interface EntityHooks<TEntity, TInsert, TUpdate = Partial<TInsert>> {
37546
- /** Called before an entity is created */
37547
37523
  beforeCreate?: (ctx: EntityHookContext, data: TInsert) => Promise<TInsert>;
37548
- /** Called after an entity is created */
37549
37524
  afterCreate?: (ctx: EntityHookContext, entity: TEntity) => Promise<void>;
37550
- /** Called before an entity is updated */
37551
37525
  beforeUpdate?: (ctx: EntityHookContext, id: string, data: TUpdate) => Promise<TUpdate>;
37552
- /** Called after an entity is updated */
37553
37526
  afterUpdate?: (ctx: EntityHookContext, id: string, entity: TEntity) => Promise<void>;
37554
- /** Called before an entity is deleted */
37555
37527
  beforeDelete?: (ctx: EntityHookContext, id: string) => Promise<void>;
37556
- /** Called after an entity is deleted */
37557
37528
  afterDelete?: (ctx: EntityHookContext, id: string) => Promise<void>;
37558
37529
  }
37559
- /**
37560
- * Hooks for role permission assignment operations.
37561
- *
37562
- * Role permissions use assign/remove operations rather than typical CRUD,
37563
- * so they have a specialized hook interface.
37564
- *
37565
- * @example
37566
- * ```typescript
37567
- * const rolePermissionHooks: RolePermissionHooks = {
37568
- * afterAssign: async (ctx, roleId, permissions) => {
37569
- * // Sync permissions to child tenants
37570
- * await syncPermissionsToChildTenants(ctx, roleId, permissions);
37571
- * },
37572
- * };
37573
- * ```
37574
- */
37530
+ /** Hooks for role permission assign/remove operations */
37575
37531
  export interface RolePermissionHooks {
37576
- /** Called before permissions are assigned to a role */
37577
37532
  beforeAssign?: (ctx: EntityHookContext, roleId: string, permissions: RolePermissionInsert[]) => Promise<RolePermissionInsert[]>;
37578
- /** Called after permissions are assigned to a role */
37579
37533
  afterAssign?: (ctx: EntityHookContext, roleId: string, permissions: RolePermissionInsert[]) => Promise<void>;
37580
- /** Called before permissions are removed from a role */
37581
37534
  beforeRemove?: (ctx: EntityHookContext, roleId: string, permissions: Pick<RolePermissionInsert, "resource_server_identifier" | "permission_name">[]) => Promise<Pick<RolePermissionInsert, "resource_server_identifier" | "permission_name">[]>;
37582
- /** Called after permissions are removed from a role */
37583
37535
  afterRemove?: (ctx: EntityHookContext, roleId: string, permissions: Pick<RolePermissionInsert, "resource_server_identifier" | "permission_name">[]) => Promise<void>;
37584
37536
  }
37585
37537
  export type Transaction = {
@@ -37596,7 +37548,7 @@ export type Transaction = {
37596
37548
  };
37597
37549
  export type HookRequest = {
37598
37550
  asn?: string;
37599
- body?: Record<string, any>;
37551
+ body?: Record<string, unknown>;
37600
37552
  geoip?: {
37601
37553
  cityName?: string;
37602
37554
  continentCode?: string;
@@ -37639,13 +37591,13 @@ export type HookEvent = {
37639
37591
  id: string;
37640
37592
  name: string;
37641
37593
  strategy: string;
37642
- metadata?: Record<string, any>;
37594
+ metadata?: Record<string, unknown>;
37643
37595
  };
37644
37596
  organization?: {
37645
37597
  id: string;
37646
37598
  name: string;
37647
37599
  display_name: string;
37648
- metadata?: Record<string, any>;
37600
+ metadata?: Record<string, unknown>;
37649
37601
  };
37650
37602
  resource_server?: {
37651
37603
  identifier: string;
@@ -37761,8 +37713,20 @@ export type OnExecuteValidateRegistrationUsername = (event: Omit<HookEvent, "use
37761
37713
  connection: string;
37762
37714
  };
37763
37715
  }, api: OnExecuteValidateRegistrationUsernameAPI) => Promise<void>;
37764
- export type OnExecuteValidateSignupEmail = OnExecuteValidateRegistrationUsername;
37765
- export type OnExecuteValidateSignupEmailAPI = OnExecuteValidateRegistrationUsernameAPI;
37716
+ export type UserInfoEvent = {
37717
+ ctx: Context<{
37718
+ Bindings: Bindings;
37719
+ Variables: Variables;
37720
+ }>;
37721
+ user: User;
37722
+ tenant_id: string;
37723
+ scopes: string[];
37724
+ };
37725
+ export type OnFetchUserInfoAPI = {
37726
+ setCustomClaim: (claim: string, value: unknown) => void;
37727
+ };
37728
+ /** Called when /userinfo endpoint is accessed */
37729
+ export type OnFetchUserInfo = (event: UserInfoEvent, api: OnFetchUserInfoAPI) => Promise<void>;
37766
37730
  /**
37767
37731
  * Entity hooks configuration for CRUD operations.
37768
37732
  *
@@ -37805,6 +37769,11 @@ export interface AuthHeroConfig {
37805
37769
  onExecutePostUserRegistration?: OnExecutePostUserRegistration;
37806
37770
  onExecutePreUserUpdate?: OnExecutePreUserUpdate;
37807
37771
  onExecutePostLogin?: OnExecutePostLogin;
37772
+ /**
37773
+ * Called when the /userinfo endpoint is accessed.
37774
+ * Use this to add custom claims to the userinfo response.
37775
+ */
37776
+ onFetchUserInfo?: OnFetchUserInfo;
37808
37777
  };
37809
37778
  /**
37810
37779
  * Entity CRUD hooks for when resources are created/updated/deleted.
@@ -37906,8 +37875,9 @@ export type Bindings = {
37906
37875
  onExecutePostLogin?: OnExecutePostLogin;
37907
37876
  onExecutePreUserDeletion?: OnExecutePreUserDeletion;
37908
37877
  onExecutePostUserDeletion?: OnExecutePostUserDeletion;
37909
- onExecuteValidateSignupEmail?: OnExecuteValidateSignupEmail;
37910
37878
  onExecuteValidateRegistrationUsername?: OnExecuteValidateRegistrationUsername;
37879
+ /** Called when /userinfo endpoint is accessed to add custom claims */
37880
+ onFetchUserInfo?: OnFetchUserInfo;
37911
37881
  };
37912
37882
  /**
37913
37883
  * Entity CRUD hooks for when resources are created/updated/deleted.
package/dist/authhero.mjs CHANGED
@@ -7973,7 +7973,7 @@ async function by(t, e, n, r, i = "email") {
7973
7973
  reason: "Public signup is disabled for this client"
7974
7974
  };
7975
7975
  }
7976
- if (t.env.hooks?.onExecuteValidateSignupEmail) {
7976
+ if (t.env.hooks?.onExecuteValidateRegistrationUsername) {
7977
7977
  const a = {
7978
7978
  method: t.req.method,
7979
7979
  ip: t.var.ip || t.get("ip") || "",
@@ -7982,7 +7982,7 @@ async function by(t, e, n, r, i = "email") {
7982
7982
  };
7983
7983
  let c = !1, l;
7984
7984
  try {
7985
- if (await t.env.hooks.onExecuteValidateSignupEmail(
7985
+ if (await t.env.hooks.onExecuteValidateRegistrationUsername(
7986
7986
  {
7987
7987
  ctx: t,
7988
7988
  client: e,
@@ -25803,7 +25803,27 @@ const P$ = new ae().openapi(
25803
25803
  );
25804
25804
  if (!e)
25805
25805
  throw new j(404, { message: "User not found" });
25806
- return t.json($m.parse({ ...e, sub: e.user_id }));
25806
+ const n = $m.parse({
25807
+ ...e,
25808
+ sub: e.user_id
25809
+ }), r = t.env.hooks?.onFetchUserInfo;
25810
+ if (r) {
25811
+ const i = {};
25812
+ return await r(
25813
+ {
25814
+ ctx: t,
25815
+ user: e,
25816
+ tenant_id: t.var.user.tenant_id,
25817
+ scopes: t.var.scope?.split(" ") || []
25818
+ },
25819
+ {
25820
+ setCustomClaim: (s, a) => {
25821
+ i[s] = a;
25822
+ }
25823
+ }
25824
+ ), t.json({ ...n, ...i });
25825
+ }
25826
+ return t.json(n);
25807
25827
  }
25808
25828
  ), L$ = new ae().openapi(
25809
25829
  P({