@thunderid/nextjs 1.0.8 → 1.2.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.
Files changed (81) hide show
  1. package/dist/ThunderIDNextClient.d.ts +16 -0
  2. package/dist/ThunderIDNextClient.d.ts.map +1 -1
  3. package/dist/ThunderIDNextClient.js +28 -2
  4. package/dist/ThunderIDNextClient.js.map +1 -1
  5. package/dist/cjs/ThunderIDNextClient.cjs +27 -1
  6. package/dist/cjs/ThunderIDNextClient.cjs.map +1 -1
  7. package/dist/cjs/client/components/presentation/ChangeCredential/ChangeCredential.cjs +104 -0
  8. package/dist/cjs/client/components/presentation/ChangeCredential/ChangeCredential.cjs.map +1 -0
  9. package/dist/cjs/client/components/presentation/UserDropdown/UserDropdown.cjs +8 -4
  10. package/dist/cjs/client/components/presentation/UserDropdown/UserDropdown.cjs.map +1 -1
  11. package/dist/cjs/client/contexts/ThunderID/ThunderIDProvider.cjs +2 -3
  12. package/dist/cjs/client/contexts/ThunderID/ThunderIDProvider.cjs.map +1 -1
  13. package/dist/cjs/client/index.cjs +1 -0
  14. package/dist/cjs/index.cjs +4 -0
  15. package/dist/cjs/server/actions/handleOAuthCallbackAction.cjs +2 -4
  16. package/dist/cjs/server/actions/handleOAuthCallbackAction.cjs.map +1 -1
  17. package/dist/cjs/server/actions/signInAction.cjs +1 -1
  18. package/dist/cjs/server/actions/signInAction.cjs.map +1 -1
  19. package/dist/cjs/server/actions/updateUserCredentialsAction.cjs +41 -0
  20. package/dist/cjs/server/actions/updateUserCredentialsAction.cjs.map +1 -0
  21. package/dist/cjs/server/backchannelLogout.cjs +92 -0
  22. package/dist/cjs/server/backchannelLogout.cjs.map +1 -0
  23. package/dist/cjs/server/index.cjs +2 -0
  24. package/dist/cjs/server/proxy/thunderIDProxy.cjs +4 -1
  25. package/dist/cjs/server/proxy/thunderIDProxy.cjs.map +1 -1
  26. package/dist/cjs/utils/SessionManager.cjs +17 -1
  27. package/dist/cjs/utils/SessionManager.cjs.map +1 -1
  28. package/dist/cjs/utils/handleRefreshToken.cjs +5 -2
  29. package/dist/cjs/utils/handleRefreshToken.cjs.map +1 -1
  30. package/dist/cjs/utils/loggedOutSessions.cjs +32 -0
  31. package/dist/cjs/utils/loggedOutSessions.cjs.map +1 -0
  32. package/dist/client/components/presentation/ChangeCredential/ChangeCredential.d.ts +45 -0
  33. package/dist/client/components/presentation/ChangeCredential/ChangeCredential.d.ts.map +1 -0
  34. package/dist/client/components/presentation/ChangeCredential/ChangeCredential.js +99 -0
  35. package/dist/client/components/presentation/ChangeCredential/ChangeCredential.js.map +1 -0
  36. package/dist/client/components/presentation/UserDropdown/UserDropdown.d.ts +12 -0
  37. package/dist/client/components/presentation/UserDropdown/UserDropdown.d.ts.map +1 -1
  38. package/dist/client/components/presentation/UserDropdown/UserDropdown.js +8 -4
  39. package/dist/client/components/presentation/UserDropdown/UserDropdown.js.map +1 -1
  40. package/dist/client/contexts/ThunderID/ThunderIDProvider.d.ts +1 -1
  41. package/dist/client/contexts/ThunderID/ThunderIDProvider.d.ts.map +1 -1
  42. package/dist/client/contexts/ThunderID/ThunderIDProvider.js +3 -4
  43. package/dist/client/contexts/ThunderID/ThunderIDProvider.js.map +1 -1
  44. package/dist/client/index.d.ts +2 -0
  45. package/dist/client/index.d.ts.map +1 -1
  46. package/dist/client/index.js +1 -0
  47. package/dist/index.js +3 -1
  48. package/dist/server/actions/handleOAuthCallbackAction.d.ts +1 -2
  49. package/dist/server/actions/handleOAuthCallbackAction.d.ts.map +1 -1
  50. package/dist/server/actions/handleOAuthCallbackAction.js +2 -4
  51. package/dist/server/actions/handleOAuthCallbackAction.js.map +1 -1
  52. package/dist/server/actions/signInAction.d.ts.map +1 -1
  53. package/dist/server/actions/signInAction.js +1 -1
  54. package/dist/server/actions/signInAction.js.map +1 -1
  55. package/dist/server/actions/updateUserCredentialsAction.d.ts +16 -0
  56. package/dist/server/actions/updateUserCredentialsAction.d.ts.map +1 -0
  57. package/dist/server/actions/updateUserCredentialsAction.js +39 -0
  58. package/dist/server/actions/updateUserCredentialsAction.js.map +1 -0
  59. package/dist/server/backchannelLogout.d.ts +40 -0
  60. package/dist/server/backchannelLogout.d.ts.map +1 -0
  61. package/dist/server/backchannelLogout.js +90 -0
  62. package/dist/server/backchannelLogout.js.map +1 -0
  63. package/dist/server/index.d.ts +2 -0
  64. package/dist/server/index.d.ts.map +1 -1
  65. package/dist/server/index.js +2 -1
  66. package/dist/server/proxy/thunderIDProxy.d.ts +12 -1
  67. package/dist/server/proxy/thunderIDProxy.d.ts.map +1 -1
  68. package/dist/server/proxy/thunderIDProxy.js +4 -1
  69. package/dist/server/proxy/thunderIDProxy.js.map +1 -1
  70. package/dist/utils/SessionManager.d.ts +13 -1
  71. package/dist/utils/SessionManager.d.ts.map +1 -1
  72. package/dist/utils/SessionManager.js +17 -1
  73. package/dist/utils/SessionManager.js.map +1 -1
  74. package/dist/utils/handleRefreshToken.d.ts.map +1 -1
  75. package/dist/utils/handleRefreshToken.js +5 -2
  76. package/dist/utils/handleRefreshToken.js.map +1 -1
  77. package/dist/utils/loggedOutSessions.d.ts +12 -0
  78. package/dist/utils/loggedOutSessions.d.ts.map +1 -0
  79. package/dist/utils/loggedOutSessions.js +29 -0
  80. package/dist/utils/loggedOutSessions.js.map +1 -0
  81. package/package.json +4 -4
@@ -10,6 +10,22 @@ declare class ThunderIDNextClient<T extends ThunderIDNextConfig = ThunderIDNextC
10
10
  getUserProfile(userId?: string): Promise<UserProfile>;
11
11
  getUserSchema(userId?: string): Promise<Record<string, AttributeSchema> | null>;
12
12
  updateUserProfile(payload: any, userId?: string): Promise<User>;
13
+ /**
14
+ * Updates one or more of the signed-in user's credentials (e.g. `password`, or any other
15
+ * attribute the user type schema declares `credential: true`).
16
+ *
17
+ * Not part of {@link ThunderIDJavaScriptClient}'s base surface — unlike `updateUserProfile`,
18
+ * no other SDK routes credential updates through a client method (React/Vue's
19
+ * `ChangeCredential` call the core `updateMeCredentials` function directly), so this is a
20
+ * Next.js-specific addition rather than an override. Kept here anyway so this SDK's own
21
+ * server actions have one consistent way to reach every `/users/me/*` operation.
22
+ *
23
+ * Deliberately does not catch and rewrap errors the way `updateUserProfile` does: the caller
24
+ * (`updateUserCredentialsAction`) needs the real `ThunderIDAPIError` instance, status code
25
+ * included, to map a failure onto the right form field before it crosses the server action
26
+ * boundary back to the client.
27
+ */
28
+ updateUserCredentials(payload: Record<string, string>, userId?: string): Promise<void>;
13
29
  isLoading(): boolean;
14
30
  isSignedIn(sessionId?: string): Promise<boolean>;
15
31
  exchangeToken(config: TokenExchangeRequestConfig, sessionId?: string): Promise<TokenResponse | Response>;
@@ -1 +1 @@
1
- {"version":3,"file":"ThunderIDNextClient.d.ts","sourceRoot":"","sources":["../src/ThunderIDNextClient.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,mBAAmB,EAEnB,eAAe,EAGf,iCAAiC,EACjC,OAAO,EACP,aAAa,EACb,aAAa,EACb,OAAO,EACP,0BAA0B,EAC1B,aAAa,EACb,IAAI,EACJ,WAAW,EAQZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAC,mBAAmB,EAAC,MAAM,iBAAiB,CAAC;AAKpD,cAAM,mBAAmB,CAAC,CAAC,SAAS,mBAAmB,GAAG,mBAAmB,CAAE,SAAQ,mBAAmB,CAAC,CAAC,CAAC;IACpG,aAAa,UAAS;;YAMf,iBAAiB;IAehB,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IA0C1D,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAclD,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBvC,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IA2B9D,aAAa,CAAC,MAAM,C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1,7 @@
1
1
  import getClientOrigin_default from "./server/actions/getClientOrigin.js";
2
2
  import getSessionId_default from "./server/actions/getSessionId.js";
3
3
  import decorateConfigWithNextEnv_default from "./utils/decorateConfigWithNextEnv.js";
4
- import { ThunderIDNodeClient, ThunderIDRuntimeError, executeEmbeddedSignInFlow, extractUserClaimsFromIdToken, generateFlattenedUserProfile, getUsersMe, getUsersMeMeta, resolveResourceEndpoint, updateMeProfile } from "@thunderid/node";
4
+ import { ThunderIDNodeClient, ThunderIDRuntimeError, executeEmbeddedSignInFlow, extractUserClaimsFromIdToken, generateFlattenedUserProfile, getUsersMe, getUsersMeMeta, resolveResourceEndpoint, updateMeCredentials, updateMeProfile } from "@thunderid/node";
5
5
 
6
6
  //#region src/ThunderIDNextClient.ts
7
7
  var ThunderIDNextClient = class extends ThunderIDNodeClient {
@@ -107,6 +107,32 @@ var ThunderIDNextClient = class extends ThunderIDNodeClient {
107
107
  throw new ThunderIDRuntimeError(`Failed to update user profile: ${error instanceof Error ? error.message : String(error)}`, "ThunderIDNextClient-UpdateProfileError-001", "react", "An error occurred while updating the user profile. Please check your configuration and network connection.");
108
108
  }
109
109
  }
110
+ /**
111
+ * Updates one or more of the signed-in user's credentials (e.g. `password`, or any other
112
+ * attribute the user type schema declares `credential: true`).
113
+ *
114
+ * Not part of {@link ThunderIDJavaScriptClient}'s base surface — unlike `updateUserProfile`,
115
+ * no other SDK routes credential updates through a client method (React/Vue's
116
+ * `ChangeCredential` call the core `updateMeCredentials` function directly), so this is a
117
+ * Next.js-specific addition rather than an override. Kept here anyway so this SDK's own
118
+ * server actions have one consistent way to reach every `/users/me/*` operation.
119
+ *
120
+ * Deliberately does not catch and rewrap errors the way `updateUserProfile` does: the caller
121
+ * (`updateUserCredentialsAction`) needs the real `ThunderIDAPIError` instance, status code
122
+ * included, to map a failure onto the right form field before it crosses the server action
123
+ * boundary back to the client.
124
+ */
125
+ async updateUserCredentials(payload, userId) {
126
+ await this.ensureInitialized();
127
+ const configData = await this.getStorageManager().getConfigData();
128
+ const baseUrl = configData?.baseUrl;
129
+ await updateMeCredentials({
130
+ baseUrl,
131
+ url: resolveResourceEndpoint("usersMeCredentials", configData),
132
+ headers: { Authorization: `Bearer ${await this.getAccessToken(userId)}` },
133
+ payload
134
+ });
135
+ }
110
136
  isLoading() {
111
137
  return false;
112
138
  }
@@ -141,7 +167,7 @@ var ThunderIDNextClient = class extends ThunderIDNodeClient {
141
167
  url: resolveResourceEndpoint("flowExecute", configData, arg2?.url)
142
168
  });
143
169
  }
144
- return super.signIn(arg4, arg3, arg1?.code, arg1?.session_state, arg1?.state, arg1);
170
+ return super.signIn(arg4, arg3, arg1?.code, arg1?.state, arg1);
145
171
  }
