@asgardeo/nuxt 0.0.0 → 0.1.0-alpha.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 (119) hide show
  1. package/README.md +482 -6
  2. package/dist/module.d.mts +17 -24
  3. package/dist/module.json +2 -2
  4. package/dist/module.mjs +174 -48
  5. package/dist/runtime/components/AsgardeoRoot.d.ts +52 -0
  6. package/dist/runtime/components/AsgardeoRoot.js +160 -0
  7. package/dist/runtime/components/actions/SignInButton.d.ts +37 -0
  8. package/dist/runtime/components/actions/SignInButton.js +51 -0
  9. package/dist/runtime/components/actions/SignOutButton.d.ts +34 -0
  10. package/dist/runtime/components/actions/SignOutButton.js +43 -0
  11. package/dist/runtime/components/actions/SignUpButton.d.ts +33 -0
  12. package/dist/runtime/components/actions/SignUpButton.js +48 -0
  13. package/dist/runtime/components/auth/Callback.d.ts +43 -0
  14. package/dist/runtime/components/auth/Callback.js +93 -0
  15. package/dist/runtime/components/auth/SignIn.d.ts +38 -0
  16. package/dist/runtime/components/auth/SignIn.js +60 -0
  17. package/dist/runtime/components/auth/SignUp.d.ts +40 -0
  18. package/dist/runtime/components/auth/SignUp.js +79 -0
  19. package/dist/runtime/components/control/Loading.d.ts +36 -0
  20. package/dist/runtime/components/control/Loading.js +17 -0
  21. package/dist/runtime/components/control/SignedIn.d.ts +38 -0
  22. package/dist/runtime/components/control/SignedIn.js +17 -0
  23. package/dist/runtime/components/control/SignedOut.d.ts +37 -0
  24. package/dist/runtime/components/control/SignedOut.js +17 -0
  25. package/dist/runtime/components/organization/CreateOrganization.d.ts +32 -0
  26. package/dist/runtime/components/organization/CreateOrganization.js +29 -0
  27. package/dist/runtime/components/organization/Organization.d.ts +39 -0
  28. package/dist/runtime/components/organization/Organization.js +17 -0
  29. package/dist/runtime/components/organization/OrganizationList.d.ts +34 -0
  30. package/dist/runtime/components/organization/OrganizationList.js +30 -0
  31. package/dist/runtime/components/organization/OrganizationProfile.d.ts +32 -0
  32. package/dist/runtime/components/organization/OrganizationProfile.js +32 -0
  33. package/dist/runtime/components/organization/OrganizationSwitcher.d.ts +36 -0
  34. package/dist/runtime/components/organization/OrganizationSwitcher.js +26 -0
  35. package/dist/runtime/components/user/User.d.ts +38 -0
  36. package/dist/runtime/components/user/User.js +17 -0
  37. package/dist/runtime/components/user/UserDropdown.d.ts +38 -0
  38. package/dist/runtime/components/user/UserDropdown.js +45 -0
  39. package/dist/runtime/components/user/UserProfile.d.ts +35 -0
  40. package/dist/runtime/components/user/UserProfile.js +35 -0
  41. package/dist/runtime/composables/useAsgardeo.d.ts +38 -0
  42. package/dist/runtime/composables/useAsgardeo.js +73 -0
  43. package/dist/runtime/errors/asgardeo-error.d.ts +47 -0
  44. package/dist/runtime/errors/asgardeo-error.js +15 -0
  45. package/dist/runtime/errors/error-codes.d.ts +40 -0
  46. package/dist/runtime/errors/error-codes.js +19 -0
  47. package/dist/runtime/{composables/asgardeo/useAuth.d.ts → errors/index.d.ts} +2 -2
  48. package/dist/runtime/errors/index.js +2 -0
  49. package/dist/runtime/middleware/auth.d.ts +35 -0
  50. package/dist/runtime/middleware/auth.js +2 -0
  51. package/dist/runtime/middleware/defineAsgardeoMiddleware.d.ts +53 -0
  52. package/dist/runtime/middleware/defineAsgardeoMiddleware.js +24 -0
  53. package/dist/runtime/plugins/asgardeo.d.ts +40 -0
  54. package/dist/runtime/plugins/asgardeo.js +129 -0
  55. package/dist/runtime/server/AsgardeoNuxtClient.d.ts +182 -0
  56. package/dist/runtime/server/AsgardeoNuxtClient.js +366 -0
  57. package/dist/runtime/server/index.d.ts +33 -0
  58. package/dist/runtime/server/index.js +3 -0
  59. package/dist/runtime/server/plugins/asgardeo-ssr.d.ts +41 -0
  60. package/dist/runtime/server/plugins/asgardeo-ssr.js +134 -0
  61. package/dist/runtime/server/routes/auth/branding/branding.get.d.ts +31 -0
  62. package/dist/runtime/server/routes/auth/branding/branding.get.js +40 -0
  63. package/dist/runtime/server/routes/auth/organizations/current.get.d.ts +29 -0
  64. package/dist/runtime/server/routes/auth/organizations/current.get.js +24 -0
  65. package/dist/runtime/server/routes/auth/organizations/id.get.d.ts +28 -0
  66. package/dist/runtime/server/routes/auth/organizations/id.get.js +28 -0
  67. package/dist/runtime/server/routes/auth/organizations/index.get.d.ts +28 -0
  68. package/dist/runtime/server/routes/auth/organizations/index.get.js +24 -0
  69. package/dist/runtime/server/routes/auth/organizations/index.post.d.ts +30 -0
  70. package/dist/runtime/server/routes/auth/organizations/index.post.js +30 -0
  71. package/dist/runtime/server/routes/auth/organizations/me.get.d.ts +28 -0
  72. package/dist/runtime/server/routes/auth/organizations/me.get.js +24 -0
  73. package/dist/runtime/server/routes/auth/organizations/switch.post.d.ts +32 -0
  74. package/dist/runtime/server/routes/auth/organizations/switch.post.js +49 -0
  75. package/dist/runtime/server/routes/auth/session/callback.get.d.ts +27 -0
  76. package/dist/runtime/server/routes/auth/session/callback.get.js +91 -0
  77. package/dist/runtime/server/routes/auth/session/callback.post.d.ts +48 -0
  78. package/dist/runtime/server/routes/auth/session/callback.post.js +53 -0
  79. package/dist/runtime/server/routes/auth/session/session.get.d.ts +26 -0
  80. package/dist/runtime/server/routes/auth/session/session.get.js +22 -0
  81. package/dist/runtime/server/routes/auth/session/signin.get.d.ts +29 -0
  82. package/dist/runtime/server/routes/auth/session/signin.get.js +37 -0
  83. package/dist/runtime/server/routes/auth/session/signin.post.d.ts +37 -0
  84. package/dist/runtime/server/routes/auth/session/signin.post.js +102 -0
  85. package/dist/runtime/server/routes/auth/session/signout.post.d.ts +31 -0
  86. package/dist/runtime/server/routes/auth/session/signout.post.js +38 -0
  87. package/dist/runtime/server/routes/auth/session/signup.post.d.ts +36 -0
  88. package/dist/runtime/server/routes/auth/session/signup.post.js +30 -0
  89. package/dist/runtime/server/routes/auth/session/token.get.d.ts +29 -0
  90. package/dist/runtime/server/routes/auth/session/token.get.js +6 -0
  91. package/dist/runtime/server/routes/auth/user/profile.get.d.ts +29 -0
  92. package/dist/runtime/server/routes/auth/user/profile.get.js +24 -0
  93. package/dist/runtime/server/{handler.d.ts → routes/auth/user/profile.patch.d.ts} +17 -13
  94. package/dist/runtime/server/routes/auth/user/profile.patch.js +33 -0
  95. package/dist/runtime/server/{services/asgardeo/index.d.ts → routes/auth/user/user.get.d.ts} +6 -4
  96. package/dist/runtime/server/routes/auth/user/user.get.js +21 -0
  97. package/dist/runtime/server/utils/event-context.d.ts +49 -0
  98. package/dist/runtime/server/utils/event-context.js +3 -0
  99. package/dist/runtime/server/utils/serverSession.d.ts +65 -0
  100. package/dist/runtime/server/utils/serverSession.js +44 -0
  101. package/dist/runtime/server/utils/session.d.ts +85 -0
  102. package/dist/runtime/server/utils/session.js +106 -0
  103. package/dist/runtime/server/utils/token-refresh.d.ts +42 -0
  104. package/dist/runtime/server/utils/token-refresh.js +65 -0
  105. package/dist/runtime/types/augments.d.ts +61 -0
  106. package/dist/runtime/types.d.ts +115 -38
  107. package/dist/runtime/utils/createRouteMatcher.d.ts +40 -0
  108. package/dist/runtime/utils/createRouteMatcher.js +7 -0
  109. package/dist/runtime/utils/index.d.ts +30 -0
  110. package/dist/runtime/utils/index.js +1 -0
  111. package/dist/runtime/utils/log.d.ts +44 -0
  112. package/dist/runtime/utils/log.js +25 -0
  113. package/dist/runtime/utils/url-validation.d.ts +49 -0
  114. package/dist/runtime/utils/url-validation.js +38 -0
  115. package/dist/types.d.mts +0 -2
  116. package/package.json +48 -23
  117. package/dist/runtime/composables/asgardeo/useAuth.js +0 -129
  118. package/dist/runtime/server/handler.js +0 -231
  119. package/dist/runtime/server/services/asgardeo/index.js +0 -18