146
172
  async signOut(...args) {
147
173
  if (args[1] && typeof args[1] !== "string") throw new Error("The second argument must be a string.");
@@ -1 +1 @@
1
- {"version":3,"file":"ThunderIDNextClient.js","names":["decorateConfigWithNextEnv","origin: string","getClientOrigin","initialized: boolean","resolvedSessionId: string","getSessionId","configData: AuthClientConfig<T>","baseUrl: string | undefined","profile: User","token: string | undefined","arg1: any","arg2: any","arg3: any","arg4: any","configData: ThunderIDNextConfig","afterSignOutUrl: string","message: string"],"sources":["../src/ThunderIDNextClient.ts"],"sourcesContent":["// Copyright 2025 The ThunderID Authors\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n ThunderIDNodeClient,\n ThunderIDRuntimeError,\n AttributeSchema,\n AuthClientConfig,\n EmbeddedSignInFlowResponse,\n ExtendedAuthorizeRequestUrlParams,\n IdToken,\n SignInOptions,\n SignUpOptions,\n Storage,\n TokenExchangeRequestConfig,\n TokenResponse,\n User,\n UserProfile,\n executeEmbeddedSignInFlow,\n extractUserClaimsFromIdToken,\n generateFlattenedUserProfile,\n getUsersMe,\n getUsersMeMeta,\n updateMeProfile,\n resolveResourceEndpoint,\n} from '@thunderid/node';\nimport {ThunderIDNextConfig} from './models/config';\nimport getClientOrigin from './server/actions/getClientOrigin';\nimport getSessionId from './server/actions/getSessionId';\nimport decorateConfigWithNextEnv from './utils/decorateConfigWithNextEnv';\n\nclass ThunderIDNextClient<T extends ThunderIDNextConfig = ThunderIDNextConfig> extends ThunderIDNodeClient<T> {\n public isInitialized = false;\n\n public constructor() {\n super();\n }\n\n private async ensureInitialized(): Promise<void> {\n if (!this.isInitialized) {\n // Server actions may run in a module context that hasn't been through\n // ThunderIDServerProvider (e.g. a different worker). Try to initialize\n // from environment variables before giving up.\n await this.initialize({} as T);\n }\n\n if (!this.isInitialized) {\n throw new Error(\n '[ThunderIDNextClient] Client is not initialized. Make sure you have wrapped your app with ThunderIDProvider and provided the required configuration (baseUrl, clientId, etc.).',\n );\n }\n }\n\n override async initialize(config: T, storage?: Storage): Promise<boolean> {\n if (this.isInitialized) {\n return Promise.resolve(true);\n }\n\n const {\n baseUrl,\n organizationHandle,\n clientId,\n clientSecret,\n flowSecret,\n signInUrl,\n afterSignInUrl,\n afterSignOutUrl,\n signUpUrl,\n ...rest\n } = decorateConfigWithNextEnv(config);\n\n const origin: string = await getClientOrigin();\n\n const initialized: boolean = await super.initialize(\n {\n ...rest,\n afterSignInUrl: afterSignInUrl ?? origin,\n afterSignOutUrl: afterSignOutUrl ?? origin,\n baseUrl,\n clientId,\n clientSecret,\n enablePKCE: (rest as any).enablePKCE ?? true,\n flowSecret,\n organizationHandle,\n signInUrl,\n signUpUrl,\n } as any,\n storage,\n );\n\n this.isInitialized = initialized;\n\n return initialized;\n }\n\n override async reInitialize(config: Partial<T>): Promise<boolean> {\n try {\n await super.reInitialize(config);\n return true;\n } catch (error) {\n throw new ThunderIDRuntimeError(\n `Failed to re-initialize the client: ${error instanceof Error ? error.message : String(error)}`,\n 'ThunderIDNextClient-reInitialize-RuntimeError-001',\n 'nextjs',\n 'An error occurred while re-initializing the client. Please check your configuration and network connection.',\n );\n }\n }\n\n override async getUser(userId?: string): Promise<User> {\n await this.ensureInitialized();\n const resolvedSessionId: string = userId || (await getSessionId())!;\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n const profile: User = await getUsersMe({\n baseUrl,\n url: resolveResourceEndpoint('usersMe', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n });\n\n return profile;\n } catch (error) {\n return await super.getUser(resolvedSessionId);\n }\n }\n\n override async getUserProfile(userId?: string): Promise<UserProfile> {\n await this.ensureInitialized();\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n const profile: User = await getUsersMe({\n baseUrl,\n url: resolveResourceEndpoint('usersMe', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n });\n\n return {\n flattenedProfile: generateFlattenedUserProfile(profile),\n profile,\n };\n } catch (error) {\n return {\n flattenedProfile: extractUserClaimsFromIdToken(await super.getDecodedIdToken(userId)),\n profile: extractUserClaimsFromIdToken(await super.getDecodedIdToken(userId)),\n };\n }\n }\n\n async getUserSchema(userId?: string): Promise<Record<string, AttributeSchema> | null> {\n await this.ensureInitialized();\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n const {schema} = await getUsersMeMeta({\n baseUrl,\n url: resolveResourceEndpoint('usersMeMeta', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n });\n\n return schema ?? null;\n } catch (error) {\n return null;\n }\n }\n\n override async updateUserProfile(payload: any, userId?: string): Promise<User> {\n await this.ensureInitialized();\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n return updateMeProfile({\n baseUrl,\n url: resolveResourceEndpoint('usersMe', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n payload: payload?.payload ?? payload,\n });\n } catch (error) {\n throw new ThunderIDRuntimeError(\n `Failed to update user profile: ${error instanceof Error ? error.message : String(error)}`,\n 'ThunderIDNextClient-UpdateProfileError-001',\n 'react',\n 'An error occurred while updating the user profile. Please check your configuration and network connection.',\n );\n }\n }\n\n override isLoading(): boolean {\n return false;\n }\n\n override isSignedIn(sessionId?: string): Promise<boolean> {\n return super.isSignedIn(sessionId);\n }\n\n override exchangeToken(config: TokenExchangeRequestConfig, sessionId?: string): Promise<TokenResponse | Response> {\n return super.exchangeToken(config, sessionId) as unknown as Promise<TokenResponse | Response>;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n override async getAccessToken(_sessionId?: string): Promise<string> {\n const {default: getAccessToken} = await import('./server/actions/getAccessToken');\n const token: string | undefined = await getAccessToken();\n\n if (typeof token !== 'string' || !token) {\n throw new ThunderIDRuntimeError(\n 'Failed to get access token.',\n 'ThunderIDNextClient-getAccessToken-RuntimeError-003',\n 'nextjs',\n 'An error occurred while obtaining the access token. Please check your configuration and network connection.',\n );\n }\n\n return token;\n }\n\n override async getDecodedIdToken(sessionId?: string, idToken?: string): Promise<IdToken> {\n await this.ensureInitialized();\n return await super.getDecodedIdToken(sessionId, idToken);\n }\n\n override async signIn(...args: any[]): Promise<any> {\n const arg1: any = args[0];\n const arg2: any = args[1];\n const arg3: any = args[2];\n const arg4: any = args[3];\n\n // An embedded sign-in flow payload initiates or continues a `POST /flow/execute` step\n // (identified by `applicationId` for a new flow or `executionId` to continue one). This is\n // distinct from the OAuth authorization_code exchange handled by `super.signIn` below, which\n // is used once the embedded flow completes and returns an authorization code.\n const isEmbeddedFlowPayload: boolean =\n typeof arg1 === 'object' && arg1 !== null && ('executionId' in arg1 || 'applicationId' in arg1);\n\n if (isEmbeddedFlowPayload) {\n await this.ensureInitialized();\n\n // Typed as the Next config rather than `AuthClientConfig<T>` because the server-only\n // `flowSecret` lives on `ThunderIDNodeConfig`, which the generic base config does not expose.\n const configData: ThunderIDNextConfig = (await this.getStorageManager().getConfigData()) as ThunderIDNextConfig;\n\n return executeEmbeddedSignInFlow({\n baseUrl: configData?.baseUrl,\n flowSecret: arg2?.flowSecret ?? configData?.flowSecret,\n payload: arg1,\n url: resolveResourceEndpoint('flowExecute', configData, arg2?.url),\n }) as unknown as Promise<EmbeddedSignInFlowResponse>;\n }\n\n return super.signIn(arg4, arg3, arg1?.code, arg1?.session_state, arg1?.state, arg1) as unknown as Promise<User>;\n }\n\n override async signOut(...args: any[]): Promise<string> {\n if (args[1] && typeof args[1] !== 'string') {\n throw new Error('The second argument must be a string.');\n }\n\n const config: T = this.getConfiguration();\n const afterSignOutUrl: string = config?.afterSignOutUrl || '/';\n\n const resolvedSessionId: string = args[1] || (await getSessionId())!;\n\n try {\n await (super.signOut as (...a: any[]) => Promise<string>)(resolvedSessionId);\n } catch (error) {\n const message: string = error instanceof Error ? error.message : String(error);\n\n if (\n !message.includes('end_session_endpoint') &&\n !message.includes('sign-out endpoint') &&\n !message.includes('Sign-out endpoint') &&\n !message.includes('Sign-out redirect URL')\n ) {\n throw error;\n }\n }\n\n return afterSignOutUrl;\n }\n\n override async signUp(_options?: SignUpOptions): Promise<void> {\n throw new ThunderIDRuntimeError(\n 'Not implemented',\n 'ThunderIDNextClient-ValidationError-002',\n 'nextjs',\n 'The signUp method is not implemented in the Next.js client.',\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n override signInSilently(_options?: SignInOptions): Promise<User | boolean> {\n throw new ThunderIDRuntimeError(\n 'Not implemented',\n 'ThunderIDNextClient-signInSilently-NotImplementedError-001',\n 'nextjs',\n 'The signInSilently method is not implemented in the Next.js client.',\n );\n }\n\n public async getAuthorizeRequestUrl(\n customParams: ExtendedAuthorizeRequestUrlParams,\n userId?: string,\n ): Promise<string> {\n await this.ensureInitialized();\n return this.getSignInUrl(customParams, userId);\n }\n\n public override getStorageManager(): any {\n return super.getStorageManager();\n }\n\n public override async clearSession(): Promise<void> {\n throw new ThunderIDRuntimeError(\n 'Not implemented',\n 'ThunderIDNextClient-clearSession-NotImplementedError-001',\n 'nextjs',\n 'The clearSession method is not implemented in the Next.js client.',\n );\n }\n\n override async setSession(sessionData: Record<string, unknown>, sessionId?: string): Promise<void> {\n return this.getStorageManager().setSessionData(sessionData, sessionId);\n }\n\n override decodeJwtToken<R = Record<string, unknown>>(token: string): Promise<R> {\n return super.decodeJwtToken<R>(token);\n }\n}\n\nexport default ThunderIDNextClient;\n"],"mappings":";;;;;;AA+BA,IAAM,sBAAN,cAAuF,oBAAuB;CAC5G,AAAO,gBAAgB;CAEvB,AAAO,cAAc;AACnB,SAAO;;CAGT,MAAc,oBAAmC;AAC/C,MAAI,CAAC,KAAK,cAIR,OAAM,KAAK,WAAW,EAAE,CAAM;AAGhC,MAAI,CAAC,KAAK,cACR,OAAM,IAAI,MACR,iLACD;;CAIL,MAAe,WAAW,QAAW,SAAqC;AACxE,MAAI,KAAK,cACP,QAAO,QAAQ,QAAQ,KAAK;EAG9B,MAAM,EACJ,SACA,oBACA,UACA,cACA,YACA,WACA,gBACA,iBACA,UACA,GAAG,SACDA,kCAA0B,OAAO;EAErC,MAAMC,SAAiB,MAAMC,yBAAiB;EAE9C,MAAMC,cAAuB,MAAM,MAAM,WACvC;GACE,GAAG;GACH,gBAAgB,kBAAkB;GAClC,iBAAiB,mBAAmB;GACpC;GACA;GACA;GACA,YAAa,KAAa,cAAc;GACxC;GACA;GACA;GACA;GACD,EACD,QACD;AAED,OAAK,gBAAgB;AAErB,SAAO;;CAGT,MAAe,aAAa,QAAsC;AAChE,MAAI;AACF,SAAM,MAAM,aAAa,OAAO;AAChC,UAAO;WACA,OAAO;AACd,SAAM,IAAI,sBACR,uCAAuC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,IAC7F,qDACA,UACA,8GACD;;;CAIL,MAAe,QAAQ,QAAgC;AACrD,QAAM,KAAK,mBAAmB;EAC9B,MAAMC,oBAA4B,UAAW,MAAMC,sBAAc;AAEjE,MAAI;GACF,MAAMC,aAAkC,MAAM,KAAK,mBAAmB,CAAC,eAAe;GACtF,MAAMC,UAA8B,YA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,OAAO,SAChC,OAAM,IAAI,MAAM,wCAAwC;EAI1D,MAAMC,kBADY,KAAK,kBAAkB,EACD,mBAAmB;EAE3D,MAAMX,oBAA4B,KAAK,MAAO,MAAMC,sBAAc;AAElE,MAAI;AACF,SAAO,MAAM,QAA6C,kBAAkB;WACrE,OAAO;GACd,MAAMW,UAAkB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AAE9E,OACE,CAAC,QAAQ,SAAS,uBAAuB,IACzC,CAAC,QAAQ,SAAS,oBAAoB,IACtC,CAAC,QAAQ,SAAS,oBAAoB,IACtC,CAAC,QAAQ,SAAS,wBAAwB,CAE1C,OAAM;;AAIV,SAAO;;CAGT,MAAe,OAAO,UAAyC;AAC7D,QAAM,IAAI,sBACR,mBACA,2CACA,UACA,8DACD;;CAIH,AAAS,eAAe,UAAmD;AACzE,QAAM,IAAI,sBACR,mBACA,8DACA,UACA,sEACD;;CAGH,MAAa,uBACX,cACA,QACiB;AACjB,QAAM,KAAK,mBAAmB;AAC9B,SAAO,KAAK,aAAa,cAAc,OAAO;;CAGhD,AAAgB,oBAAyB;AACvC,SAAO,MAAM,mBAAmB;;CAGlC,MAAsB,eAA8B;AAClD,QAAM,IAAI,sBACR,mBACA,4DACA,UACA,oEACD;;CAGH,MAAe,WAAW,aAAsC,WAAmC;AACjG,SAAO,KAAK,mBAAmB,CAAC,eAAe,aAAa,UAAU;;CAGxE,AAAS,eAA4C,OAA2B;AAC9E,SAAO,MAAM,eAAkB,MAAM;;;AAIzC,kCAAe"}
1
+ {"version":3,"file":"ThunderIDNextClient.js","names":["decorateConfigWithNextEnv","origin: string","getClientOrigin","initialized: boolean","resolvedSessionId: string","getSessionId","configData: AuthClientConfig<T>","baseUrl: string | undefined","profile: User","token: string | undefined","arg1: any","arg2: any","arg3: any","arg4: any","configData: ThunderIDNextConfig","afterSignOutUrl: string","message: string"],"sources":["../src/ThunderIDNextClient.ts"],"sourcesContent":["// Copyright 2025 The ThunderID Authors\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n ThunderIDNodeClient,\n ThunderIDRuntimeError,\n AttributeSchema,\n AuthClientConfig,\n EmbeddedSignInFlowResponse,\n ExtendedAuthorizeRequestUrlParams,\n IdToken,\n SignInOptions,\n SignUpOptions,\n Storage,\n TokenExchangeRequestConfig,\n TokenResponse,\n User,\n UserProfile,\n executeEmbeddedSignInFlow,\n extractUserClaimsFromIdToken,\n generateFlattenedUserProfile,\n getUsersMe,\n getUsersMeMeta,\n updateMeCredentials,\n updateMeProfile,\n resolveResourceEndpoint,\n} from '@thunderid/node';\nimport {ThunderIDNextConfig} from './models/config';\nimport getClientOrigin from './server/actions/getClientOrigin';\nimport getSessionId from './server/actions/getSessionId';\nimport decorateConfigWithNextEnv from './utils/decorateConfigWithNextEnv';\n\nclass ThunderIDNextClient<T extends ThunderIDNextConfig = ThunderIDNextConfig> extends ThunderIDNodeClient<T> {\n public isInitialized = false;\n\n public constructor() {\n super();\n }\n\n private async ensureInitialized(): Promise<void> {\n if (!this.isInitialized) {\n // Server actions may run in a module context that hasn't been through\n // ThunderIDServerProvider (e.g. a different worker). Try to initialize\n // from environment variables before giving up.\n await this.initialize({} as T);\n }\n\n if (!this.isInitialized) {\n throw new Error(\n '[ThunderIDNextClient] Client is not initialized. Make sure you have wrapped your app with ThunderIDProvider and provided the required configuration (baseUrl, clientId, etc.).',\n );\n }\n }\n\n override async initialize(config: T, storage?: Storage): Promise<boolean> {\n if (this.isInitialized) {\n return Promise.resolve(true);\n }\n\n const {\n baseUrl,\n organizationHandle,\n clientId,\n clientSecret,\n flowSecret,\n signInUrl,\n afterSignInUrl,\n afterSignOutUrl,\n signUpUrl,\n ...rest\n } = decorateConfigWithNextEnv(config);\n\n const origin: string = await getClientOrigin();\n\n const initialized: boolean = await super.initialize(\n {\n ...rest,\n afterSignInUrl: afterSignInUrl ?? origin,\n afterSignOutUrl: afterSignOutUrl ?? origin,\n baseUrl,\n clientId,\n clientSecret,\n enablePKCE: (rest as any).enablePKCE ?? true,\n flowSecret,\n organizationHandle,\n signInUrl,\n signUpUrl,\n } as any,\n storage,\n );\n\n this.isInitialized = initialized;\n\n return initialized;\n }\n\n override async reInitialize(config: Partial<T>): Promise<boolean> {\n try {\n await super.reInitialize(config);\n return true;\n } catch (error) {\n throw new ThunderIDRuntimeError(\n `Failed to re-initialize the client: ${error instanceof Error ? error.message : String(error)}`,\n 'ThunderIDNextClient-reInitialize-RuntimeError-001',\n 'nextjs',\n 'An error occurred while re-initializing the client. Please check your configuration and network connection.',\n );\n }\n }\n\n override async getUser(userId?: string): Promise<User> {\n await this.ensureInitialized();\n const resolvedSessionId: string = userId || (await getSessionId())!;\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n const profile: User = await getUsersMe({\n baseUrl,\n url: resolveResourceEndpoint('usersMe', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n });\n\n return profile;\n } catch (error) {\n return await super.getUser(resolvedSessionId);\n }\n }\n\n override async getUserProfile(userId?: string): Promise<UserProfile> {\n await this.ensureInitialized();\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n const profile: User = await getUsersMe({\n baseUrl,\n url: resolveResourceEndpoint('usersMe', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n });\n\n return {\n flattenedProfile: generateFlattenedUserProfile(profile),\n profile,\n };\n } catch (error) {\n return {\n flattenedProfile: extractUserClaimsFromIdToken(await super.getDecodedIdToken(userId)),\n profile: extractUserClaimsFromIdToken(await super.getDecodedIdToken(userId)),\n };\n }\n }\n\n async getUserSchema(userId?: string): Promise<Record<string, AttributeSchema> | null> {\n await this.ensureInitialized();\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n const {schema} = await getUsersMeMeta({\n baseUrl,\n url: resolveResourceEndpoint('usersMeMeta', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n });\n\n return schema ?? null;\n } catch (error) {\n return null;\n }\n }\n\n override async updateUserProfile(payload: any, userId?: string): Promise<User> {\n await this.ensureInitialized();\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n return updateMeProfile({\n baseUrl,\n url: resolveResourceEndpoint('usersMe', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n payload: payload?.payload ?? payload,\n });\n } catch (error) {\n throw new ThunderIDRuntimeError(\n `Failed to update user profile: ${error instanceof Error ? error.message : String(error)}`,\n 'ThunderIDNextClient-UpdateProfileError-001',\n 'react',\n 'An error occurred while updating the user profile. Please check your configuration and network connection.',\n );\n }\n }\n\n /**\n * Updates one or more of the signed-in user's credentials (e.g. `password`, or any other\n * attribute the user type schema declares `credential: true`).\n *\n * Not part of {@link ThunderIDJavaScriptClient}'s base surface — unlike `updateUserProfile`,\n * no other SDK routes credential updates through a client method (React/Vue's\n * `ChangeCredential` call the core `updateMeCredentials` function directly), so this is a\n * Next.js-specific addition rather than an override. Kept here anyway so this SDK's own\n * server actions have one consistent way to reach every `/users/me/*` operation.\n *\n * Deliberately does not catch and rewrap errors the way `updateUserProfile` does: the caller\n * (`updateUserCredentialsAction`) needs the real `ThunderIDAPIError` instance, status code\n * included, to map a failure onto the right form field before it crosses the server action\n * boundary back to the client.\n */\n override async updateUserCredentials(payload: Record<string, string>, userId?: string): Promise<void> {\n await this.ensureInitialized();\n\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n await updateMeCredentials({\n baseUrl,\n url: resolveResourceEndpoint('usersMeCredentials', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n payload,\n });\n }\n\n override isLoading(): boolean {\n return false;\n }\n\n override isSignedIn(sessionId?: string): Promise<boolean> {\n return super.isSignedIn(sessionId);\n }\n\n override exchangeToken(config: TokenExchangeRequestConfig, sessionId?: string): Promise<TokenResponse | Response> {\n return super.exchangeToken(config, sessionId) as unknown as Promise<TokenResponse | Response>;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n override async getAccessToken(_sessionId?: string): Promise<string> {\n const {default: getAccessToken} = await import('./server/actions/getAccessToken');\n const token: string | undefined = await getAccessToken();\n\n if (typeof token !== 'string' || !token) {\n throw new ThunderIDRuntimeError(\n 'Failed to get access token.',\n 'ThunderIDNextClient-getAccessToken-RuntimeError-003',\n 'nextjs',\n 'An error occurred while obtaining the access token. Please check your configuration and network connection.',\n );\n }\n\n return token;\n }\n\n override async getDecodedIdToken(sessionId?: string, idToken?: string): Promise<IdToken> {\n await this.ensureInitialized();\n return await super.getDecodedIdToken(sessionId, idToken);\n }\n\n override async signIn(...args: any[]): Promise<any> {\n const arg1: any = args[0];\n const arg2: any = args[1];\n const arg3: any = args[2];\n const arg4: any = args[3];\n\n // An embedded sign-in flow payload initiates or continues a `POST /flow/execute` step\n // (identified by `applicationId` for a new flow or `executionId` to continue one). This is\n // distinct from the OAuth authorization_code exchange handled by `super.signIn` below, which\n // is used once the embedded flow completes and returns an authorization code.\n const isEmbeddedFlowPayload: boolean =\n typeof arg1 === 'object' && arg1 !== null && ('executionId' in arg1 || 'applicationId' in arg1);\n\n if (isEmbeddedFlowPayload) {\n await this.ensureInitialized();\n\n // Typed as the Next config rather than `AuthClientConfig<T>` because the server-only\n // `flowSecret` lives on `ThunderIDNodeConfig`, which the generic base config does not expose.\n const configData: ThunderIDNextConfig = (await this.getStorageManager().getConfigData()) as ThunderIDNextConfig;\n\n return executeEmbeddedSignInFlow({\n baseUrl: configData?.baseUrl,\n flowSecret: arg2?.flowSecret ?? configData?.flowSecret,\n payload: arg1,\n url: resolveResourceEndpoint('flowExecute', configData, arg2?.url),\n }) as unknown as Promise<EmbeddedSignInFlowResponse>;\n }\n\n return super.signIn(arg4, arg3, arg1?.code, arg1?.state, arg1) as unknown as Promise<User>;\n }\n\n override async signOut(...args: any[]): Promise<string> {\n if (args[1] && typeof args[1] !== 'string') {\n throw new Error('The second argument must be a string.');\n }\n\n const config: T = this.getConfiguration();\n const afterSignOutUrl: string = config?.afterSignOutUrl || '/';\n\n const resolvedSessionId: string = args[1] || (await getSessionId())!;\n\n try {\n await (super.signOut as (...a: any[]) => Promise<string>)(resolvedSessionId);\n } catch (error) {\n const message: string = error instanceof Error ? error.message : String(error);\n\n if (\n !message.includes('end_session_endpoint') &&\n !message.includes('sign-out endpoint') &&\n !message.includes('Sign-out endpoint') &&\n !message.includes('Sign-out redirect URL')\n ) {\n throw error;\n }\n }\n\n return afterSignOutUrl;\n }\n\n override async signUp(_options?: SignUpOptions): Promise<void> {\n throw new ThunderIDRuntimeError(\n 'Not implemented',\n 'ThunderIDNextClient-ValidationError-002',\n 'nextjs',\n 'The signUp method is not implemented in the Next.js client.',\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n override signInSilently(_options?: SignInOptions): Promise<User | boolean> {\n throw new ThunderIDRuntimeError(\n 'Not implemented',\n 'ThunderIDNextClient-signInSilently-NotImplementedError-001',\n 'nextjs',\n 'The signInSilently method is not implemented in the Next.js client.',\n );\n }\n\n public async getAuthorizeRequestUrl(\n customParams: ExtendedAuthorizeRequestUrlParams,\n userId?: string,\n ): Promise<string> {\n await this.ensureInitialized();\n return this.getSignInUrl(customParams, userId);\n }\n\n public override getStorageManager(): any {\n return super.getStorageManager();\n }\n\n public override async clearSession(): Promise<void> {\n throw new ThunderIDRuntimeError(\n 'Not implemented',\n 'ThunderIDNextClient-clearSession-NotImplementedError-001',\n 'nextjs',\n 'The clearSession method is not implemented in the Next.js client.',\n );\n }\n\n override async setSession(sessionData: Record<string, unknown>, sessionId?: string): Promise<void> {\n return this.getStorageManager().setSessionData(sessionData, sessionId);\n }\n\n override decodeJwtToken<R = Record<string, unknown>>(token: string): Promise<R> {\n return super.decodeJwtToken<R>(token);\n }\n}\n\nexport default ThunderIDNextClient;\n"],"mappings":";;;;;;AAgCA,IAAM,sBAAN,cAAuF,oBAAuB;CAC5G,AAAO,gBAAgB;CAEvB,AAAO,cAAc;AACnB,SAAO;;CAGT,MAAc,oBAAmC;AAC/C,MAAI,CAAC,KAAK,cAIR,OAAM,KAAK,WAAW,EAAE,CAAM;AAGhC,MAAI,CAAC,KAAK,cACR,OAAM,IAAI,MACR,iLACD;;CAIL,MAAe,WAAW,QAAW,SAAqC;AACxE,MAAI,KAAK,cACP,QAAO,QAAQ,QAAQ,KAAK;EAG9B,MAAM,EACJ,SACA,oBACA,UACA,cACA,YACA,WACA,gBACA,iBACA,UACA,GAAG,SACDA,kCAA0B,OAAO;EAErC,MAAMC,SAAiB,MAAMC,yBAAiB;EAE9C,MAAMC,cAAuB,MAAM,MAAM,WACvC;GACE,GAAG;GACH,gBAAgB,kBAAkB;GAClC,iBAAiB,mBAAmB;GACpC;GACA;GACA;GACA,YAAa,KAAa,cAAc;GACxC;GACA;GACA;GACA;GACD,EACD,QACD;AAED,OAAK,gBAAgB;AAErB,SAAO;;CAGT,MAAe,aAAa,QAAsC;AAChE,MAAI;AACF,SAAM,MAAM,aAAa,OAAO;AAChC,UAAO;WACA,OAAO;AACd,SAAM,IAAI,sBACR,uCAAuC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,IAC7F,qDACA,UACA,8GACD;;;CAIL,MAAe,QAAQ,QAAgC;AACrD,QAAM,KAAK,mBAAmB;EAC9B,MAAMC,oBAA4B,UAAW,MAAMC,sBAAc;AAEjE,MAAI;GACF,MAAMC,aAAkC,MAAM,KAAK,mBAAmB,CAAC,eAAe;GACtF,MAAMC,UAA8B,YAAY;AAUhD,UARsB,MAAM,WAAW;IACrC;IACA,KAAK,wBAAwB,WAAW,WAAW;IACnD,SAAS,EACP,eAAe,UAAU,MAAM,KAAK,eAAe,OAAO,IAC3D;IACF,CAAC;WA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IACnE,CAAC;;AAGJ,SAAO,MAAM,OAAO,MAAM,MAAM,MAAM,MAAM,MAAM,OAAO,KAAK;;CAGhE,MAAe,QAAQ,GAAG,MAA8B;AACtD,MAAI,KAAK,MAAM,OAAO,KAAK,OAAO,SAChC,OAAM,IAAI,MAAM,wCAAwC;EAI1D,MAAMC,kBADY,KAAK,kBAAkB,EACD,mBAAmB;EAE3D,MAAMX,oBAA4B,KAAK,MAAO,MAAMC,sBAAc;AAElE,MAAI;AACF,SAAO,MAAM,QAA6C,kBAAkB;WACrE,OAAO;GACd,MAAMW,UAAkB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;AAE9E,OACE,CAAC,QAAQ,SAAS,uBAAuB,IACzC,CAAC,QAAQ,SAAS,oBAAoB,IACtC,CAAC,QAAQ,SAAS,oBAAoB,IACtC,CAAC,QAAQ,SAAS,wBAAwB,CAE1C,OAAM;;AAIV,SAAO;;CAGT,MAAe,OAAO,UAAyC;AAC7D,QAAM,IAAI,sBACR,mBACA,2CACA,UACA,8DACD;;CAIH,AAAS,eAAe,UAAmD;AACzE,QAAM,IAAI,sBACR,mBACA,8DACA,UACA,sEACD;;CAGH,MAAa,uBACX,cACA,QACiB;AACjB,QAAM,KAAK,mBAAmB;AAC9B,SAAO,KAAK,aAAa,cAAc,OAAO;;CAGhD,AAAgB,oBAAyB;AACvC,SAAO,MAAM,mBAAmB;;CAGlC,MAAsB,eAA8B;AAClD,QAAM,IAAI,sBACR,mBACA,4DACA,UACA,oEACD;;CAGH,MAAe,WAAW,aAAsC,WAAmC;AACjG,SAAO,KAAK,mBAAmB,CAAC,eAAe,aAAa,UAAU;;CAGxE,AAAS,eAA4C,OAA2B;AAC9E,SAAO,MAAM,eAAkB,MAAM;;;AAIzC,kCAAe"}
@@ -109,6 +109,32 @@ var ThunderIDNextClient = class extends __thunderid_node.ThunderIDNodeClient {
109
109
  throw new __thunderid_node.ThunderIDRuntimeError(`Failed to update user profile: ${error instanceof Error ? error.message : String(error)}`, "ThunderIDNextClient-UpdateProfileError-001", "react", "An error occurred while updating the user profile. Please check your configuration and network connection.");
110
110
  }
111
111
  }
112
+ /**
113
+ * Updates one or more of the signed-in user's credentials (e.g. `password`, or any other
114
+ * attribute the user type schema declares `credential: true`).
115
+ *
116
+ * Not part of {@link ThunderIDJavaScriptClient}'s base surface — unlike `updateUserProfile`,
117
+ * no other SDK routes credential updates through a client method (React/Vue's
118
+ * `ChangeCredential` call the core `updateMeCredentials` function directly), so this is a
119
+ * Next.js-specific addition rather than an override. Kept here anyway so this SDK's own
120
+ * server actions have one consistent way to reach every `/users/me/*` operation.
121
+ *
122
+ * Deliberately does not catch and rewrap errors the way `updateUserProfile` does: the caller
123
+ * (`updateUserCredentialsAction`) needs the real `ThunderIDAPIError` instance, status code
124
+ * included, to map a failure onto the right form field before it crosses the server action
125
+ * boundary back to the client.
126
+ */
127
+ async updateUserCredentials(payload, userId) {
128
+ await this.ensureInitialized();
129
+ const configData = await this.getStorageManager().getConfigData();
130
+ const baseUrl = configData?.baseUrl;
131
+ await (0, __thunderid_node.updateMeCredentials)({
132
+ baseUrl,
133
+ url: (0, __thunderid_node.resolveResourceEndpoint)("usersMeCredentials", configData),
134
+ headers: { Authorization: `Bearer ${await this.getAccessToken(userId)}` },
135
+ payload
136
+ });
137
+ }
112
138
  isLoading() {
113
139
  return false;
114
140
  }