@@ -15,5 +15,5 @@
15
15
  * specific language governing permissions and limitations
16
16
  * under the License.
17
17
  */
18
- import type { AuthInterface } from '../../types.js';
19
- export declare const useAuth: () => AuthInterface;
18
+ export { AsgardeoError } from './asgardeo-error.js';
19
+ export { ErrorCode } from './error-codes.js';
@@ -0,0 +1,2 @@
1
+ export { AsgardeoError } from "./asgardeo-error.js";
2
+ export { ErrorCode } from "./error-codes.js";
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ /**
19
+ * Named route middleware for protecting pages.
20
+ *
21
+ * Registered under the name `'auth'` by the Nuxt module, so pages can
22
+ * opt in by string reference:
23
+ *
24
+ * ```vue
25
+ * <script setup>
26
+ * definePageMeta({ middleware: ['auth'] });
27
+ * </script>
28
+ * ```
29
+ *
30
+ * Equivalent to `defineAsgardeoMiddleware()` with no options: redirects
31
+ * unauthenticated users to `/api/auth/signin?returnTo=<path>`. For scope
32
+ * or organization gating, use `defineAsgardeoMiddleware({ ... })` directly.
33
+ */
34
+ declare const _default: import("#app").RouteMiddleware;
35
+ export default _default;
@@ -0,0 +1,2 @@
1
+ import { defineAsgardeoMiddleware } from "./defineAsgardeoMiddleware.js";
2
+ export default defineAsgardeoMiddleware();
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { defineNuxtRouteMiddleware } from '#app';
19
+ export interface AsgardeoMiddlewareOptions {
20
+ /**
21
+ * The path to redirect unauthenticated (or unauthorised) requests to.
22
+ * Defaults to `'/api/auth/signin'`.
23
+ */
24
+ redirectTo?: string;
25
+ /**
26
+ * If `true`, the middleware will also require that the user has an
27
+ * `organizationId` in their session. Redirects to `redirectTo` if not.
28
+ */
29
+ requireOrganization?: boolean;
30
+ /**
31
+ * Required OAuth scopes. The middleware checks that every listed scope
32
+ * is present in the session before allowing access.
33
+ */
34
+ requireScopes?: string[];
35
+ }
36
+ /**
37
+ * Typed factory for Asgardeo route middleware.
38
+ *
39
+ * Usage in a page component:
40
+ * ```vue
41
+ * <script setup>
42
+ * definePageMeta({
43
+ * middleware: [defineAsgardeoMiddleware({ requireOrganization: true })]
44
+ * });
45
+ * </script>
46
+ * ```
47
+ *
48
+ * Or add it as a named middleware in `middleware/` and reference by name.
49
+ *
50
+ * The built-in `'auth'` middleware registered by this module is equivalent
51
+ * to calling `defineAsgardeoMiddleware()` with no options.
52
+ */
53
+ export declare function defineAsgardeoMiddleware(options?: AsgardeoMiddlewareOptions): ReturnType<typeof defineNuxtRouteMiddleware>;
@@ -0,0 +1,24 @@
1
+ import { defineNuxtRouteMiddleware, navigateTo, useState } from "#app";
2
+ const DEFAULT_REDIRECT_TO = "/api/auth/signin";
3
+ export function defineAsgardeoMiddleware(options = {}) {
4
+ const { redirectTo = DEFAULT_REDIRECT_TO, requireOrganization = false, requireScopes = [] } = options;
5
+ return defineNuxtRouteMiddleware((to) => {
6
+ const authState = useState("asgardeo:auth");
7
+ if (!authState.value?.isSignedIn) {
8
+ const returnTo = encodeURIComponent(to.fullPath);
9
+ return navigateTo(`${redirectTo}?returnTo=${returnTo}`, { external: true });
10
+ }
11
+ const user = authState.value.user;
12
+ if (requireOrganization && !user?.["organizationId"]) {
13
+ return navigateTo(redirectTo, { external: true });
14
+ }
15
+ if (requireScopes.length > 0) {
16
+ const sessionScopes = String(user?.["scopes"] ?? "").split(" ");
17
+ const hasAllScopes = requireScopes.every((s) => sessionScopes.includes(s));
18
+ if (!hasAllScopes) {
19
+ return navigateTo(redirectTo, { external: true });
20
+ }
21
+ }
22
+ return void 0;
23
+ });
24
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import '../types/augments.d.js';
19
+ /**
20
+ * Universal Nuxt plugin (runs on both server and client) that wires up the
21
+ * Asgardeo Vue SDK.
22
+ *
23
+ * Responsibilities — mirrors the split between `AsgardeoServerProvider` and
24
+ * `AsgardeoClientProvider` in the Next.js SDK:
25
+ *
26
+ * 1. **Auth state** — hydrate `useState('asgardeo:auth')` from the Nitro
27
+ * plugin's `event.context.asgardeo` so SSR and client agree on signed-in
28
+ * status and the user object.
29
+ * 2. **ASGARDEO_KEY** — provide the primary auth context at the app level.
30
+ * Action helpers (`signIn` / `signOut` / `signUp`) use Nuxt's
31
+ * `navigateTo` so redirects work on both server and client.
32
+ * 3. **AsgardeoRoot** — register the wrapper component that mounts the rest
33
+ * of the provider tree (`I18nProvider`, `BrandingProvider`,
34
+ * `ThemeProvider`, `FlowProvider`, `UserProvider`, `OrganizationProvider`)
35
+ * so downstream composables receive real context values.
36
+ * 4. **AsgardeoPlugin (delegated)** — install the Vue SDK plugin in
37
+ * delegated mode so it skips browser-only initialisation (SSR-safe).
38
+ */
39
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
40
+ export default _default;
@@ -0,0 +1,129 @@
1
+ import { getRedirectBasedSignUpUrl } from "@asgardeo/browser";
2
+ import { AsgardeoPlugin, ASGARDEO_KEY } from "@asgardeo/vue";
3
+ import { computed } from "vue";
4
+ import AsgardeoRoot from "../components/AsgardeoRoot.js";
5
+ import { defineNuxtPlugin, useState, useRequestEvent, useRuntimeConfig, navigateTo } from "#app";
6
+ import "../types/augments.d";
7
+ export default defineNuxtPlugin((nuxtApp) => {
8
+ const publicConfig = useRuntimeConfig().public.asgardeo;
9
+ if (import.meta.client && import.meta.dev) {
10
+ if (!publicConfig?.baseUrl || !publicConfig?.clientId) {
11
+ console.warn(
12
+ "[@asgardeo/nuxt] Missing baseUrl or clientId. Set NUXT_PUBLIC_ASGARDEO_BASE_URL and NUXT_PUBLIC_ASGARDEO_CLIENT_ID, or configure `asgardeo` in nuxt.config. Auth endpoints will not function until this is resolved."
13
+ );
14
+ }
15
+ }
16
+ const authState = useState("asgardeo:auth", () => ({
17
+ isLoading: true,
18
+ isSignedIn: false,
19
+ user: null
20
+ }));
21
+ const userProfileState = useState("asgardeo:user-profile", () => null);
22
+ const currentOrgState = useState("asgardeo:current-org", () => null);
23
+ const myOrgsState = useState("asgardeo:my-orgs", () => []);
24
+ const brandingState = useState(
25
+ "asgardeo:branding",
26
+ () => null
27
+ );
28
+ if (import.meta.server) {
29
+ const event = useRequestEvent();
30
+ const ssr = event?.context?.asgardeo?.ssr;
31
+ if (ssr) {
32
+ authState.value = {
33
+ isLoading: false,
34
+ isSignedIn: ssr.isSignedIn,
35
+ user: ssr.user
36
+ };
37
+ userProfileState.value = ssr.userProfile;
38
+ currentOrgState.value = ssr.currentOrganization;
39
+ myOrgsState.value = ssr.myOrganizations;
40
+ brandingState.value = ssr.brandingPreference;
41
+ } else {
42
+ const ssrContext = event?.context?.asgardeo;
43
+ if (ssrContext) {
44
+ authState.value = {
45
+ isLoading: false,
46
+ isSignedIn: ssrContext.isSignedIn ?? false,
47
+ user: ssrContext.session?.sub ? { sub: ssrContext.session.sub } : null
48
+ };
49
+ } else {
50
+ const legacyAuth = event?.context?.["__asgardeoAuth"];
51
+ authState.value = legacyAuth ?? { isLoading: false, isSignedIn: false, user: null };
52
+ }
53
+ }
54
+ }
55
+ if (import.meta.client) {
56
+ authState.value = { ...authState.value, isLoading: false };
57
+ }
58
+ const isSignedIn = computed(() => authState.value.isSignedIn);
59
+ const isLoading = computed(() => authState.value.isLoading);
60
+ const isInitialized = computed(() => !authState.value.isLoading);
61
+ const user = computed(() => authState.value.user ?? null);
62
+ const organizationRef = computed(() => currentOrgState.value);
63
+ const signIn = async (options) => {
64
+ const returnTo = typeof options?.["returnTo"] === "string" ? options["returnTo"] : void 0;
65
+ const url = returnTo ? `/api/auth/signin?returnTo=${encodeURIComponent(returnTo)}` : "/api/auth/signin";
66
+ await navigateTo(url, { external: true });
67
+ };
68
+ const signOut = async () => {
69
+ const res = await $fetch("/api/auth/signout", { method: "POST" });
70
+ await navigateTo(res.redirectUrl || "/", { external: true });
71
+ };
72
+ const signUp = async () => {
73
+ if (publicConfig.signUpUrl) {
74
+ await navigateTo(publicConfig.signUpUrl, { external: true });
75
+ return;
76
+ }
77
+ const redirectUrl = getRedirectBasedSignUpUrl({
78
+ applicationId: publicConfig.applicationId,
79
+ baseUrl: publicConfig.baseUrl,
80
+ clientId: publicConfig.clientId
81
+ });
82
+ if (redirectUrl) {
83
+ await navigateTo(redirectUrl, { external: true });
84
+ return;
85
+ }
86
+ await navigateTo("/api/auth/signup", { external: true });
87
+ };
88
+ const getAccessToken = async () => {
89
+ try {
90
+ const res = await $fetch("/api/auth/token");
91
+ return res.accessToken ?? "";
92
+ } catch {
93
+ return "";
94
+ }
95
+ };
96
+ const noop = async () => void 0;
97
+ nuxtApp.vueApp.provide(ASGARDEO_KEY, {
98
+ afterSignInUrl: publicConfig.afterSignInUrl,
99
+ applicationId: publicConfig.applicationId,
100
+ baseUrl: publicConfig.baseUrl,
101
+ clearSession: noop,
102
+ clientId: publicConfig.clientId,
103
+ exchangeToken: noop,
104
+ getAccessToken,
105
+ getDecodedIdToken: noop,
106
+ getIdToken: noop,
107
+ http: { request: noop, requestAll: noop },
108
+ instanceId: 0,
109
+ isInitialized,
110
+ isLoading,
111
+ isSignedIn,
112
+ organization: organizationRef,
113
+ organizationHandle: publicConfig.organizationHandle,
114
+ platform: void 0,
115
+ reInitialize: async () => false,
116
+ signIn,
117
+ signInOptions: void 0,
118
+ signInSilently: noop,
119
+ signInUrl: publicConfig.signInUrl,
120
+ signOut,
121
+ signUp,
122
+ signUpUrl: publicConfig.signUpUrl,
123
+ storage: void 0,
124
+ switchOrganization: noop,
125
+ user
126
+ });
127
+ nuxtApp.vueApp.component("AsgardeoRoot", AsgardeoRoot);
128
+ nuxtApp.vueApp.use(AsgardeoPlugin, { mode: "delegated" });
129
+ });
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3
+ *
4
+ * WSO2 LLC. licenses this file to you under the Apache License,
5
+ * Version 2.0 (the "License"); you may not use this file except
6
+ * in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing,
12
+ * software distributed under the License is distributed on an
13
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ * KIND, either express or implied. See the License for the
15
+ * specific language governing permissions and limitations
16
+ * under the License.
17
+ */
18
+ import { AsgardeoNodeClient, type IdToken, type Organization, type OrganizationDetails, type CreateOrganizationPayload, type Storage, type TokenExchangeRequestConfig, type TokenResponse, type User, type UserProfile, type UpdateMeProfileConfig, type AllOrganizationsApiResponse, type GetBrandingPreferenceConfig, type BrandingPreference, type EmbeddedFlowExecuteRequestPayload, type EmbeddedFlowExecuteResponse, type ExtendedAuthorizeRequestUrlParams, type SignUpOptions } from '@asgardeo/node';
19
+ import type { AsgardeoNuxtConfig, AsgardeoSessionPayload } from '../types.js';
20
+ /**
21
+ * Singleton Asgardeo client for Nuxt applications.
22
+ *
23
+ * Mirrors the {@link AsgardeoNextClient} pattern: a single shared instance per
24
+ * server process that delegates OAuth/OIDC operations to an internal
25
+ * {@link LegacyAsgardeoNodeClient}. The legacy client provisions its own default
26
+ * in-memory store (`MemoryCacheStore`) for PKCE state and tokens so that state
27
+ * persists across the sign-in → callback boundary.
28
+ *
29
+ * Consumers call {@link getInstance} directly from server routes and plugins —
30
+ * there is no per-request wrapper factory. Initialization happens once per
31
+ * process (guarded by {@link isInitialized}) from the `asgardeo-init` Nitro
32
+ * plugin on the first request.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * // In a Nitro API route:
37
+ * export default defineEventHandler(async (event) => {
38
+ * const client = AsgardeoNuxtClient.getInstance();
39
+ * return client.getUser(sessionId);
40
+ * });
41
+ * ```
42
+ */
43
+ declare class AsgardeoNuxtClient extends AsgardeoNodeClient<AsgardeoNuxtConfig> {
44
+ private static instance;
45
+ private legacy;
46
+ isInitialized: boolean;
47
+ private constructor();
48
+ /**
49
+ * Get the singleton instance of AsgardeoNuxtClient.
50
+ */
51
+ static getInstance(): AsgardeoNuxtClient;
52
+ /**
53
+ * Initializes the underlying legacy client with OAuth/OIDC settings derived
54
+ * from the Nuxt module config. Idempotent — repeated calls are no-ops after
55
+ * the first successful initialization.
56
+ */
57
+ initialize(config: AsgardeoNuxtConfig, storage?: Storage): Promise<boolean>;
58
+ reInitialize(config: Partial<AsgardeoNuxtConfig>): Promise<boolean>;
59
+ /**
60
+ * Seeds the legacy in-memory token store from a verified session JWT payload.
61
+ *
62
+ * The signed session cookie is the source of truth for tokens in this SDK — it
63
+ * survives server restarts and new worker processes. The underlying
64
+ * {@link LegacyAsgardeoNodeClient}, however, keeps tokens in a
65
+ * {@link MemoryCacheStore} keyed by `sessionId`, and its
66
+ * `getAccessToken` / `getUser` / `getDecodedIdToken` / `signOut` paths all
67
+ * read from that store. Without rehydration, those calls fail whenever the
68
+ * in-memory store and the cookie diverge (the classic case: `nuxi dev`
69
+ * restart while the browser still holds a valid session cookie).
70
+ *
71
+ * Writes the snake_case token shape the legacy helper expects
72
+ * (see `AuthenticationHelper.processTokenResponse`). Safe to call on every
73
+ * request — it's an in-memory write and the cookie always reflects the
74
+ * freshest tokens (the refresh path re-issues the cookie too).
75
+ */
76
+ rehydrateSessionFromPayload(session: AsgardeoSessionPayload): Promise<void>;
77
+ /**
78
+ * Initiates the authorization code flow, handles an embedded sign-in step,
79
+ * or exchanges a code for tokens.
80
+ *
81
+ * Overload 1 — **redirect-flow** (existing callers like `signin.get.ts`):
82
+ * ```
83
+ * signIn(authURLCallback, sessionId, code?, sessionState?, state?, config?)
84
+ * ```
85
+ * Overload 2 — **embedded flow initiate** (flowId === ''):
86
+ * ```
87
+ * signIn({flowId: ''}, request, sessionId)
88
+ * ```
89
+ * Dispatches to `initializeEmbeddedSignInFlow`.
90
+ *
91
+ * Overload 3 — **embedded flow execute** (flowId set):
92
+ * ```
93
+ * signIn(payload, request, sessionId)
94
+ * ```
95
+ * Dispatches to `executeEmbeddedSignInFlow`.
96
+ *
97
+ * Overload 4 — **code exchange** (completion after embedded flow):
98
+ * ```
99
+ * signIn({code, state, session_state}, {}, sessionId)
100
+ * ```
101
+ * Falls through to the legacy redirect-flow code-exchange path.
102
+ */
103
+ signIn(...args: any[]): Promise<any>;
104
+ /**
105
+ * Executes the embedded sign-up flow step.
106
+ * Mirrors `AsgardeoNextClient.signUp` with an `EmbeddedFlowExecuteRequestPayload`.
107
+ */
108
+ signUp(options?: SignUpOptions): Promise<void>;
109
+ signUp(payload: EmbeddedFlowExecuteRequestPayload): Promise<EmbeddedFlowExecuteResponse>;
110
+ /**
111
+ * Returns the OAuth2 authorization URL.
112
+ * Used by the redirect-flow GET handler and the embedded-flow initiation path.
113
+ *
114
+ * Mirrors `AsgardeoNextClient.getAuthorizeRequestUrl`.
115
+ */
116
+ getAuthorizeRequestUrl(customParams: ExtendedAuthorizeRequestUrlParams, userId?: string): Promise<string>;
117
+ /**
118
+ * Clears the session and returns the RP-Initiated Logout URL.
119
+ * Accepts either `(sessionId: string)` or `(options?, sessionId?, callback?)`.
120
+ */
121
+ signOut(...args: any[]): Promise<string>;
122
+ getUser(sessionId?: string): Promise<User>;
123
+ getAccessToken(sessionId?: string): Promise<string>;
124
+ /**
125
+ * Decodes and returns the ID token claims for the given session.
126
+ * Exposed here (as on {@link AsgardeoNextClient}) so route handlers can
127
+ * access ID token claims without falling back to the legacy client.
128
+ */
129
+ getDecodedIdToken(sessionId?: string, idToken?: string): Promise<IdToken>;
130
+ isSignedIn(sessionId?: string): Promise<boolean>;
131
+ exchangeToken(config: TokenExchangeRequestConfig, sessionId?: string): Promise<TokenResponse | Response>;
132
+ /**
133
+ * Fetches the flattened SCIM2 user profile for the given session.
134
+ * Mirrors `AsgardeoNextClient.getUserProfile` — calls `getScim2Me` +
135
+ * `getSchemas` + `generateFlattenedUserProfile` and falls back to
136
+ * `getUser` claims if SCIM2 is unavailable.
137
+ */
138
+ getUserProfile(sessionId: string): Promise<UserProfile>;
139
+ /**
140
+ * Extracts the current organisation from the decoded ID token.
141
+ * Returns null when the user is not acting within an organisation.
142
+ */
143
+ getCurrentOrganization(sessionId: string): Promise<Organization | null>;
144
+ /**
145
+ * Returns the list of organisations the authenticated user is a member of.
146
+ */
147
+ getMyOrganizations(sessionId: string): Promise<Organization[]>;
148
+ /**
149
+ * Fetches the branding preference for the tenant / application.
150
+ * Delegates to the standalone `getBrandingPreference` API helper from
151
+ * `@asgardeo/node`, which does not require an authenticated session.
152
+ */
153
+ getBrandingPreference(config: GetBrandingPreferenceConfig): Promise<BrandingPreference>;
154
+ /**
155
+ * Updates the SCIM2 /Me profile for the authenticated user.
156
+ * Mirrors `AsgardeoNextClient.updateUserProfile`.
157
+ */
158
+ updateUserProfile(config: UpdateMeProfileConfig, sessionId: string): Promise<User>;
159
+ /**
160
+ * Retrieves all organisations accessible to the authenticated user
161
+ * (paginated). Mirrors `AsgardeoNextClient.getAllOrganizations`.
162
+ */
163
+ getAllOrganizations(options?: any, sessionId?: string): Promise<AllOrganizationsApiResponse>;
164
+ /**
165
+ * Creates a new sub-organisation. Mirrors `AsgardeoNextClient.createOrganization`.
166
+ */
167
+ createOrganization(payload: CreateOrganizationPayload, sessionId: string): Promise<Organization>;
168
+ /**
169
+ * Fetches the details of a single organisation by ID.
170
+ * Mirrors `AsgardeoNextClient.getOrganization`.
171
+ */
172
+ getOrganization(organizationId: string, sessionId: string): Promise<OrganizationDetails>;
173
+ /**
174
+ * Performs an organisation-switch token exchange and returns the new
175
+ * `TokenResponse`. The caller (the Nitro route) is responsible for
176
+ * persisting the new session cookie.
177
+ *
178
+ * Mirrors `AsgardeoNextClient.switchOrganization`.
179
+ */
180
+ switchOrganization(organization: Organization, sessionId: string): Promise<TokenResponse | Response>;
181
+ }
182
+ export default AsgardeoNuxtClient;