@@ -143,7 +169,7 @@ var ThunderIDNextClient = class extends __thunderid_node.ThunderIDNodeClient {
143
169
  url: (0, __thunderid_node.resolveResourceEndpoint)("flowExecute", configData, arg2?.url)
144
170
  });
145
171
  }
146
- return super.signIn(arg4, arg3, arg1?.code, arg1?.session_state, arg1?.state, arg1);
172
+ return super.signIn(arg4, arg3, arg1?.code, arg1?.state, arg1);
147
173
  }
148
174
  async signOut(...args) {
149
175
  if (args[1] && typeof args[1] !== "string") throw new Error("The second argument must be a string.");
@@ -1 +1 @@
1
- {"version":3,"file":"ThunderIDNextClient.cjs","names":["ThunderIDNodeClient","decorateConfigWithNextEnv","origin: string","getClientOrigin","initialized: boolean","ThunderIDRuntimeError","resolvedSessionId: string","getSessionId","configData: AuthClientConfig<T>","baseUrl: string | undefined","profile: User","token: string | undefined","arg1: any","arg2: any","arg3: any","arg4: any","configData: ThunderIDNextConfig","afterSignOutUrl: string","message: string"],"sources":["../../src/ThunderIDNextClient.ts"],"sourcesContent":["// Copyright 2025 The ThunderID Authors\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n ThunderIDNodeClient,\n ThunderIDRuntimeError,\n AttributeSchema,\n AuthClientConfig,\n EmbeddedSignInFlowResponse,\n ExtendedAuthorizeRequestUrlParams,\n IdToken,\n SignInOptions,\n SignUpOptions,\n Storage,\n TokenExchangeRequestConfig,\n TokenResponse,\n User,\n UserProfile,\n executeEmbeddedSignInFlow,\n extractUserClaimsFromIdToken,\n generateFlattenedUserProfile,\n getUsersMe,\n getUsersMeMeta,\n updateMeProfile,\n resolveResourceEndpoint,\n} from '@thunderid/node';\nimport {ThunderIDNextConfig} from './models/config';\nimport getClientOrigin from './server/actions/getClientOrigin';\nimport getSessionId from './server/actions/getSessionId';\nimport decorateConfigWithNextEnv from './utils/decorateConfigWithNextEnv';\n\nclass ThunderIDNextClient<T extends ThunderIDNextConfig = ThunderIDNextConfig> extends ThunderIDNodeClient<T> {\n public isInitialized = false;\n\n public constructor() {\n super();\n }\n\n private async ensureInitialized(): Promise<void> {\n if (!this.isInitialized) {\n // Server actions may run in a module context that hasn't been through\n // ThunderIDServerProvider (e.g. a different worker). Try to initialize\n // from environment variables before giving up.\n await this.initialize({} as T);\n }\n\n if (!this.isInitialized) {\n throw new Error(\n '[ThunderIDNextClient] Client is not initialized. Make sure you have wrapped your app with ThunderIDProvider and provided the required configuration (baseUrl, clientId, etc.).',\n );\n }\n }\n\n override async initialize(config: T, storage?: Storage): Promise<boolean> {\n if (this.isInitialized) {\n return Promise.resolve(true);\n }\n\n const {\n baseUrl,\n organizationHandle,\n clientId,\n clientSecret,\n flowSecret,\n signInUrl,\n afterSignInUrl,\n afterSignOutUrl,\n signUpUrl,\n ...rest\n } = decorateConfigWithNextEnv(config);\n\n const origin: string = await getClientOrigin();\n\n const initialized: boolean = await super.initialize(\n {\n ...rest,\n afterSignInUrl: afterSignInUrl ?? origin,\n afterSignOutUrl: afterSignOutUrl ?? origin,\n baseUrl,\n clientId,\n clientSecret,\n enablePKCE: (rest as any).enablePKCE ?? true,\n flowSecret,\n organizationHandle,\n signInUrl,\n signUpUrl,\n } as any,\n storage,\n );\n\n this.isInitialized = initialized;\n\n return initialized;\n }\n\n override async reInitialize(config: Partial<T>): Promise<boolean> {\n try {\n await super.reInitialize(config);\n return true;\n } catch (error) {\n throw new ThunderIDRuntimeError(\n `Failed to re-initialize the client: ${error instanceof Error ? error.message : String(error)}`,\n 'ThunderIDNextClient-reInitialize-RuntimeError-001',\n 'nextjs',\n 'An error occurred while re-initializing the client. Please check your configuration and network connection.',\n );\n }\n }\n\n override async getUser(userId?: string): Promise<User> {\n await this.ensureInitialized();\n const resolvedSessionId: string = userId || (await getSessionId())!;\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n const profile: User = await getUsersMe({\n baseUrl,\n url: resolveResourceEndpoint('usersMe', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n });\n\n return profile;\n } catch (error) {\n return await super.getUser(resolvedSessionId);\n }\n }\n\n override async getUserProfile(userId?: string): Promise<UserProfile> {\n await this.ensureInitialized();\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n const profile: User = await getUsersMe({\n baseUrl,\n url: resolveResourceEndpoint('usersMe', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n });\n\n return {\n flattenedProfile: generateFlattenedUserProfile(profile),\n profile,\n };\n } catch (error) {\n return {\n flattenedProfile: extractUserClaimsFromIdToken(await super.getDecodedIdToken(userId)),\n profile: extractUserClaimsFromIdToken(await super.getDecodedIdToken(userId)),\n };\n }\n }\n\n async getUserSchema(userId?: string): Promise<Record<string, AttributeSchema> | null> {\n await this.ensureInitialized();\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n const {schema} = await getUsersMeMeta({\n baseUrl,\n url: resolveResourceEndpoint('usersMeMeta', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n });\n\n return schema ?? null;\n } catch (error) {\n return null;\n }\n }\n\n override async updateUserProfile(payload: any, userId?: string): Promise<User> {\n await this.ensureInitialized();\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n return updateMeProfile({\n baseUrl,\n url: resolveResourceEndpoint('usersMe', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n payload: payload?.payload ?? payload,\n });\n } catch (error) {\n throw new ThunderIDRuntimeError(\n `Failed to update user profile: ${error instanceof Error ? error.message : String(error)}`,\n 'ThunderIDNextClient-UpdateProfileError-001',\n 'react',\n 'An error occurred while updating the user profile. Please check your configuration and network connection.',\n );\n }\n }\n\n override isLoading(): boolean {\n return false;\n }\n\n override isSignedIn(sessionId?: string): Promise<boolean> {\n return super.isSignedIn(sessionId);\n }\n\n override exchangeToken(config: TokenExchangeRequestConfig, sessionId?: string): Promise<TokenResponse | Response> {\n return super.exchangeToken(config, sessionId) as unknown as Promise<TokenResponse | Response>;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n override async getAccessToken(_sessionId?: string): Promise<string> {\n const {default: getAccessToken} = await import('./server/actions/getAccessToken');\n const token: string | undefined = await getAccessToken();\n\n if (typeof token !== 'string' || !token) {\n throw new ThunderIDRuntimeError(\n 'Failed to get access token.',\n 'ThunderIDNextClient-getAccessToken-RuntimeError-003',\n 'nextjs',\n 'An error occurred while obtaining the access token. Please check your configuration and network connection.',\n );\n }\n\n return token;\n }\n\n override async getDecodedIdToken(sessionId?: string, idToken?: string): Promise<IdToken> {\n await this.ensureInitialized();\n return await super.getDecodedIdToken(sessionId, idToken);\n }\n\n override async signIn(...args: any[]): Promise<any> {\n const arg1: any = args[0];\n const arg2: any = args[1];\n const arg3: any = args[2];\n const arg4: any = args[3];\n\n // An embedded sign-in flow payload initiates or continues a `POST /flow/execute` step\n // (identified by `applicationId` for a new flow or `executionId` to continue one). This is\n // distinct from the OAuth authorization_code exchange handled by `super.signIn` below, which\n // is used once the embedded flow completes and returns an authorization code.\n const isEmbeddedFlowPayload: boolean =\n typeof arg1 === 'object' && arg1 !== null && ('executionId' in arg1 || 'applicationId' in arg1);\n\n if (isEmbeddedFlowPayload) {\n await this.ensureInitialized();\n\n // Typed as the Next config rather than `AuthClientConfig<T>` because the server-only\n // `flowSecret` lives on `ThunderIDNodeConfig`, which the generic base config does not expose.\n const configData: ThunderIDNextConfig = (await this.getStorageManager().getConfigData()) as ThunderIDNextConfig;\n\n return executeEmbeddedSignInFlow({\n baseUrl: configData?.baseUrl,\n flowSecret: arg2?.flowSecret ?? configData?.flowSecret,\n payload: arg1,\n url: resolveResourceEndpoint('flowExecute', configData, arg2?.url),\n }) as unknown as Promise<EmbeddedSignInFlowResponse>;\n }\n\n return super.signIn(arg4, arg3, arg1?.code, arg1?.session_state, arg1?.state, arg1) as unknown as Promise<User>;\n }\n\n override async signOut(...args: any[]): Promise<string> {\n if (args[1] && typeof args[1] !== 'string') {\n throw new Error('The second argument must be a string.');\n }\n\n const config: T = this.getConfiguration();\n const afterSignOutUrl: string = config?.afterSignOutUrl || '/';\n\n const resolvedSessionId: string = args[1] || (await getSessionId())!;\n\n try {\n await (super.signOut as (...a: any[]) => Promise<string>)(resolvedSessionId);\n } catch (error) {\n const message: string = error instanceof Error ? error.message : String(error);\n\n if (\n !message.includes('end_session_endpoint') &&\n !message.includes('sign-out endpoint') &&\n !message.includes('Sign-out endpoint') &&\n !message.includes('Sign-out redirect URL')\n ) {\n throw error;\n }\n }\n\n return afterSignOutUrl;\n }\n\n override async signUp(_options?: SignUpOptions): Promise<void> {\n throw new ThunderIDRuntimeError(\n 'Not implemented',\n 'ThunderIDNextClient-ValidationError-002',\n 'nextjs',\n 'The signUp method is not implemented in the Next.js client.',\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n override signInSilently(_options?: SignInOptions): Promise<User | boolean> {\n throw new ThunderIDRuntimeError(\n 'Not implemented',\n 'ThunderIDNextClient-signInSilently-NotImplementedError-001',\n 'nextjs',\n 'The signInSilently method is not implemented in the Next.js client.',\n );\n }\n\n public async getAuthorizeRequestUrl(\n customParams: ExtendedAuthorizeRequestUrlParams,\n userId?: string,\n ): Promise<string> {\n await this.ensureInitialized();\n return this.getSignInUrl(customParams, userId);\n }\n\n public override getStorageManager(): any {\n return super.getStorageManager();\n }\n\n public override async clearSession(): Promise<void> {\n throw new ThunderIDRuntimeError(\n 'Not implemented',\n 'ThunderIDNextClient-clearSession-NotImplementedError-001',\n 'nextjs',\n 'The clearSession method is not implemented in the Next.js client.',\n );\n }\n\n override async setSession(sessionData: Record<string, unknown>, sessionId?: string): Promise<void> {\n return this.getStorageManager().setSessionData(sessionData, sessionId);\n }\n\n override decodeJwtToken<R = Record<string, unknown>>(token: string): Promise<R> {\n return super.decodeJwtToken<R>(token);\n }\n}\n\nexport default ThunderIDNextClient;\n"],"mappings":";;;;;;;;AA+BA,IAAM,sBAAN,cAAuFA,qCAAuB;CAC5G,AAAO,gBAAgB;CAEvB,AAAO,cAAc;AACnB,SAAO;;CAGT,MAAc,oBAAmC;AAC/C,MAAI,CAAC,KAAK,cAIR,OAAM,KAAK,WAAW,EAAE,CAAM;AAGhC,MAAI,CAAC,KAAK,cACR,OAAM,IAAI,MACR,iLACD;;CAIL,MAAe,WAAW,QAAW,SAAqC;AACxE,MAAI,KAAK,cACP,QAAO,QAAQ,QAAQ,KAAK;EAG9B,MAA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mBAAmB;AAC9B,SAAO,KAAK,aAAa,cAAc,OAAO;;CAGhD,AAAgB,oBAAyB;AACvC,SAAO,MAAM,mBAAmB;;CAGlC,MAAsB,eAA8B;AAClD,QAAM,IAAIA,uCACR,mBACA,4DACA,UACA,oEACD;;CAGH,MAAe,WAAW,aAAsC,WAAmC;AACjG,SAAO,KAAK,mBAAmB,CAAC,eAAe,aAAa,UAAU;;CAGxE,AAAS,eAA4C,OAA2B;AAC9E,SAAO,MAAM,eAAkB,MAAM;;;AAIzC,kCAAe"}
1
+ {"version":3,"file":"ThunderIDNextClient.cjs","names":["ThunderIDNodeClient","decorateConfigWithNextEnv","origin: string","getClientOrigin","initialized: boolean","ThunderIDRuntimeError","resolvedSessionId: string","getSessionId","configData: AuthClientConfig<T>","baseUrl: string | undefined","profile: User","token: string | undefined","arg1: any","arg2: any","arg3: any","arg4: any","configData: ThunderIDNextConfig","afterSignOutUrl: string","message: string"],"sources":["../../src/ThunderIDNextClient.ts"],"sourcesContent":["// Copyright 2025 The ThunderID Authors\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n ThunderIDNodeClient,\n ThunderIDRuntimeError,\n AttributeSchema,\n AuthClientConfig,\n EmbeddedSignInFlowResponse,\n ExtendedAuthorizeRequestUrlParams,\n IdToken,\n SignInOptions,\n SignUpOptions,\n Storage,\n TokenExchangeRequestConfig,\n TokenResponse,\n User,\n UserProfile,\n executeEmbeddedSignInFlow,\n extractUserClaimsFromIdToken,\n generateFlattenedUserProfile,\n getUsersMe,\n getUsersMeMeta,\n updateMeCredentials,\n updateMeProfile,\n resolveResourceEndpoint,\n} from '@thunderid/node';\nimport {ThunderIDNextConfig} from './models/config';\nimport getClientOrigin from './server/actions/getClientOrigin';\nimport getSessionId from './server/actions/getSessionId';\nimport decorateConfigWithNextEnv from './utils/decorateConfigWithNextEnv';\n\nclass ThunderIDNextClient<T extends ThunderIDNextConfig = ThunderIDNextConfig> extends ThunderIDNodeClient<T> {\n public isInitialized = false;\n\n public constructor() {\n super();\n }\n\n private async ensureInitialized(): Promise<void> {\n if (!this.isInitialized) {\n // Server actions may run in a module context that hasn't been through\n // ThunderIDServerProvider (e.g. a different worker). Try to initialize\n // from environment variables before giving up.\n await this.initialize({} as T);\n }\n\n if (!this.isInitialized) {\n throw new Error(\n '[ThunderIDNextClient] Client is not initialized. Make sure you have wrapped your app with ThunderIDProvider and provided the required configuration (baseUrl, clientId, etc.).',\n );\n }\n }\n\n override async initialize(config: T, storage?: Storage): Promise<boolean> {\n if (this.isInitialized) {\n return Promise.resolve(true);\n }\n\n const {\n baseUrl,\n organizationHandle,\n clientId,\n clientSecret,\n flowSecret,\n signInUrl,\n afterSignInUrl,\n afterSignOutUrl,\n signUpUrl,\n ...rest\n } = decorateConfigWithNextEnv(config);\n\n const origin: string = await getClientOrigin();\n\n const initialized: boolean = await super.initialize(\n {\n ...rest,\n afterSignInUrl: afterSignInUrl ?? origin,\n afterSignOutUrl: afterSignOutUrl ?? origin,\n baseUrl,\n clientId,\n clientSecret,\n enablePKCE: (rest as any).enablePKCE ?? true,\n flowSecret,\n organizationHandle,\n signInUrl,\n signUpUrl,\n } as any,\n storage,\n );\n\n this.isInitialized = initialized;\n\n return initialized;\n }\n\n override async reInitialize(config: Partial<T>): Promise<boolean> {\n try {\n await super.reInitialize(config);\n return true;\n } catch (error) {\n throw new ThunderIDRuntimeError(\n `Failed to re-initialize the client: ${error instanceof Error ? error.message : String(error)}`,\n 'ThunderIDNextClient-reInitialize-RuntimeError-001',\n 'nextjs',\n 'An error occurred while re-initializing the client. Please check your configuration and network connection.',\n );\n }\n }\n\n override async getUser(userId?: string): Promise<User> {\n await this.ensureInitialized();\n const resolvedSessionId: string = userId || (await getSessionId())!;\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n const profile: User = await getUsersMe({\n baseUrl,\n url: resolveResourceEndpoint('usersMe', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n });\n\n return profile;\n } catch (error) {\n return await super.getUser(resolvedSessionId);\n }\n }\n\n override async getUserProfile(userId?: string): Promise<UserProfile> {\n await this.ensureInitialized();\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n const profile: User = await getUsersMe({\n baseUrl,\n url: resolveResourceEndpoint('usersMe', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n });\n\n return {\n flattenedProfile: generateFlattenedUserProfile(profile),\n profile,\n };\n } catch (error) {\n return {\n flattenedProfile: extractUserClaimsFromIdToken(await super.getDecodedIdToken(userId)),\n profile: extractUserClaimsFromIdToken(await super.getDecodedIdToken(userId)),\n };\n }\n }\n\n async getUserSchema(userId?: string): Promise<Record<string, AttributeSchema> | null> {\n await this.ensureInitialized();\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n const {schema} = await getUsersMeMeta({\n baseUrl,\n url: resolveResourceEndpoint('usersMeMeta', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n });\n\n return schema ?? null;\n } catch (error) {\n return null;\n }\n }\n\n override async updateUserProfile(payload: any, userId?: string): Promise<User> {\n await this.ensureInitialized();\n\n try {\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n return updateMeProfile({\n baseUrl,\n url: resolveResourceEndpoint('usersMe', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n payload: payload?.payload ?? payload,\n });\n } catch (error) {\n throw new ThunderIDRuntimeError(\n `Failed to update user profile: ${error instanceof Error ? error.message : String(error)}`,\n 'ThunderIDNextClient-UpdateProfileError-001',\n 'react',\n 'An error occurred while updating the user profile. Please check your configuration and network connection.',\n );\n }\n }\n\n /**\n * Updates one or more of the signed-in user's credentials (e.g. `password`, or any other\n * attribute the user type schema declares `credential: true`).\n *\n * Not part of {@link ThunderIDJavaScriptClient}'s base surface — unlike `updateUserProfile`,\n * no other SDK routes credential updates through a client method (React/Vue's\n * `ChangeCredential` call the core `updateMeCredentials` function directly), so this is a\n * Next.js-specific addition rather than an override. Kept here anyway so this SDK's own\n * server actions have one consistent way to reach every `/users/me/*` operation.\n *\n * Deliberately does not catch and rewrap errors the way `updateUserProfile` does: the caller\n * (`updateUserCredentialsAction`) needs the real `ThunderIDAPIError` instance, status code\n * included, to map a failure onto the right form field before it crosses the server action\n * boundary back to the client.\n */\n override async updateUserCredentials(payload: Record<string, string>, userId?: string): Promise<void> {\n await this.ensureInitialized();\n\n const configData: AuthClientConfig<T> = await this.getStorageManager().getConfigData();\n const baseUrl: string | undefined = configData?.baseUrl;\n\n await updateMeCredentials({\n baseUrl,\n url: resolveResourceEndpoint('usersMeCredentials', configData),\n headers: {\n Authorization: `Bearer ${await this.getAccessToken(userId)}`,\n },\n payload,\n });\n }\n\n override isLoading(): boolean {\n return false;\n }\n\n override isSignedIn(sessionId?: string): Promise<boolean> {\n return super.isSignedIn(sessionId);\n }\n\n override exchangeToken(config: TokenExchangeRequestConfig, sessionId?: string): Promise<TokenResponse | Response> {\n return super.exchangeToken(config, sessionId) as unknown as Promise<TokenResponse | Response>;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n override async getAccessToken(_sessionId?: string): Promise<string> {\n const {default: getAccessToken} = await import('./server/actions/getAccessToken');\n const token: string | undefined = await getAccessToken();\n\n if (typeof token !== 'string' || !token) {\n throw new ThunderIDRuntimeError(\n 'Failed to get access token.',\n 'ThunderIDNextClient-getAccessToken-RuntimeError-003',\n 'nextjs',\n 'An error occurred while obtaining the access token. Please check your configuration and network connection.',\n );\n }\n\n return token;\n }\n\n override async getDecodedIdToken(sessionId?: string, idToken?: string): Promise<IdToken> {\n await this.ensureInitialized();\n return await super.getDecodedIdToken(sessionId, idToken);\n }\n\n override async signIn(...args: any[]): Promise<any> {\n const arg1: any = args[0];\n const arg2: any = args[1];\n const arg3: any = args[2];\n const arg4: any = args[3];\n\n // An embedded sign-in flow payload initiates or continues a `POST /flow/execute` step\n // (identified by `applicationId` for a new flow or `executionId` to continue one). This is\n // distinct from the OAuth authorization_code exchange handled by `super.signIn` below, which\n // is used once the embedded flow completes and returns an authorization code.\n const isEmbeddedFlowPayload: boolean =\n typeof arg1 === 'object' && arg1 !== null && ('executionId' in arg1 || 'applicationId' in arg1);\n\n if (isEmbeddedFlowPayload) {\n await this.ensureInitialized();\n\n // Typed as the Next config rather than `AuthClientConfig<T>` because the server-only\n // `flowSecret` lives on `ThunderIDNodeConfig`, which the generic base config does not expose.\n const configData: ThunderIDNextConfig = (await this.getStorageManager().getConfigData()) as ThunderIDNextConfig;\n\n return executeEmbeddedSignInFlow({\n baseUrl: configData?.baseUrl,\n flowSecret: arg2?.flowSecret ?? configData?.flowSecret,\n payload: arg1,\n url: resolveResourceEndpoint('flowExecute', configData, arg2?.url),\n }) as unknown as Promise<EmbeddedSignInFlowResponse>;\n }\n\n return super.signIn(arg4, arg3, arg1?.code, arg1?.state, arg1) as unknown as Promise<User>;\n }\n\n override async signOut(...args: any[]): Promise<string> {\n if (args[1] && typeof args[1] !== 'string') {\n throw new Error('The second argument must be a string.');\n }\n\n const config: T = this.getConfiguration();\n const afterSignOutUrl: string = config?.afterSignOutUrl || '/';\n\n const resolvedSessionId: string = args[1] || (await getSessionId())!;\n\n try {\n await (super.signOut as (...a: any[]) => Promise<string>)(resolvedSessionId);\n } catch (error) {\n const message: string = error instanceof Error ? error.message : String(error);\n\n if (\n !message.includes('end_session_endpoint') &&\n !message.includes('sign-out endpoint') &&\n !message.includes('Sign-out endpoint') &&\n !message.includes('Sign-out redirect URL')\n ) {\n throw error;\n }\n }\n\n return afterSignOutUrl;\n }\n\n override async signUp(_options?: SignUpOptions): Promise<void> {\n throw new ThunderIDRuntimeError(\n 'Not implemented',\n 'ThunderIDNextClient-ValidationError-002',\n 'nextjs',\n 'The signUp method is not implemented in the Next.js client.',\n );\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n override signInSilently(_options?: SignInOptions): Promise<User | boolean> {\n throw new ThunderIDRuntimeError(\n 'Not implemented',\n 'ThunderIDNextClient-signInSilently-NotImplementedError-001',\n 'nextjs',\n 'The signInSilently method is not implemented in the Next.js client.',\n );\n }\n\n public async getAuthorizeRequestUrl(\n customParams: ExtendedAuthorizeRequestUrlParams,\n userId?: string,\n ): Promise<string> {\n await this.ensureInitialized();\n return this.getSignInUrl(customParams, userId);\n }\n\n public override getStorageManager(): any {\n return super.getStorageManager();\n }\n\n public override async clearSession(): Promise<void> {\n throw new ThunderIDRuntimeError(\n 'Not implemented',\n 'ThunderIDNextClient-clearSession-NotImplementedError-001',\n 'nextjs',\n 'The clearSession method is not implemented in the Next.js client.',\n );\n }\n\n override async setSession(sessionData: Record<string, unknown>, sessionId?: string): Promise<void> {\n return this.getStorageManager().setSessionData(sessionData, sessionId);\n }\n\n override decodeJwtToken<R = Record<string, unknown>>(token: string): Promise<R> {\n return super.decodeJwtToken<R>(token);\n }\n}\n\nexport default ThunderIDNextClient;\n"],"mappings":";;;;;;;;AAgCA,IAAM,sBAAN,cAAuFA,qCAAuB;CAC5G,AAAO,gBAAgB;CAEvB,AAAO,cAAc;AACnB,SAAO;;CAGT,MAAc,oBAAmC;AAC/C,MAAI,CAAC,KAAK,cAIR,OAAM,KAAK,WAAW,EAAE,CAAM;AAGhC,MAAI,CAAC,KAAK,cACR,OAAM,IAAI,MACR,iLACD;;CAIL,MAAe,WAAW,QAAW,SAAqC;AACxE,MAAI,KAAK,cACP,QAAO,QAAQ,QAAQ,KAAK;EAG9B,MAAM,EACJ,SACA,oBACA,UACA,cACA,YACA,WACA,gBACA,iBACA,UACA,GAAG,SACDC,0CAA0B,OAAO;EAErC,MAAMC,SAAiB,MAAMC,iCAAiB;EAE9C,MAAMC,cAAuB,MAAM,MAAM,WACvC;GACE,GAAG;GACH,g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AAmD;AACzE,QAAM,IAAIA,uCACR,mBACA,8DACA,UACA,sEACD;;CAGH,MAAa,uBACX,cACA,QACiB;AACjB,QAAM,KAAK,mBAAmB;AAC9B,SAAO,KAAK,aAAa,cAAc,OAAO;;CAGhD,AAAgB,oBAAyB;AACvC,SAAO,MAAM,mBAAmB;;CAGlC,MAAsB,eAA8B;AAClD,QAAM,IAAIA,uCACR,mBACA,4DACA,UACA,oEACD;;CAGH,MAAe,WAAW,aAAsC,WAAmC;AACjG,SAAO,KAAK,mBAAmB,CAAC,eAAe,aAAa,UAAU;;CAGxE,AAAS,eAA4C,OAA2B;AAC9E,SAAO,MAAM,eAAkB,MAAM;;;AAIzC,kCAAe"}
@@ -0,0 +1,104 @@
1
+ 'use client';
2
+
3
+
4
+ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
5
+ const require_getSessionId = require('../../../../server/actions/getSessionId.cjs');
6
+ const require_useThunderID = require('../../../contexts/ThunderID/useThunderID.cjs');
7
+ const require_updateUserCredentialsAction = require('../../../../server/actions/updateUserCredentialsAction.cjs');
8
+ let __thunderid_node = require("@thunderid/node");
9
+ __thunderid_node = require_rolldown_runtime.__toESM(__thunderid_node);
10
+ let __thunderid_react = require("@thunderid/react");
11
+ __thunderid_react = require_rolldown_runtime.__toESM(__thunderid_react);
12
+ let react = require("react");
13
+ react = require_rolldown_runtime.__toESM(react);
14
+ let react_jsx_runtime = require("react/jsx-runtime");
15
+ react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
16
+
17
+ //#region src/client/components/presentation/ChangeCredential/ChangeCredential.tsx
18
+ /**
19
+ * Title-cases a credential attribute name for use as a display-name fallback when the schema
20
+ * declares no `displayName` for it, e.g. `pin` -> `Pin`.
21
+ */
22
+ const defaultDisplayName = (attribute) => attribute.charAt(0).toUpperCase() + attribute.slice(1);
23
+ /**
24
+ * ChangeCredential lets the signed-in user set a new value for one of their own credentials.
25
+ *
26
+ * This is the Next.js-specific implementation: it uses `BaseChangeCredential` from
27
+ * `@thunderid/react` for rendering, but routes the write through
28
+ * `updateUserCredentialsAction` (a server action) instead of calling the ThunderID server
29
+ * directly from the browser, matching how `UserProfile` reaches `updateUserProfileAction`.
30
+ *
31
+ * Defaults to managing the `password` credential. To manage a different one (for example a
32
+ * PIN declared on the user type schema), set `attribute`; render the component once per
33
+ * credential to let a user manage several.
34
+ *
35
+ * @example
36
+ * ```tsx
37
+ * // Basic usage, manages the password
38
+ * <ChangeCredential onSuccess={() => toast('Password updated')} />
39
+ *
40
+ * // Managing a different credential declared on the schema
41
+ * <ChangeCredential attribute="pin" />
42
+ * ```
43
+ */
44
+ const ChangeCredential = ({ attribute = __thunderid_node.CredentialConstants.PASSWORD, onSuccess, policy, preferences,...rest }) => {
45
+ const { preferences: contextPreferences } = require_useThunderID.default();
46
+ const { userSchema } = (0, __thunderid_react.useUser)();
47
+ const resolvedDisplayName = userSchema?.[attribute]?.displayName ?? defaultDisplayName(attribute);
48
+ const resolvedPreferences = (0, react.useMemo)(() => ({
49
+ ...contextPreferences,
50
+ ...preferences,
51
+ user: {
52
+ ...contextPreferences?.user,
53
+ ...preferences?.user
54
+ }
55
+ }), [contextPreferences, preferences]);
56
+ const { t } = (0, __thunderid_react.useTranslation)(resolvedPreferences?.i18n);
57
+ const [error, setError] = (0, react.useState)(null);
58
+ const [fieldErrors, setFieldErrors] = (0, react.useState)({});
59
+ const [loading, setLoading] = (0, react.useState)(false);
60
+ const [success, setSuccess] = (0, react.useState)(false);
61
+ const resolvedPolicy = (0, react.useMemo)(() => (0, __thunderid_node.resolveChangeCredentialPolicy)(userSchema, attribute, policy), [
62
+ userSchema,
63
+ attribute,
64
+ policy
65
+ ]);
66
+ const handleSubmit = async ({ newPassword }) => {
67
+ setError(null);
68
+ setFieldErrors({});
69
+ setSuccess(false);
70
+ setLoading(true);
71
+ const result = await require_updateUserCredentialsAction.default({ [attribute]: newPassword }, await require_getSessionId.default());
72
+ if (result.success) {
73
+ setSuccess(true);
74
+ onSuccess?.();
75
+ } else {
76
+ const text = result.message ?? t(result.messageKey, {
77
+ credential: resolvedDisplayName,
78
+ credentialLower: resolvedDisplayName.toLowerCase()
79
+ });
80
+ if (result.field) setFieldErrors({ [result.field]: text });
81
+ else setError(text);
82
+ }
83
+ setLoading(false);
84
+ };
85
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__thunderid_react.BaseChangeCredential, {
86
+ ...rest,
87
+ credentialDisplayName: resolvedDisplayName,
88
+ error,
89
+ fieldErrors,
90
+ loading,
91
+ policy: resolvedPolicy,
92
+ preferences: resolvedPreferences,
93
+ success,
94
+ unavailable: !(0, __thunderid_node.supportsCredential)(userSchema, attribute),
95
+ onSubmit: (values) => {
96
+ handleSubmit(values);
97
+ }
98
+ });
99
+ };
100
+ var ChangeCredential_default = ChangeCredential;
101
+
102
+ //#endregion
103
+ exports.default = ChangeCredential_default;
104
+ //# sourceMappingURL=ChangeCredential.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChangeCredential.cjs","names":["ChangeCredential: FC<ChangeCredentialProps>","CredentialConstants","useThunderID","resolvedDisplayName: string","resolvedPolicy: PasswordPolicy","result: UpdateUserCredentialsActionResult","updateUserCredentialsAction","getSessionId","text: string","BaseChangeCredential"],"sources":["../../../../../../src/client/components/presentation/ChangeCredential/ChangeCredential.tsx"],"sourcesContent":["// Copyright 2026 The ThunderID Authors\n// SPDX-License-Identifier: Apache-2.0\n\n'use client';\n\nimport {CredentialConstants, PasswordPolicy, resolveChangeCredentialPolicy, supportsCredential} from '@thunderid/node';\nimport {\n BaseChangeCredential,\n BaseChangeCredentialProps,\n ChangePasswordValues,\n useTranslation,\n useUser,\n} from '@thunderid/react';\nimport {FC, ReactElement, useMemo, useState} from 'react';\nimport getSessionId from '../../../../server/actions/getSessionId';\nimport updateUserCredentialsAction, {\n UpdateUserCredentialsActionResult,\n} from '../../../../server/actions/updateUserCredentialsAction';\nimport useThunderID from '../../../contexts/ThunderID/useThunderID';\n\n/**\n * Title-cases a credential attribute name for use as a display-name fallback when the schema\n * declares no `displayName` for it, e.g. `pin` -> `Pin`.\n */\nconst defaultDisplayName = (attribute: string): string => attribute.charAt(0).toUpperCase() + attribute.slice(1);\n\n/**\n * Props for the ChangeCredential component.\n * Mirrors `@thunderid/react`'s `ChangeCredentialProps` exactly, so a consumer moving between\n * the React and Next.js SDKs doesn't need to change how they call it.\n */\nexport type ChangeCredentialProps = Omit<\n BaseChangeCredentialProps,\n 'credentialDisplayName' | 'error' | 'fieldErrors' | 'loading' | 'onSubmit' | 'success'\n> & {\n /**\n * The credential attribute this instance manages, any attribute the user's entity type\n * schema declares `credential: true` (for example `password` or `pin`). Defaults to\n * `password`. Render the component once per credential to let a user manage more than one,\n * for example `<ChangeCredential />` for the password and\n * `<ChangeCredential attribute=\"pin\" />` for a PIN.\n */\n attribute?: string;\n /**\n * Called after the credential has been changed successfully.\n */\n onSuccess?: () => void;\n};\n\n/**\n * ChangeCredential lets the signed-in user set a new value for one of their own credentials.\n *\n * This is the Next.js-specific implementation: it uses `BaseChangeCredential` from\n * `@thunderid/react` for rendering, but routes the write through\n * `updateUserCredentialsAction` (a server action) instead of calling the ThunderID server\n * directly from the browser, matching how `UserProfile` reaches `updateUserProfileAction`.\n *\n * Defaults to managing the `password` credential. To manage a different one (for example a\n * PIN declared on the user type schema), set `attribute`; render the component once per\n * credential to let a user manage several.\n *\n * @example\n * ```tsx\n * // Basic usage, manages the password\n * <ChangeCredential onSuccess={() => toast('Password updated')} />\n *\n * // Managing a different credential declared on the schema\n * <ChangeCredential attribute=\"pin\" />\n * ```\n */\nconst ChangeCredential: FC<ChangeCredentialProps> = ({\n attribute = CredentialConstants.PASSWORD,\n onSuccess,\n policy,\n preferences,\n ...rest\n}: ChangeCredentialProps): ReactElement => {\n const {preferences: contextPreferences} = useThunderID();\n const {userSchema} = useUser();\n const resolvedDisplayName: string = userSchema?.[attribute]?.displayName ?? defaultDisplayName(attribute);\n\n const resolvedPreferences = useMemo(\n () => ({\n ...contextPreferences,\n ...preferences,\n user: {...contextPreferences?.user, ...preferences?.user},\n }),\n [contextPreferences, preferences],\n );\n const {t} = useTranslation(resolvedPreferences?.i18n);\n\n const [error, setError] = useState<string | null>(null);\n const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});\n const [loading, setLoading] = useState<boolean>(false);\n const [success, setSuccess] = useState<boolean>(false);\n\n const resolvedPolicy: PasswordPolicy = useMemo(\n () => resolveChangeCredentialPolicy(userSchema, attribute, policy),\n [userSchema, attribute, policy],\n );\n\n const handleSubmit = async ({newPassword}: ChangePasswordValues): Promise<void> => {\n setError(null);\n setFieldErrors({});\n setSuccess(false);\n setLoading(true);\n\n const result: UpdateUserCredentialsActionResult = await updateUserCredentialsAction(\n {[attribute]: newPassword},\n await getSessionId(),\n );\n\n if (result.success) {\n setSuccess(true);\n onSuccess?.();\n } else {\n const text: string =\n result.message ??\n t(result.messageKey, {credential: resolvedDisplayName, credentialLower: resolvedDisplayName.toLowerCase()});\n\n if (result.field) {\n setFieldErrors({[result.field]: text});\n } else {\n setError(text);\n }\n }\n\n setLoading(false);\n };\n\n return (\n <BaseChangeCredential\n {...rest}\n credentialDisplayName={resolvedDisplayName}\n error={error}\n fieldErrors={fieldErrors}\n loading={loading}\n policy={resolvedPolicy}\n preferences={resolvedPreferences}\n success={success}\n unavailable={!supportsCredential(userSchema, attribute)}\n onSubmit={(values: ChangePasswordValues): void => {\n void handleSubmit(values);\n }}\n />\n );\n};\n\nexport default ChangeCredential;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,sBAAsB,cAA8B,UAAU,OAAO,EAAE,CAAC,aAAa,GAAG,UAAU,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;AA8ChH,MAAMA,oBAA+C,EACnD,YAAYC,qCAAoB,UAChC,WACA,QACA,YACA,GAAG,WACsC;CACzC,MAAM,EAAC,aAAa,uBAAsBC,8BAAc;CACxD,MAAM,EAAC,+CAAuB;CAC9B,MAAMC,sBAA8B,aAAa,YAAY,eAAe,mBAAmB,UAAU;CAEzG,MAAM,gDACG;EACL,GAAG;EACH,GAAG;EACH,MAAM;GAAC,GAAG,oBAAoB;GAAM,GAAG,aAAa;GAAK;EAC1D,GACD,CAAC,oBAAoB,YAAY,CAClC;CACD,MAAM,EAAC,4CAAoB,qBAAqB,KAAK;CAErD,MAAM,CAAC,OAAO,gCAAoC,KAAK;CACvD,MAAM,CAAC,aAAa,sCAAmD,EAAE,CAAC;CAC1E,MAAM,CAAC,SAAS,kCAAgC,MAAM;CACtD,MAAM,CAAC,SAAS,kCAAgC,MAAM;CAEtD,MAAMC,8FACgC,YAAY,WAAW,OAAO,EAClE;EAAC;EAAY;EAAW;EAAO,CAChC;CAED,MAAM,eAAe,OAAO,EAAC,kBAAsD;AACjF,WAAS,KAAK;AACd,iBAAe,EAAE,CAAC;AAClB,aAAW,MAAM;AACjB,aAAW,KAAK;EAEhB,MAAMC,SAA4C,MAAMC,4CACtD,GAAE,YAAY,aAAY,EAC1B,MAAMC,8BAAc,CACrB;AAED,MAAI,OAAO,SAAS;AAClB,cAAW,KAAK;AAChB,gBAAa;SACR;GACL,MAAMC,OACJ,OAAO,WACP,EAAE,OAAO,YAAY;IAAC,YAAY;IAAqB,iBAAiB,oBAAoB,aAAa;IAAC,CAAC;AAE7G,OAAI,OAAO,MACT,gBAAe,GAAE,OAAO,QAAQ,MAAK,CAAC;OAEtC,UAAS,KAAK;;AAIlB,aAAW,MAAM;;AAGnB,QACE,2CAACC;EACC,GAAI;EACJ,uBAAuB;EAChB;EACM;EACJ;EACT,QAAQ;EACR,aAAa;EACJ;EACT,aAAa,0CAAoB,YAAY,UAAU;EACvD,WAAW,WAAuC;AAChD,GAAK,aAAa,OAAO;;GAE3B;;AAIN,+BAAe"}
@@ -58,10 +58,14 @@ react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
58
58
  * />
59
59
  * ```
60
60
  */
61
- const UserDropdown = ({ children, renderTrigger, renderDropdown, onSignOut,...rest }) => {
61
+ const UserDropdown = ({ children, renderTrigger, renderDropdown, onManageProfile: onManageProfileOverride, onSignOut,...rest }) => {
62
62
  const { user, isLoading, signOut } = require_useThunderID.default();
63
63
  const [isProfileOpen, setIsProfileOpen] = (0, react.useState)(false);
64
64
  const handleManageProfile = () => {
65
+ if (onManageProfileOverride) {
66
+ onManageProfileOverride();
67
+ return;
68
+ }
65
69
  setIsProfileOpen(true);
66
70
  };
67
71
  const handleSignOut = () => {
@@ -79,7 +83,7 @@ const UserDropdown = ({ children, renderTrigger, renderDropdown, onSignOut,...re
79
83
  signOut: handleSignOut,
80
84
  user
81
85
  };
82
- if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [children(renderProps), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_UserProfile.default, {
86
+ if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [children(renderProps), !onManageProfileOverride && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_UserProfile.default, {
83
87
  mode: "popup",
84
88
  open: isProfileOpen,
85
89
  onOpenChange: setIsProfileOpen
@@ -90,7 +94,7 @@ const UserDropdown = ({ children, renderTrigger, renderDropdown, onSignOut,...re
90
94
  onManageProfile: handleManageProfile,
91
95
  onSignOut: handleSignOut,
92
96
  ...rest
93
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_UserProfile.default, {
97
+ }), !onManageProfileOverride && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_UserProfile.default, {
94
98
  mode: "popup",
95
99
  open: isProfileOpen,
96
100
  onOpenChange: setIsProfileOpen
@@ -101,7 +105,7 @@ const UserDropdown = ({ children, renderTrigger, renderDropdown, onSignOut,...re
101
105
  onManageProfile: handleManageProfile,
102
106
  onSignOut: handleSignOut,
103
107
  ...rest
104
- }), isProfileOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_UserProfile.default, {
108
+ }), !onManageProfileOverride && isProfileOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_UserProfile.default, {
105
109
  mode: "popup",
106
110
  open: isProfileOpen,
107
111
  onOpenChange: setIsProfileOpen
@@ -1 +1 @@
1
- {"version":3,"file":"UserDropdown.cjs","names":["UserDropdown: FC<UserDropdownProps>","useThunderID","renderProps: UserDropdownRenderProps","UserProfile","BaseUserDropdown"],"sources":["../../../../../../src/client/components/presentation/UserDropdown/UserDropdown.tsx"],"sourcesContent":["// Copyright 2025 The ThunderID Authors\n// SPDX-License-Identifier: Apache-2.0\n\n'use client';\n\nimport {BaseUserDropdown, BaseUserDropdownProps} from '@thunderid/react';\nimport {FC, ReactElement, ReactNode, useState} from 'react';\nimport useThunderID from '../../../contexts/ThunderID/useThunderID';\nimport UserProfile from '../UserProfile/UserProfile.js';\n\n/**\n * Render props data passed to the children function\n */\nexport interface UserDropdownRenderProps {\n /** Function to close the profile dialog */\n closeProfile: () => void;\n /** Whether user data is currently loading */\n isLoading: boolean;\n /** Whether the profile dialog is currently open */\n isProfileOpen: boolean;\n /** Function to open the user profile dialog */\n openProfile: () => void;\n /** Function to sign out the user */\n signOut: () => void;\n /** The authenticated user object */\n user: any;\n}\n\n/**\n * Props for the UserDropdown component.\n * Extends BaseUserDropdownProps but excludes user, onManageProfile, and onSignOut since they're handled internally\n */\nexport type UserDropdownProps = Omit<BaseUserDropdownProps, 'user' | 'onManageProfile'> & {\n /**\n * Render prop function that receives user state and actions.\n * When provided, this completely replaces the default dropdown rendering.\n */\n children?: (props: UserDropdownRenderProps) => ReactNode;\n /**\n * Custom render function for the dropdown content.\n * When provided, this replaces just the dropdown content while keeping the trigger.\n */\n renderDropdown?: (props: UserDropdownRenderProps) => ReactNode;\n /**\n * Custom render function for the trigger button.\n * When provided, this replaces just the trigger button while keeping the dropdown.\n */\n renderTrigger?: (props: UserDropdownRenderProps) => ReactNode;\n};\n\n/**\n * UserDropdown component displays a user avatar with a dropdown menu.\n * When clicked, it shows a popover with customizable menu items.\n * This component is the React-specific implementation that uses the BaseUserDropdown\n * and automatically retrieves the user data from ThunderID context.\n *\n * Supports render props for complete customization of the dropdown appearance and behavior.\n *\n * @example\n * ```tsx\n * // Basic usage - will use user from ThunderID context\n * <UserDropdown menuItems={[\n * { label: 'Profile', onClick: () => {} },\n * { label: 'Settings', href: '/settings' },\n * { label: 'Sign Out', onClick: () => {} }\n * ]} />\n *\n * // With custom configuration\n * <UserDropdown\n * showTriggerLabel={true}\n * avatarSize={40}\n * fallback={<div>Please sign in</div>}\n * />\n *\n * // Using render props for complete customization\n * <UserDropdown>\n * {({ user, isLoading, openProfile, signOut }) => (\n * <div>\n * <button onClick={openProfile}>\n * {user?.name || 'Loading...'}\n * </button>\n * <button onClick={signOut}>Logout</button>\n * </div>\n * )}\n * </UserDropdown>\n *\n * // Using partial render props\n * <UserDropdown\n * renderTrigger={({ user, openProfile }) => (\n * <button onClick={openProfile} className=\"custom-trigger\">\n * Welcome, {user?.name}!\n * </button>\n * )}\n * />\n * ```\n */\nconst UserDropdown: FC<UserDropdownProps> = ({\n children,\n renderTrigger,\n renderDropdown,\n onSignOut,\n ...rest\n}: UserDropdownProps): ReactElement => {\n const {user, isLoading, signOut} = useThunderID();\n const [isProfileOpen, setIsProfileOpen] = useState(false);\n\n const handleManageProfile = (): void => {\n setIsProfileOpen(true);\n };\n\n const handleSignOut = (): void => {\n signOut();\n if (onSignOut) {\n onSignOut();\n }\n };\n\n const closeProfile = (): void => {\n setIsProfileOpen(false);\n };\n\n // Prepare render props data\n const renderProps: UserDropdownRenderProps = {\n closeProfile,\n isLoading: isLoading!,\n isProfileOpen,\n openProfile: handleManageProfile,\n signOut: handleSignOut,\n user,\n };\n\n // If children render prop is provided, use it for complete customization\n if (children) {\n return (\n <>\n {children(renderProps)}\n <UserProfile mode=\"popup\" open={isProfileOpen} onOpenChange={setIsProfileOpen} />\n </>\n );\n }\n\n // If partial render props are provided, customize specific parts\n if (renderTrigger || renderDropdown) {\n // This would require significant changes to BaseUserDropdown to support partial customization\n // For now, we'll provide a simple implementation that shows how it could work\n return (\n <>\n {renderTrigger ? (\n renderTrigger(renderProps)\n ) : (\n <BaseUserDropdown\n user={user}\n isLoading={isLoading}\n onManageProfile={handleManageProfile}\n onSignOut={handleSignOut}\n {...rest}\n />\n )}\n {/* Note: renderDropdown would need BaseUserDropdown modifications to implement properly */}\n <UserProfile mode=\"popup\" open={isProfileOpen} onOpenChange={setIsProfileOpen} />\n </>\n );\n }\n\n // Default behavior - use BaseUserDropdown as before\n return (\n <>\n <BaseUserDropdown\n user={user}\n isLoading={isLoading}\n onManageProfile={handleManageProfile}\n onSignOut={handleSignOut}\n {...rest}\n />\n {isProfileOpen && <UserProfile mode=\"popup\" open={isProfileOpen} onOpenChange={setIsProfileOpen} />}\n </>\n );\n};\n\nexport default UserDropdown;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgGA,MAAMA,gBAAuC,EAC3C,UACA,eACA,gBACA,UACA,GAAG,WACkC;CACrC,MAAM,EAAC,MAAM,WAAW,YAAWC,8BAAc;CACjD,MAAM,CAAC,eAAe,wCAA6B,MAAM;CAEzD,MAAM,4BAAkC;AACtC,mBAAiB,KAAK;;CAGxB,MAAM,sBAA4B;AAChC,WAAS;AACT,MAAI,UACF,YAAW;;CAIf,MAAM,qBAA2B;AAC/B,mBAAiB,MAAM;;CAIzB,MAAMC,cAAuC;EAC3C;EACW;EACX;EACA,aAAa;EACb,SAAS;EACT;EACD;AAGD,KAAI,SACF,QACE,qFACG,SAAS,YAAY,EACtB,2CAACC;EAAY,MAAK;EAAQ,MAAM;EAAe,cAAc;GAAoB,IAChF;AAKP,KAAI,iBAAiB,eAGnB,QACE,qFACG,gBACC,cAAc,YAAY,GAE1B,2CAACC;EACO;EACK;EACX,iBAAiB;EACjB,WAAW;EACX,GAAI;GACJ,EAGJ,2CAACD;EAAY,MAAK;EAAQ,MAAM;EAAe,cAAc;GAAoB,IAChF;AAKP,QACE,qFACE,2CAACC;EACO;EACK;EACX,iBAAiB;EACjB,WAAW;EACX,GAAI;GACJ,EACD,iBAAiB,2CAACD;EAAY,MAAK;EAAQ,MAAM;EAAe,cAAc;GAAoB,IAClG;;AAIP,2BAAe"}
1
+ {"version":3,"file":"UserDropdown.cjs","names":["UserDropdown: FC<UserDropdownProps>","useThunderID","renderProps: UserDropdownRenderProps","UserProfile","BaseUserDropdown"],"sources":["../../../../../../src/client/components/presentation/UserDropdown/UserDropdown.tsx"],"sourcesContent":["// Copyright 2025 The ThunderID Authors\n// SPDX-License-Identifier: Apache-2.0\n\n'use client';\n\nimport {BaseUserDropdown, BaseUserDropdownProps} from '@thunderid/react';\nimport {FC, ReactElement, ReactNode, useState} from 'react';\nimport useThunderID from '../../../contexts/ThunderID/useThunderID';\nimport UserProfile from '../UserProfile/UserProfile.js';\n\n/**\n * Render props data passed to the children function\n */\nexport interface UserDropdownRenderProps {\n /** Function to close the profile dialog */\n closeProfile: () => void;\n /** Whether user data is currently loading */\n isLoading: boolean;\n /** Whether the profile dialog is currently open */\n isProfileOpen: boolean;\n /** Function to open the user profile dialog */\n openProfile: () => void;\n /** Function to sign out the user */\n signOut: () => void;\n /** The authenticated user object */\n user: any;\n}\n\n/**\n * Props for the UserDropdown component.\n * Extends BaseUserDropdownProps but excludes user, onManageProfile, and onSignOut since they're handled internally\n */\nexport type UserDropdownProps = Omit<BaseUserDropdownProps, 'user' | 'onManageProfile'> & {\n /**\n * Render prop function that receives user state and actions.\n * When provided, this completely replaces the default dropdown rendering.\n */\n children?: (props: UserDropdownRenderProps) => ReactNode;\n /**\n * Called instead of opening the built-in \"Manage Profile\" popup when the \"Manage Profile\"\n * menu item (see `manageProfileLabel`) is clicked. Use this when the app has its own\n * profile/account page it wants to navigate to instead, for example with the router's\n * `push()`.\n *\n * @example\n * ```tsx\n * <UserDropdown manageProfileLabel=\"Manage Account\" onManageProfile={() => router.push('/account')} />\n * ```\n */\n onManageProfile?: () => void;\n /**\n * Custom render function for the dropdown content.\n * When provided, this replaces just the dropdown content while keeping the trigger.\n */\n renderDropdown?: (props: UserDropdownRenderProps) => ReactNode;\n /**\n * Custom render function for the trigger button.\n * When provided, this replaces just the trigger button while keeping the dropdown.\n */\n renderTrigger?: (props: UserDropdownRenderProps) => ReactNode;\n};\n\n/**\n * UserDropdown component displays a user avatar with a dropdown menu.\n * When clicked, it shows a popover with customizable menu items.\n * This component is the React-specific implementation that uses the BaseUserDropdown\n * and automatically retrieves the user data from ThunderID context.\n *\n * Supports render props for complete customization of the dropdown appearance and behavior.\n *\n * @example\n * ```tsx\n * // Basic usage - will use user from ThunderID context\n * <UserDropdown menuItems={[\n * { label: 'Profile', onClick: () => {} },\n * { label: 'Settings', href: '/settings' },\n * { label: 'Sign Out', onClick: () => {} }\n * ]} />\n *\n * // With custom configuration\n * <UserDropdown\n * showTriggerLabel={true}\n * avatarSize={40}\n * fallback={<div>Please sign in</div>}\n * />\n *\n * // Using render props for complete customization\n * <UserDropdown>\n * {({ user, isLoading, openProfile, signOut }) => (\n * <div>\n * <button onClick={openProfile}>\n * {user?.name || 'Loading...'}\n * </button>\n * <button onClick={signOut}>Logout</button>\n * </div>\n * )}\n * </UserDropdown>\n *\n * // Using partial render props\n * <UserDropdown\n * renderTrigger={({ user, openProfile }) => (\n * <button onClick={openProfile} className=\"custom-trigger\">\n * Welcome, {user?.name}!\n * </button>\n * )}\n * />\n * ```\n */\nconst UserDropdown: FC<UserDropdownProps> = ({\n children,\n renderTrigger,\n renderDropdown,\n onManageProfile: onManageProfileOverride,\n onSignOut,\n ...rest\n}: UserDropdownProps): ReactElement => {\n const {user, isLoading, signOut} = useThunderID();\n const [isProfileOpen, setIsProfileOpen] = useState(false);\n\n const handleManageProfile = (): void => {\n if (onManageProfileOverride) {\n onManageProfileOverride();\n return;\n }\n setIsProfileOpen(true);\n };\n\n const handleSignOut = (): void => {\n signOut();\n if (onSignOut) {\n onSignOut();\n }\n };\n\n const closeProfile = (): void => {\n setIsProfileOpen(false);\n };\n\n // Prepare render props data\n const renderProps: UserDropdownRenderProps = {\n closeProfile,\n isLoading: isLoading!,\n isProfileOpen,\n openProfile: handleManageProfile,\n signOut: handleSignOut,\n user,\n };\n\n // If children render prop is provided, use it for complete customization\n if (children) {\n return (\n <>\n {children(renderProps)}\n {!onManageProfileOverride && <UserProfile mode=\"popup\" open={isProfileOpen} onOpenChange={setIsProfileOpen} />}\n </>\n );\n }\n\n // If partial render props are provided, customize specific parts\n if (renderTrigger || renderDropdown) {\n // This would require significant changes to BaseUserDropdown to support partial customization\n // For now, we'll provide a simple implementation that shows how it could work\n return (\n <>\n {renderTrigger ? (\n renderTrigger(renderProps)\n ) : (\n <BaseUserDropdown\n user={user}\n isLoading={isLoading}\n onManageProfile={handleManageProfile}\n onSignOut={handleSignOut}\n {...rest}\n />\n )}\n {/* Note: renderDropdown would need BaseUserDropdown modifications to implement properly */}\n {!onManageProfileOverride && <UserProfile mode=\"popup\" open={isProfileOpen} onOpenChange={setIsProfileOpen} />}\n </>\n );\n }\n\n // Default behavior - use BaseUserDropdown as before\n return (\n <>\n <BaseUserDropdown\n user={user}\n isLoading={isLoading}\n onManageProfile={handleManageProfile}\n onSignOut={handleSignOut}\n {...rest}\n />\n {!onManageProfileOverride && isProfileOpen && (\n <UserProfile mode=\"popup\" open={isProfileOpen} onOpenChange={setIsProfileOpen} />\n )}\n </>\n );\n};\n\nexport default UserDropdown;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,MAAMA,gBAAuC,EAC3C,UACA,eACA,gBACA,iBAAiB,yBACjB,UACA,GAAG,WACkC;CACrC,MAAM,EAAC,MAAM,WAAW,YAAWC,8BAAc;CACjD,MAAM,CAAC,eAAe,wCAA6B,MAAM;CAEzD,MAAM,4BAAkC;AACtC,MAAI,yBAAyB;AAC3B,4BAAyB;AACzB;;AAEF,mBAAiB,KAAK;;CAGxB,MAAM,sBAA4B;AAChC,WAAS;AACT,MAAI,UACF,YAAW;;CAIf,MAAM,qBAA2B;AAC/B,mBAAiB,MAAM;;CAIzB,MAAMC,cAAuC;EAC3C;EACW;EACX;EACA,aAAa;EACb,SAAS;EACT;EACD;AAGD,KAAI,SACF,QACE,qFACG,SAAS,YAAY,EACrB,CAAC,2BAA2B,2CAACC;EAAY,MAAK;EAAQ,MAAM;EAAe,cAAc;GAAoB,IAC7G;AAKP,KAAI,iBAAiB,eAGnB,QACE,qFACG,gBACC,cAAc,YAAY,GAE1B,2CAACC;EACO;EACK;EACX,iBAAiB;EACjB,WAAW;EACX,GAAI;GACJ,EAGH,CAAC,2BAA2B,2CAACD;EAAY,MAAK;EAAQ,MAAM;EAAe,cAAc;GAAoB,IAC7G;AAKP,QACE,qFACE,2CAACC;EACO;EACK;EACX,iBAAiB;EACjB,WAAW;EACX,GAAI;GACJ,EACD,CAAC,2BAA2B,iBAC3B,2CAACD;EAAY,MAAK;EAAQ,MAAM;EAAe,cAAc;GAAoB,IAElF;;AAIP,2BAAe"}
@@ -41,14 +41,13 @@ const ThunderIDClientProvider = ({ baseUrl, children, signIn, clearSession, refr
41
41
  try {
42
42
  const code = searchParams.get("code");
43
43
  const state = searchParams.get("state");
44
- const sessionState = searchParams.get("session_state");
45
44
  if (searchParams.get("error")) {
46
45
  require_logger.default.error("[ThunderIDClientProvider] An error was received for the initiated sign-in request.");
47
46
  return;
48
47
  }
49
48
  if (code && state) {
50
49
  setIsLoading(true);
51
- const result = await handleOAuthCallback(code, state, sessionState || void 0);
50
+ const result = await handleOAuthCallback(code, state);
52
51
  if (result.success) if (result.redirectUrl) router.push(result.redirectUrl);
53
52
  else window.location.reload();
54
53
  else require_logger.default.error(`[ThunderIDClientProvider] An error occurred while signing in: ${result.error || "Authentication failed"}`);
@@ -210,7 +209,7 @@ const ThunderIDClientProvider = ({ baseUrl, children, signIn, clearSession, refr
210
209
  fetchMeta,
211
210
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__thunderid_react.ThemeProvider, {
212
211
  theme: preferences?.theme?.overrides,
213
- mode: (0, __thunderid_react.getActiveTheme)(preferences?.theme?.mode),
212
+ mode: preferences?.theme?.mode,
214
213
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__thunderid_react.FlowProvider, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__thunderid_react.UserProvider, {
215
214
  profile: userProfile,
216
215
  userSchema,