@nodehive/nextjs 0.2.1 → 0.4.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.
- package/dist/auth/internal/draft-session.d.ts +12 -0
- package/dist/auth/internal/draft-session.js +22 -0
- package/dist/auth/internal/draft-session.js.map +1 -0
- package/dist/auth/internal/refresh.d.ts +10 -0
- package/dist/auth/internal/refresh.js +17 -0
- package/dist/auth/internal/refresh.js.map +1 -1
- package/dist/auth/internal/update-session.js +2 -1
- package/dist/auth/internal/update-session.js.map +1 -1
- package/dist/auth/server.d.ts +1 -0
- package/dist/auth/server.js +1 -0
- package/dist/auth/server.js.map +1 -1
- package/dist/smart-actions/internal/ordering.d.ts +5 -0
- package/dist/smart-actions/internal/ordering.js +16 -0
- package/dist/smart-actions/internal/ordering.js.map +1 -0
- package/dist/smart-actions/internal/smart-actions-button.d.ts +7 -12
- package/dist/smart-actions/internal/smart-actions-button.js +1 -6
- package/dist/smart-actions/internal/smart-actions-button.js.map +1 -1
- package/dist/smart-actions/internal/smart-actions-config.d.ts +4 -3
- package/dist/smart-actions/internal/smart-actions-config.js +4 -3
- package/dist/smart-actions/internal/smart-actions-config.js.map +1 -1
- package/dist/smart-actions/server.d.ts +1 -0
- package/dist/smart-actions/server.js +1 -0
- package/dist/smart-actions/server.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The predicate for the data layer's draft-vs-cached branch. The draft cookie
|
|
3
|
+
* alone is not enough: it survives its session (see clearStaleDraftCookie), and
|
|
4
|
+
* taking the draft branch without a token means fetching as a user that is not
|
|
5
|
+
* there. Without a session this returns false and the caller falls back to the
|
|
6
|
+
* cached anonymous branch, which is what the visitor gets anyway.
|
|
7
|
+
*
|
|
8
|
+
* isEnabled must stay the first operand. draftMode() is prerender-safe (false
|
|
9
|
+
* at build time) while a cookie read is not, so the short-circuit is what keeps
|
|
10
|
+
* the anonymous branch inside the static shell under cacheComponents.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isDraftSession: () => Promise<boolean>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { cache } from 'react';
|
|
2
|
+
import { draftMode } from 'next/headers';
|
|
3
|
+
import { checkHasSession } from "./has-session.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The predicate for the data layer's draft-vs-cached branch. The draft cookie
|
|
7
|
+
* alone is not enough: it survives its session (see clearStaleDraftCookie), and
|
|
8
|
+
* taking the draft branch without a token means fetching as a user that is not
|
|
9
|
+
* there. Without a session this returns false and the caller falls back to the
|
|
10
|
+
* cached anonymous branch, which is what the visitor gets anyway.
|
|
11
|
+
*
|
|
12
|
+
* isEnabled must stay the first operand. draftMode() is prerender-safe (false
|
|
13
|
+
* at build time) while a cookie read is not, so the short-circuit is what keeps
|
|
14
|
+
* the anonymous branch inside the static shell under cacheComponents.
|
|
15
|
+
*/
|
|
16
|
+
export const isDraftSession = cache(async () => {
|
|
17
|
+
const {
|
|
18
|
+
isEnabled
|
|
19
|
+
} = await draftMode();
|
|
20
|
+
return isEnabled && (await checkHasSession());
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=draft-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft-session.js","names":["cache","draftMode","checkHasSession","isDraftSession","isEnabled"],"sources":["../../../src/auth/internal/draft-session.ts"],"sourcesContent":["import { cache } from 'react';\nimport { draftMode } from 'next/headers';\n\nimport { checkHasSession } from './has-session.ts';\n\n/**\n * The predicate for the data layer's draft-vs-cached branch. The draft cookie\n * alone is not enough: it survives its session (see clearStaleDraftCookie), and\n * taking the draft branch without a token means fetching as a user that is not\n * there. Without a session this returns false and the caller falls back to the\n * cached anonymous branch, which is what the visitor gets anyway.\n *\n * isEnabled must stay the first operand. draftMode() is prerender-safe (false\n * at build time) while a cookie read is not, so the short-circuit is what keeps\n * the anonymous branch inside the static shell under cacheComponents.\n */\nexport const isDraftSession = cache(async (): Promise<boolean> => {\n const { isEnabled } = await draftMode();\n return isEnabled && (await checkHasSession());\n});\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,OAAO;AAC7B,SAASC,SAAS,QAAQ,cAAc;AAExC,SAASC,eAAe,QAAQ,kBAAkB;;AAElD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,cAAc,GAAGH,KAAK,CAAC,YAA8B;EAChE,MAAM;IAAEI;EAAU,CAAC,GAAG,MAAMH,SAAS,CAAC,CAAC;EACvC,OAAOG,SAAS,KAAK,MAAMF,eAAe,CAAC,CAAC,CAAC;AAC/C,CAAC,CAAC","ignoreList":[]}
|
|
@@ -9,4 +9,14 @@ export declare function shouldRefreshSession(request: NextRequest): boolean;
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function refreshSession(request: NextRequest, response: NextResponse, config: NodeHiveAuthConfig): Promise<void>;
|
|
11
11
|
export declare function clearAuthCookies(request: NextRequest, response: NextResponse): void;
|
|
12
|
+
/**
|
|
13
|
+
* clearAuthCookies takes the draft cookie down with the session, but it only
|
|
14
|
+
* runs once a refresh was attempted and rejected. When the refresh-token cookie
|
|
15
|
+
* is simply gone there is nothing to refresh, shouldRefreshSession bails out,
|
|
16
|
+
* and a draft cookie from an earlier login outlives its session — it is set for
|
|
17
|
+
* the full refresh-token lifetime, so this can last weeks. The data layer then
|
|
18
|
+
* reads draftMode() as enabled and fetches with a user client that has no
|
|
19
|
+
* token, which is answered with Drupal's HTML error pages.
|
|
20
|
+
*/
|
|
21
|
+
export declare function clearStaleDraftCookie(request: NextRequest, response: NextResponse): void;
|
|
12
22
|
export declare function isAuthFailure(error: unknown): boolean;
|
|
@@ -93,6 +93,23 @@ export function clearAuthCookies(request, response) {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
/**
|
|
97
|
+
* clearAuthCookies takes the draft cookie down with the session, but it only
|
|
98
|
+
* runs once a refresh was attempted and rejected. When the refresh-token cookie
|
|
99
|
+
* is simply gone there is nothing to refresh, shouldRefreshSession bails out,
|
|
100
|
+
* and a draft cookie from an earlier login outlives its session — it is set for
|
|
101
|
+
* the full refresh-token lifetime, so this can last weeks. The data layer then
|
|
102
|
+
* reads draftMode() as enabled and fetches with a user client that has no
|
|
103
|
+
* token, which is answered with Drupal's HTML error pages.
|
|
104
|
+
*/
|
|
105
|
+
export function clearStaleDraftCookie(request, response) {
|
|
106
|
+
const keys = NextCookieStorage.cookieKeys();
|
|
107
|
+
if (request.cookies.get(keys.refresh_token)) return;
|
|
108
|
+
if (!request.cookies.get(DRAFT_MODE_COOKIE)) return;
|
|
109
|
+
request.cookies.delete(DRAFT_MODE_COOKIE);
|
|
110
|
+
appendClearedAuthCookie(response, DRAFT_MODE_COOKIE);
|
|
111
|
+
}
|
|
112
|
+
|
|
96
113
|
// Auth failure (invalid/expired refresh token) vs transient (network, timeout,
|
|
97
114
|
// 5xx): transient errors keep the session, auth failures clear it.
|
|
98
115
|
export function isAuthFailure(error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh.js","names":["AuthenticationError","DRAFT_MODE_COOKIE","appendClearedAuthCookie","NextCookieStorage","buildUserClient","REFRESH_TOKEN_MAX_AGE","MAX_RETRIES","BACKOFF_MS","ROTATION_GRACE_MS","refreshDeadlineMs","setRefreshDeadlineMsForTesting","ms","wait","Promise","resolve","setTimeout","withDeadline","promise","race","_","reject","timer","Error","unref","activeRefreshes","Map","recentRotations","rememberRotation","oldToken","result","expiresAt","Date","now","set","delete","getRecentRotation","entry","get","console","info","shouldRefreshSession","request","keys","cookieKeys","token","cookies","value","refreshToken","refresh_token","token_expires_at","expiresAtNumber","Number","tokenExpiresSoon","isFinite","refreshSession","response","config","refreshOnce","clearAuthCookies","name","Object","values","isAuthFailure","error","status","details","applyLoginResult","context","storage","maxAge","expires_in","undefined","tokenOptions","String","user","JSON","stringify","recent","existing","then","client","underlying","refreshWithRetries","finally","lastError","attempt","auth","warn"],"sources":["../../../src/auth/internal/refresh.ts"],"sourcesContent":["import type { NextRequest, NextResponse } from 'next/server';\nimport { AuthenticationError, type LoginResult } from 'nodehive-js';\n\nimport type { NodeHiveAuthConfig } from './config.ts';\nimport { DRAFT_MODE_COOKIE } from './draft-mode.ts';\nimport {\n appendClearedAuthCookie,\n NextCookieStorage,\n type ProxyContext,\n} from './next-cookie-storage.ts';\nimport { buildUserClient } from './nodehive-client.ts';\nimport { REFRESH_TOKEN_MAX_AGE } from './oauth-config.ts';\n\nconst MAX_RETRIES = 3;\nconst BACKOFF_MS = 200;\nconst ROTATION_GRACE_MS = 30_000;\n// Hard ceiling for a whole refresh (incl. retries). The proxy awaits this on\n// nearly every request, and the SDK's token fetch has no timeout of its own, so\n// without this a slow/hung Drupal would stall every page load. On timeout the\n// error is non-auth → treated as transient → the stale session is kept.\nlet refreshDeadlineMs = 5_000;\n\nexport function setRefreshDeadlineMsForTesting(ms: number) {\n refreshDeadlineMs = ms;\n}\n\nconst wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n\nfunction withDeadline<T>(promise: Promise<T>, ms: number): Promise<T> {\n return Promise.race([\n promise,\n new Promise<T>((_, reject) => {\n const timer = setTimeout(\n () => reject(new Error('Token refresh timed out')),\n ms\n );\n timer.unref?.();\n }),\n ]);\n}\n\n// Per-user dedup: prevents concurrent requests from racing on token rotation.\n// Note: This Map is per-isolate — on serverless deployments, dedup is best-effort\n// and not guaranteed across concurrent isolates. On long-running servers it works fully.\nconst activeRefreshes = new Map<string, Promise<LoginResult>>();\n\n// Grace cache for recently rotated refresh tokens.\n//\n// OAuth refresh tokens are single-use: each successful refresh invalidates the\n// previous one. But the browser can have parallel requests in flight carrying\n// the old refresh-token cookie when the rotation happens. Without this cache,\n// stale requests arriving just AFTER the original refresh completed (so the\n// `activeRefreshes` dedup map is already empty) trigger a second refresh that\n// fails with invalid_grant and logs the user out.\n//\n// Mapping: old refresh_token → fresh LoginResult, valid for ROTATION_GRACE_MS.\nconst recentRotations = new Map<\n string,\n { result: LoginResult; expiresAt: number }\n>();\n\nfunction rememberRotation(oldToken: string, result: LoginResult) {\n const expiresAt = Date.now() + ROTATION_GRACE_MS;\n recentRotations.set(oldToken, { result, expiresAt });\n setTimeout(\n () => recentRotations.delete(oldToken),\n ROTATION_GRACE_MS\n ).unref?.();\n}\n\nfunction getRecentRotation(oldToken: string): LoginResult | null {\n const entry = recentRotations.get(oldToken);\n if (!entry) return null;\n if (entry.expiresAt < Date.now()) {\n recentRotations.delete(oldToken);\n return null;\n }\n console.info('[Refresh] grace cache hit — stale refresh-token reused');\n return entry.result;\n}\n\nexport function shouldRefreshSession(request: NextRequest): boolean {\n const keys = NextCookieStorage.cookieKeys();\n const token = request.cookies.get(keys.token)?.value;\n const refreshToken = request.cookies.get(keys.refresh_token)?.value;\n const expiresAt = request.cookies.get(keys.token_expires_at)?.value;\n\n if (!refreshToken) return false;\n\n const expiresAtNumber = expiresAt ? Number(expiresAt) : null;\n const tokenExpiresSoon =\n typeof expiresAtNumber === 'number' &&\n Number.isFinite(expiresAtNumber) &&\n expiresAtNumber <= Date.now() + 60_000;\n\n return !token || tokenExpiresSoon;\n}\n\n/**\n * Mutates request.cookies and sets Set-Cookie on `response`; the caller must\n * have created `response` with `{ request }` so the mutations are forwarded via\n * x-middleware-request-* headers. Throws on failure — caller decides handling.\n */\nexport async function refreshSession(\n request: NextRequest,\n response: NextResponse,\n config: NodeHiveAuthConfig\n): Promise<void> {\n const keys = NextCookieStorage.cookieKeys();\n const refreshToken = request.cookies.get(keys.refresh_token)?.value;\n\n if (!refreshToken) {\n throw new AuthenticationError('No refresh token available');\n }\n\n await refreshOnce(refreshToken, { request, response }, config);\n}\n\nexport function clearAuthCookies(\n request: NextRequest,\n response: NextResponse\n): void {\n const keys = NextCookieStorage.cookieKeys();\n // Draft cookie included: a dead session must not strand the visitor in\n // token-less draft mode. Raw headers — middleware cannot call draftMode().\n for (const name of [...Object.values(keys), DRAFT_MODE_COOKIE]) {\n request.cookies.delete(name);\n appendClearedAuthCookie(response, name);\n }\n}\n\n// Auth failure (invalid/expired refresh token) vs transient (network, timeout,\n// 5xx): transient errors keep the session, auth failures clear it.\nexport function isAuthFailure(error: unknown): boolean {\n if (!(error instanceof AuthenticationError)) return false;\n const status = error.details?.status;\n return status === 400 || status === 401 || status === 403;\n}\n\n// When the refresh is served from the grace cache or an in-flight dedup, the SDK\n// never ran for THIS request, so its cookies were never written. Mirror the\n// tokens onto the current request/response so this navigation renders logged-in\n// and the browser receives the fresh cookies.\nasync function applyLoginResult(\n context: ProxyContext,\n result: LoginResult\n): Promise<LoginResult> {\n const storage = new NextCookieStorage(context);\n const maxAge = result.expires_in ?? undefined;\n const tokenOptions = maxAge ? { maxAge } : undefined;\n\n await storage.set('token', result.token, tokenOptions);\n if (result.refresh_token) {\n await storage.set('refresh_token', result.refresh_token, {\n maxAge: REFRESH_TOKEN_MAX_AGE,\n });\n }\n if (maxAge) {\n await storage.set(\n 'token_expires_at',\n String(Date.now() + maxAge * 1000),\n tokenOptions\n );\n }\n if (result.user) {\n await storage.set(\n 'user_details',\n typeof result.user === 'string'\n ? result.user\n : JSON.stringify(result.user),\n tokenOptions\n );\n }\n return result;\n}\n\nfunction refreshOnce(\n refreshToken: string,\n context: ProxyContext,\n config: NodeHiveAuthConfig\n): Promise<LoginResult> {\n const recent = getRecentRotation(refreshToken);\n if (recent) return applyLoginResult(context, recent);\n\n const existing = activeRefreshes.get(refreshToken);\n if (existing) {\n return withDeadline(\n existing.then((result) => applyLoginResult(context, result)),\n refreshDeadlineMs\n );\n }\n\n const client = buildUserClient(config, context);\n\n // rememberRotation and the dedup cleanup hang off the underlying refresh, NOT\n // the deadline-raced promise: if Drupal answers after the deadline the\n // refresh token is already consumed, so it must still be grace-cached or the\n // next request gets invalid_grant.\n const underlying = refreshWithRetries(client)\n .then((result) => {\n rememberRotation(refreshToken, result);\n return result;\n })\n .finally(() => {\n activeRefreshes.delete(refreshToken);\n });\n\n activeRefreshes.set(refreshToken, underlying);\n return withDeadline(underlying, refreshDeadlineMs);\n}\n\nasync function refreshWithRetries(\n client: ReturnType<typeof buildUserClient>\n): Promise<LoginResult> {\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {\n try {\n return await client.auth.refreshToken();\n } catch (error) {\n lastError = error;\n\n // Don't retry auth failures (invalid/expired refresh token)\n if (isAuthFailure(error)) {\n throw error;\n }\n\n if (attempt < MAX_RETRIES) {\n console.warn(`[Refresh] Attempt ${attempt} failed, retrying...`, error);\n await wait(BACKOFF_MS * 2 ** (attempt - 1));\n }\n }\n }\n\n throw lastError;\n}\n"],"mappings":"AACA,SAASA,mBAAmB,QAA0B,aAAa;AAGnE,SAASC,iBAAiB,QAAQ,iBAAiB;AACnD,SACEC,uBAAuB,EACvBC,iBAAiB,QAEZ,0BAA0B;AACjC,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,MAAMC,WAAW,GAAG,CAAC;AACrB,MAAMC,UAAU,GAAG,GAAG;AACtB,MAAMC,iBAAiB,GAAG,MAAM;AAChC;AACA;AACA;AACA;AACA,IAAIC,iBAAiB,GAAG,KAAK;AAE7B,OAAO,SAASC,8BAA8BA,CAACC,EAAU,EAAE;EACzDF,iBAAiB,GAAGE,EAAE;AACxB;AAEA,MAAMC,IAAI,GAAID,EAAU,IAAK,IAAIE,OAAO,CAAEC,OAAO,IAAKC,UAAU,CAACD,OAAO,EAAEH,EAAE,CAAC,CAAC;AAE9E,SAASK,YAAYA,CAAIC,OAAmB,EAAEN,EAAU,EAAc;EACpE,OAAOE,OAAO,CAACK,IAAI,CAAC,CAClBD,OAAO,EACP,IAAIJ,OAAO,CAAI,CAACM,CAAC,EAAEC,MAAM,KAAK;IAC5B,MAAMC,KAAK,GAAGN,UAAU,CACtB,MAAMK,MAAM,CAAC,IAAIE,KAAK,CAAC,yBAAyB,CAAC,CAAC,EAClDX,EAC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AAE;MACdqB,SAAS,GAAGrB,KAAK;;MAEjB;MACA,IAAID,aAAa,CAACC,KAAK,CAAC,EAAE;QACxB,MAAMA,KAAK;MACb;MAEA,IAAIsB,OAAO,GAAG/E,WAAW,EAAE;QACzBgC,OAAO,CAACiD,IAAI,CAAC,qBAAqBF,OAAO,sBAAsB,EAAEtB,KAAK,CAAC;QACvE,MAAMnD,IAAI,CAACL,UAAU,GAAG,CAAC,KAAK8E,OAAO,GAAG,CAAC,CAAC,CAAC;MAC7C;IACF;EACF;EAEA,MAAMD,SAAS;AACjB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"refresh.js","names":["AuthenticationError","DRAFT_MODE_COOKIE","appendClearedAuthCookie","NextCookieStorage","buildUserClient","REFRESH_TOKEN_MAX_AGE","MAX_RETRIES","BACKOFF_MS","ROTATION_GRACE_MS","refreshDeadlineMs","setRefreshDeadlineMsForTesting","ms","wait","Promise","resolve","setTimeout","withDeadline","promise","race","_","reject","timer","Error","unref","activeRefreshes","Map","recentRotations","rememberRotation","oldToken","result","expiresAt","Date","now","set","delete","getRecentRotation","entry","get","console","info","shouldRefreshSession","request","keys","cookieKeys","token","cookies","value","refreshToken","refresh_token","token_expires_at","expiresAtNumber","Number","tokenExpiresSoon","isFinite","refreshSession","response","config","refreshOnce","clearAuthCookies","name","Object","values","clearStaleDraftCookie","isAuthFailure","error","status","details","applyLoginResult","context","storage","maxAge","expires_in","undefined","tokenOptions","String","user","JSON","stringify","recent","existing","then","client","underlying","refreshWithRetries","finally","lastError","attempt","auth","warn"],"sources":["../../../src/auth/internal/refresh.ts"],"sourcesContent":["import type { NextRequest, NextResponse } from 'next/server';\nimport { AuthenticationError, type LoginResult } from 'nodehive-js';\n\nimport type { NodeHiveAuthConfig } from './config.ts';\nimport { DRAFT_MODE_COOKIE } from './draft-mode.ts';\nimport {\n appendClearedAuthCookie,\n NextCookieStorage,\n type ProxyContext,\n} from './next-cookie-storage.ts';\nimport { buildUserClient } from './nodehive-client.ts';\nimport { REFRESH_TOKEN_MAX_AGE } from './oauth-config.ts';\n\nconst MAX_RETRIES = 3;\nconst BACKOFF_MS = 200;\nconst ROTATION_GRACE_MS = 30_000;\n// Hard ceiling for a whole refresh (incl. retries). The proxy awaits this on\n// nearly every request, and the SDK's token fetch has no timeout of its own, so\n// without this a slow/hung Drupal would stall every page load. On timeout the\n// error is non-auth → treated as transient → the stale session is kept.\nlet refreshDeadlineMs = 5_000;\n\nexport function setRefreshDeadlineMsForTesting(ms: number) {\n refreshDeadlineMs = ms;\n}\n\nconst wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n\nfunction withDeadline<T>(promise: Promise<T>, ms: number): Promise<T> {\n return Promise.race([\n promise,\n new Promise<T>((_, reject) => {\n const timer = setTimeout(\n () => reject(new Error('Token refresh timed out')),\n ms\n );\n timer.unref?.();\n }),\n ]);\n}\n\n// Per-user dedup: prevents concurrent requests from racing on token rotation.\n// Note: This Map is per-isolate — on serverless deployments, dedup is best-effort\n// and not guaranteed across concurrent isolates. On long-running servers it works fully.\nconst activeRefreshes = new Map<string, Promise<LoginResult>>();\n\n// Grace cache for recently rotated refresh tokens.\n//\n// OAuth refresh tokens are single-use: each successful refresh invalidates the\n// previous one. But the browser can have parallel requests in flight carrying\n// the old refresh-token cookie when the rotation happens. Without this cache,\n// stale requests arriving just AFTER the original refresh completed (so the\n// `activeRefreshes` dedup map is already empty) trigger a second refresh that\n// fails with invalid_grant and logs the user out.\n//\n// Mapping: old refresh_token → fresh LoginResult, valid for ROTATION_GRACE_MS.\nconst recentRotations = new Map<\n string,\n { result: LoginResult; expiresAt: number }\n>();\n\nfunction rememberRotation(oldToken: string, result: LoginResult) {\n const expiresAt = Date.now() + ROTATION_GRACE_MS;\n recentRotations.set(oldToken, { result, expiresAt });\n setTimeout(\n () => recentRotations.delete(oldToken),\n ROTATION_GRACE_MS\n ).unref?.();\n}\n\nfunction getRecentRotation(oldToken: string): LoginResult | null {\n const entry = recentRotations.get(oldToken);\n if (!entry) return null;\n if (entry.expiresAt < Date.now()) {\n recentRotations.delete(oldToken);\n return null;\n }\n console.info('[Refresh] grace cache hit — stale refresh-token reused');\n return entry.result;\n}\n\nexport function shouldRefreshSession(request: NextRequest): boolean {\n const keys = NextCookieStorage.cookieKeys();\n const token = request.cookies.get(keys.token)?.value;\n const refreshToken = request.cookies.get(keys.refresh_token)?.value;\n const expiresAt = request.cookies.get(keys.token_expires_at)?.value;\n\n if (!refreshToken) return false;\n\n const expiresAtNumber = expiresAt ? Number(expiresAt) : null;\n const tokenExpiresSoon =\n typeof expiresAtNumber === 'number' &&\n Number.isFinite(expiresAtNumber) &&\n expiresAtNumber <= Date.now() + 60_000;\n\n return !token || tokenExpiresSoon;\n}\n\n/**\n * Mutates request.cookies and sets Set-Cookie on `response`; the caller must\n * have created `response` with `{ request }` so the mutations are forwarded via\n * x-middleware-request-* headers. Throws on failure — caller decides handling.\n */\nexport async function refreshSession(\n request: NextRequest,\n response: NextResponse,\n config: NodeHiveAuthConfig\n): Promise<void> {\n const keys = NextCookieStorage.cookieKeys();\n const refreshToken = request.cookies.get(keys.refresh_token)?.value;\n\n if (!refreshToken) {\n throw new AuthenticationError('No refresh token available');\n }\n\n await refreshOnce(refreshToken, { request, response }, config);\n}\n\nexport function clearAuthCookies(\n request: NextRequest,\n response: NextResponse\n): void {\n const keys = NextCookieStorage.cookieKeys();\n // Draft cookie included: a dead session must not strand the visitor in\n // token-less draft mode. Raw headers — middleware cannot call draftMode().\n for (const name of [...Object.values(keys), DRAFT_MODE_COOKIE]) {\n request.cookies.delete(name);\n appendClearedAuthCookie(response, name);\n }\n}\n\n/**\n * clearAuthCookies takes the draft cookie down with the session, but it only\n * runs once a refresh was attempted and rejected. When the refresh-token cookie\n * is simply gone there is nothing to refresh, shouldRefreshSession bails out,\n * and a draft cookie from an earlier login outlives its session — it is set for\n * the full refresh-token lifetime, so this can last weeks. The data layer then\n * reads draftMode() as enabled and fetches with a user client that has no\n * token, which is answered with Drupal's HTML error pages.\n */\nexport function clearStaleDraftCookie(\n request: NextRequest,\n response: NextResponse\n): void {\n const keys = NextCookieStorage.cookieKeys();\n if (request.cookies.get(keys.refresh_token)) return;\n if (!request.cookies.get(DRAFT_MODE_COOKIE)) return;\n\n request.cookies.delete(DRAFT_MODE_COOKIE);\n appendClearedAuthCookie(response, DRAFT_MODE_COOKIE);\n}\n\n// Auth failure (invalid/expired refresh token) vs transient (network, timeout,\n// 5xx): transient errors keep the session, auth failures clear it.\nexport function isAuthFailure(error: unknown): boolean {\n if (!(error instanceof AuthenticationError)) return false;\n const status = error.details?.status;\n return status === 400 || status === 401 || status === 403;\n}\n\n// When the refresh is served from the grace cache or an in-flight dedup, the SDK\n// never ran for THIS request, so its cookies were never written. Mirror the\n// tokens onto the current request/response so this navigation renders logged-in\n// and the browser receives the fresh cookies.\nasync function applyLoginResult(\n context: ProxyContext,\n result: LoginResult\n): Promise<LoginResult> {\n const storage = new NextCookieStorage(context);\n const maxAge = result.expires_in ?? undefined;\n const tokenOptions = maxAge ? { maxAge } : undefined;\n\n await storage.set('token', result.token, tokenOptions);\n if (result.refresh_token) {\n await storage.set('refresh_token', result.refresh_token, {\n maxAge: REFRESH_TOKEN_MAX_AGE,\n });\n }\n if (maxAge) {\n await storage.set(\n 'token_expires_at',\n String(Date.now() + maxAge * 1000),\n tokenOptions\n );\n }\n if (result.user) {\n await storage.set(\n 'user_details',\n typeof result.user === 'string'\n ? result.user\n : JSON.stringify(result.user),\n tokenOptions\n );\n }\n return result;\n}\n\nfunction refreshOnce(\n refreshToken: string,\n context: ProxyContext,\n config: NodeHiveAuthConfig\n): Promise<LoginResult> {\n const recent = getRecentRotation(refreshToken);\n if (recent) return applyLoginResult(context, recent);\n\n const existing = activeRefreshes.get(refreshToken);\n if (existing) {\n return withDeadline(\n existing.then((result) => applyLoginResult(context, result)),\n refreshDeadlineMs\n );\n }\n\n const client = buildUserClient(config, context);\n\n // rememberRotation and the dedup cleanup hang off the underlying refresh, NOT\n // the deadline-raced promise: if Drupal answers after the deadline the\n // refresh token is already consumed, so it must still be grace-cached or the\n // next request gets invalid_grant.\n const underlying = refreshWithRetries(client)\n .then((result) => {\n rememberRotation(refreshToken, result);\n return result;\n })\n .finally(() => {\n activeRefreshes.delete(refreshToken);\n });\n\n activeRefreshes.set(refreshToken, underlying);\n return withDeadline(underlying, refreshDeadlineMs);\n}\n\nasync function refreshWithRetries(\n client: ReturnType<typeof buildUserClient>\n): Promise<LoginResult> {\n let lastError: unknown;\n\n for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {\n try {\n return await client.auth.refreshToken();\n } catch (error) {\n lastError = error;\n\n // Don't retry auth failures (invalid/expired refresh token)\n if (isAuthFailure(error)) {\n throw error;\n }\n\n if (attempt < MAX_RETRIES) {\n console.warn(`[Refresh] Attempt ${attempt} failed, retrying...`, error);\n await wait(BACKOFF_MS * 2 ** (attempt - 1));\n }\n }\n }\n\n throw lastError;\n}\n"],"mappings":"AACA,SAASA,mBAAmB,QAA0B,aAAa;AAGnE,SAASC,iBAAiB,QAAQ,iBAAiB;AACnD,SACEC,uBAAuB,EACvBC,iBAAiB,QAEZ,0BAA0B;AACjC,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,qBAAqB,QAAQ,mBAAmB;AAEzD,MAAMC,WAAW,GAAG,CAAC;AACrB,MAAMC,UAAU,GAAG,GAAG;AACtB,MAAMC,iBAAiB,GAAG,MAAM;AAChC;AACA;AACA;AACA;AACA,IAAIC,iBAAiB,GAAG,KAAK;AAE7B,OAAO,SAASC,8BAA8BA,CAACC,EAAU,EAAE;EACzDF,iBAAiB,GAAGE,EAAE;AACxB;AAEA,MAAMC,IAAI,GAAID,EAAU,IAAK,IAAIE,OAAO,CAAEC,OAAO,IAAKC,UAAU,CAACD,OAAO,EAAEH,EAAE,CAAC,CAAC;AAE9E,SAASK,YAAYA,CAAIC,OAAmB,EAAEN,EAAU,EAAc;EACpE,OAAOE,OAAO,CAACK,IAAI,CAAC,CAClBD,OAAO,EAC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AkB,CAACF,MAAM,CAAC,CAC1CD,IAAI,CAAEnD,MAAM,IAAK;IAChBF,gBAAgB,CAACoB,YAAY,EAAElB,MAAM,CAAC;IACtC,OAAOA,MAAM;EACf,CAAC,CAAC,CACDuD,OAAO,CAAC,MAAM;IACb5D,eAAe,CAACU,MAAM,CAACa,YAAY,CAAC;EACtC,CAAC,CAAC;EAEJvB,eAAe,CAACS,GAAG,CAACc,YAAY,EAAEmC,UAAU,CAAC;EAC7C,OAAOlE,YAAY,CAACkE,UAAU,EAAEzE,iBAAiB,CAAC;AACpD;AAEA,eAAe0E,kBAAkBA,CAC/BF,MAA0C,EACpB;EACtB,IAAII,SAAkB;EAEtB,KAAK,IAAIC,OAAO,GAAG,CAAC,EAAEA,OAAO,IAAIhF,WAAW,EAAEgF,OAAO,EAAE,EAAE;IACvD,IAAI;MACF,OAAO,MAAML,MAAM,CAACM,IAAI,CAACxC,YAAY,CAAC,CAAC;IACzC,CAAC,CAAC,OAAOiB,KAAK,EAAE;MACdqB,SAAS,GAAGrB,KAAK;;MAEjB;MACA,IAAID,aAAa,CAACC,KAAK,CAAC,EAAE;QACxB,MAAMA,KAAK;MACb;MAEA,IAAIsB,OAAO,GAAGhF,WAAW,EAAE;QACzBgC,OAAO,CAACkD,IAAI,CAAC,qBAAqBF,OAAO,sBAAsB,EAAEtB,KAAK,CAAC;QACvE,MAAMpD,IAAI,CAACL,UAAU,GAAG,CAAC,KAAK+E,OAAO,GAAG,CAAC,CAAC,CAAC;MAC7C;IACF;EACF;EAEA,MAAMD,SAAS;AACjB","ignoreList":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isAuthFailure, refreshSession, shouldRefreshSession } from "./refresh.js";
|
|
1
|
+
import { clearStaleDraftCookie, isAuthFailure, refreshSession, shouldRefreshSession } from "./refresh.js";
|
|
2
2
|
/**
|
|
3
3
|
* Silent token refresh for the middleware (Supabase `updateSession` pattern).
|
|
4
4
|
* Owns the prefetch shortcut + shouldRefresh decision. Mutates request.cookies
|
|
@@ -15,6 +15,7 @@ export async function updateSession(request, response, config) {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
if (!shouldRefreshSession(request)) {
|
|
18
|
+
clearStaleDraftCookie(request, response);
|
|
18
19
|
return {
|
|
19
20
|
authFailed: false
|
|
20
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-session.js","names":["isAuthFailure","refreshSession","shouldRefreshSession","updateSession","request","response","config","headers","get","authFailed","error","console","warn"],"sources":["../../../src/auth/internal/update-session.ts"],"sourcesContent":["import type { NextRequest, NextResponse } from 'next/server';\n\nimport type { NodeHiveAuthConfig } from './config.ts';\nimport {\n isAuthFailure,\n refreshSession,\n shouldRefreshSession,\n} from './refresh.ts';\n\nexport interface UpdateSessionResult {\n /** Refresh token invalid/expired — caller must clear cookies and start a fresh\n * login. Caller builds the response (401 for /api, redirect for pages). */\n authFailed: boolean;\n}\n\n/**\n * Silent token refresh for the middleware (Supabase `updateSession` pattern).\n * Owns the prefetch shortcut + shouldRefresh decision. Mutates request.cookies\n * and sets Set-Cookie on `response` (caller must create it with `{ request }`).\n *\n * Returns authFailed as DATA, not a response: the 401-vs-redirect choice needs\n * isApi + the public origin, which are proxy.ts's concern.\n */\nexport async function updateSession(\n request: NextRequest,\n response: NextResponse,\n config: NodeHiveAuthConfig\n): Promise<UpdateSessionResult> {\n // A Next prefetch must never consume the single-use refresh token.\n if (request.headers.get('next-router-prefetch') === '1') {\n return { authFailed: false };\n }\n\n if (!shouldRefreshSession(request)) {\n return { authFailed: false };\n }\n\n try {\n await refreshSession(request, response, config);\n return { authFailed: false };\n } catch (error) {\n if (isAuthFailure(error)) {\n return { authFailed: true };\n }\n\n console.warn(\n '[nodehive-auth] Token refresh failed (transient), keeping session:',\n error\n );\n return { authFailed: false };\n }\n}\n"],"mappings":"AAGA,SACEA,aAAa,EACbC,cAAc,EACdC,oBAAoB,QACf,cAAc;AAQrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,aAAaA,CACjCC,OAAoB,EACpBC,QAAsB,EACtBC,MAA0B,EACI;EAC9B;EACA,IAAIF,OAAO,CAACG,OAAO,CAACC,GAAG,CAAC,sBAAsB,CAAC,KAAK,GAAG,EAAE;IACvD,OAAO;MAAEC,UAAU,EAAE;IAAM,CAAC;EAC9B;EAEA,IAAI,CAACP,oBAAoB,CAACE,OAAO,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"update-session.js","names":["clearStaleDraftCookie","isAuthFailure","refreshSession","shouldRefreshSession","updateSession","request","response","config","headers","get","authFailed","error","console","warn"],"sources":["../../../src/auth/internal/update-session.ts"],"sourcesContent":["import type { NextRequest, NextResponse } from 'next/server';\n\nimport type { NodeHiveAuthConfig } from './config.ts';\nimport {\n clearStaleDraftCookie,\n isAuthFailure,\n refreshSession,\n shouldRefreshSession,\n} from './refresh.ts';\n\nexport interface UpdateSessionResult {\n /** Refresh token invalid/expired — caller must clear cookies and start a fresh\n * login. Caller builds the response (401 for /api, redirect for pages). */\n authFailed: boolean;\n}\n\n/**\n * Silent token refresh for the middleware (Supabase `updateSession` pattern).\n * Owns the prefetch shortcut + shouldRefresh decision. Mutates request.cookies\n * and sets Set-Cookie on `response` (caller must create it with `{ request }`).\n *\n * Returns authFailed as DATA, not a response: the 401-vs-redirect choice needs\n * isApi + the public origin, which are proxy.ts's concern.\n */\nexport async function updateSession(\n request: NextRequest,\n response: NextResponse,\n config: NodeHiveAuthConfig\n): Promise<UpdateSessionResult> {\n // A Next prefetch must never consume the single-use refresh token.\n if (request.headers.get('next-router-prefetch') === '1') {\n return { authFailed: false };\n }\n\n if (!shouldRefreshSession(request)) {\n clearStaleDraftCookie(request, response);\n return { authFailed: false };\n }\n\n try {\n await refreshSession(request, response, config);\n return { authFailed: false };\n } catch (error) {\n if (isAuthFailure(error)) {\n return { authFailed: true };\n }\n\n console.warn(\n '[nodehive-auth] Token refresh failed (transient), keeping session:',\n error\n );\n return { authFailed: false };\n }\n}\n"],"mappings":"AAGA,SACEA,qBAAqB,EACrBC,aAAa,EACbC,cAAc,EACdC,oBAAoB,QACf,cAAc;AAQrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,aAAaA,CACjCC,OAAoB,EACpBC,QAAsB,EACtBC,MAA0B,EACI;EAC9B;EACA,IAAIF,OAAO,CAACG,OAAO,CAACC,GAAG,CAAC,sBAAsB,CAAC,KAAK,GAAG,EAAE;IACvD,OAAO;MAAEC,UAAU,EAAE;IAAM,CAAC;EAC9B;EAEA,IAAI,CAACP,oBAAoB,CAACE,OAAO,CAAC,EAAE;IAClCL,qBAAqB,CAACK,OAAO,EAAEC,QAAQ,CAAC;IACxC,OAAO;MAAEI,UAAU,EAAE;IAAM,CAAC;EAC9B;EAEA,IAAI;IACF,MAAMR,cAAc,CAACG,OAAO,EAAEC,QAAQ,EAAEC,MAAM,CAAC;IAC/C,OAAO;MAAEG,UAAU,EAAE;IAAM,CAAC;EAC9B,CAAC,CAAC,OAAOC,KAAK,EAAE;IACd,IAAIV,aAAa,CAACU,KAAK,CAAC,EAAE;MACxB,OAAO;QAAED,UAAU,EAAE;MAAK,CAAC;IAC7B;IAEAE,OAAO,CAACC,IAAI,CACV,oEAAoE,EACpEF,KACF,CAAC;IACD,OAAO;MAAED,UAAU,EAAE;IAAM,CAAC;EAC9B;AACF","ignoreList":[]}
|
package/dist/auth/server.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare function createNodeHiveAuth(config: NodeHiveAuthConfig): {
|
|
|
14
14
|
performLogout: (options?: PerformLogoutOptions) => Promise<void>;
|
|
15
15
|
};
|
|
16
16
|
export { shouldEnableDraftMode } from './internal/draft-mode.js';
|
|
17
|
+
export { isDraftSession } from './internal/draft-session.js';
|
|
17
18
|
export { checkHasSession } from './internal/has-session.js';
|
|
18
19
|
export { getEditorLocale, resolveEditorLocale, } from './internal/editor-locale.js';
|
|
19
20
|
export { requireAuth } from './internal/require-auth.js';
|
package/dist/auth/server.js
CHANGED
|
@@ -57,6 +57,7 @@ export function createNodeHiveAuth(config) {
|
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
export { shouldEnableDraftMode } from "./internal/draft-mode.js";
|
|
60
|
+
export { isDraftSession } from "./internal/draft-session.js";
|
|
60
61
|
export { checkHasSession } from "./internal/has-session.js";
|
|
61
62
|
export { getEditorLocale, resolveEditorLocale } from "./internal/editor-locale.js";
|
|
62
63
|
export { requireAuth } from "./internal/require-auth.js";
|
package/dist/auth/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":["cache","checkHasSession","performLogout","NextCookieStorage","buildAnonClient","buildUserClient","createNodeHiveAuth","config","createUserClient","proxyContext","preventSdkRefresh","anonClient","createAnonClient","createClient","storage","token","get","isAuthenticated","options","shouldEnableDraftMode","getEditorLocale","resolveEditorLocale","requireAuth","getUserRoles","isSameOriginRequest","SignedIn","SignedOut"],"sources":["../../src/auth/server.ts"],"sourcesContent":["// Server entry: client factories, editor guard, logout.\nimport { cache } from 'react';\n\nimport type { NodeHiveAuthConfig } from './internal/config.ts';\nimport { checkHasSession } from './internal/has-session.ts';\nimport { performLogout, type PerformLogoutOptions } from './internal/logout.ts';\nimport {\n NextCookieStorage,\n type ProxyContext,\n} from './internal/next-cookie-storage.ts';\nimport {\n buildAnonClient,\n buildUserClient,\n} from './internal/nodehive-client.ts';\n\n/**\n * Bind the client factories + logout to a project config (explicit injection,\n * no global singleton). Call once in the project and re-export the result.\n */\nexport function createNodeHiveAuth(config: NodeHiveAuthConfig) {\n /**\n * Deliberately act as the logged-in user. Default: use createClient().\n * Binds to the request's session cookies but guarantees no user: without a\n * session the client carries no token (it is NOT the anon client) — use it\n * only where a session is established or where you check isLoggedIn().\n */\n const createUserClient = (proxyContext?: ProxyContext) =>\n buildUserClient(config, proxyContext, { preventSdkRefresh: !proxyContext });\n\n /**\n * Deliberately act as an anonymous visitor (client_credentials, capped\n * rights). Default: use createClient(). One instance per runtime since the\n * credential never rotates.\n */\n let anonClient: ReturnType<typeof buildAnonClient> | null = null;\n const createAnonClient = () => {\n if (anonClient) return anonClient;\n anonClient = buildAnonClient(config);\n return anonClient;\n };\n\n /**\n * The default client: user client when a usable access token is present,\n * else the anon client. Memoized per request via React cache().\n *\n * Checks the short-lived access token, not the refresh token: only the\n * proxy may refresh (rotated tokens can't be persisted from RSCs), so the\n * user client is only picked when a request-ready token exists. \"Is the\n * user logged in?\" is a different question — that's isAuthenticated, which\n * checks the durable refresh token.\n */\n const createClient = cache(async () => {\n const storage = new NextCookieStorage();\n const token = await storage.get('token');\n return token ? createUserClient() : createAnonClient();\n });\n\n const isAuthenticated = cache(checkHasSession);\n\n return {\n createClient,\n createUserClient,\n createAnonClient,\n isAuthenticated,\n performLogout: (options?: PerformLogoutOptions) =>\n performLogout(config, options),\n };\n}\n\nexport { shouldEnableDraftMode } from './internal/draft-mode.ts';\nexport { checkHasSession } from './internal/has-session.ts';\nexport {\n getEditorLocale,\n resolveEditorLocale,\n} from './internal/editor-locale.ts';\nexport { requireAuth } from './internal/require-auth.ts';\nexport { getUserRoles } from './internal/roles.ts';\nexport { isSameOriginRequest } from './internal/same-origin.ts';\nexport { SignedIn, SignedOut } from './internal/session-gates.tsx';\nexport type { NodeHiveAuthConfig } from './internal/config.ts';\nexport type { ProxyContext } from './internal/next-cookie-storage.ts';\nexport type { PerformLogoutOptions } from './internal/logout.ts';\n"],"mappings":"AAAA;AACA,SAASA,KAAK,QAAQ,OAAO;AAG7B,SAASC,eAAe,QAAQ,2BAA2B;AAC3D,SAASC,aAAa,QAAmC,sBAAsB;AAC/E,SACEC,iBAAiB,QAEZ,mCAAmC;AAC1C,SACEC,eAAe,EACfC,eAAe,QACV,+BAA+B;;AAEtC;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAACC,MAA0B,EAAE;EAC7D;AACF;AACA;AACA;AACA;AACA;EACE,MAAMC,gBAAgB,GAAIC,YAA2B,IACnDJ,eAAe,CAACE,MAAM,EAAEE,YAAY,EAAE;IAAEC,iBAAiB,EAAE,CAACD;EAAa,CAAC,CAAC;;EAE7E;AACF;AACA;AACA;AACA;EACE,IAAIE,UAAqD,GAAG,IAAI;EAChE,MAAMC,gBAAgB,GAAGA,CAAA,KAAM;IAC7B,IAAID,UAAU,EAAE,OAAOA,UAAU;IACjCA,UAAU,GAAGP,eAAe,CAACG,MAAM,CAAC;IACpC,OAAOI,UAAU;EACnB,CAAC;;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAME,YAAY,GAAGb,KAAK,CAAC,YAAY;IACrC,MAAMc,OAAO,GAAG,IAAIX,iBAAiB,CAAC,CAAC;IACvC,MAAMY,KAAK,GAAG,MAAMD,OAAO,CAACE,GAAG,CAAC,OAAO,CAAC;IACxC,OAAOD,KAAK,GAAGP,gBAAgB,CAAC,CAAC,GAAGI,gBAAgB,CAAC,CAAC;EACxD,CAAC,CAAC;EAEF,MAAMK,eAAe,GAAGjB,KAAK,CAACC,eAAe,CAAC;EAE9C,OAAO;IACLY,YAAY;IACZL,gBAAgB;IAChBI,gBAAgB;IAChBK,eAAe;IACff,aAAa,EAAGgB,OAA8B,IAC5ChB,aAAa,CAACK,MAAM,EAAEW,OAAO;EACjC,CAAC;AACH;AAEA,SAASC,qBAAqB,QAAQ,0BAA0B;AAChE,
|
|
1
|
+
{"version":3,"file":"server.js","names":["cache","checkHasSession","performLogout","NextCookieStorage","buildAnonClient","buildUserClient","createNodeHiveAuth","config","createUserClient","proxyContext","preventSdkRefresh","anonClient","createAnonClient","createClient","storage","token","get","isAuthenticated","options","shouldEnableDraftMode","isDraftSession","getEditorLocale","resolveEditorLocale","requireAuth","getUserRoles","isSameOriginRequest","SignedIn","SignedOut"],"sources":["../../src/auth/server.ts"],"sourcesContent":["// Server entry: client factories, editor guard, logout.\nimport { cache } from 'react';\n\nimport type { NodeHiveAuthConfig } from './internal/config.ts';\nimport { checkHasSession } from './internal/has-session.ts';\nimport { performLogout, type PerformLogoutOptions } from './internal/logout.ts';\nimport {\n NextCookieStorage,\n type ProxyContext,\n} from './internal/next-cookie-storage.ts';\nimport {\n buildAnonClient,\n buildUserClient,\n} from './internal/nodehive-client.ts';\n\n/**\n * Bind the client factories + logout to a project config (explicit injection,\n * no global singleton). Call once in the project and re-export the result.\n */\nexport function createNodeHiveAuth(config: NodeHiveAuthConfig) {\n /**\n * Deliberately act as the logged-in user. Default: use createClient().\n * Binds to the request's session cookies but guarantees no user: without a\n * session the client carries no token (it is NOT the anon client) — use it\n * only where a session is established or where you check isLoggedIn().\n */\n const createUserClient = (proxyContext?: ProxyContext) =>\n buildUserClient(config, proxyContext, { preventSdkRefresh: !proxyContext });\n\n /**\n * Deliberately act as an anonymous visitor (client_credentials, capped\n * rights). Default: use createClient(). One instance per runtime since the\n * credential never rotates.\n */\n let anonClient: ReturnType<typeof buildAnonClient> | null = null;\n const createAnonClient = () => {\n if (anonClient) return anonClient;\n anonClient = buildAnonClient(config);\n return anonClient;\n };\n\n /**\n * The default client: user client when a usable access token is present,\n * else the anon client. Memoized per request via React cache().\n *\n * Checks the short-lived access token, not the refresh token: only the\n * proxy may refresh (rotated tokens can't be persisted from RSCs), so the\n * user client is only picked when a request-ready token exists. \"Is the\n * user logged in?\" is a different question — that's isAuthenticated, which\n * checks the durable refresh token.\n */\n const createClient = cache(async () => {\n const storage = new NextCookieStorage();\n const token = await storage.get('token');\n return token ? createUserClient() : createAnonClient();\n });\n\n const isAuthenticated = cache(checkHasSession);\n\n return {\n createClient,\n createUserClient,\n createAnonClient,\n isAuthenticated,\n performLogout: (options?: PerformLogoutOptions) =>\n performLogout(config, options),\n };\n}\n\nexport { shouldEnableDraftMode } from './internal/draft-mode.ts';\nexport { isDraftSession } from './internal/draft-session.ts';\nexport { checkHasSession } from './internal/has-session.ts';\nexport {\n getEditorLocale,\n resolveEditorLocale,\n} from './internal/editor-locale.ts';\nexport { requireAuth } from './internal/require-auth.ts';\nexport { getUserRoles } from './internal/roles.ts';\nexport { isSameOriginRequest } from './internal/same-origin.ts';\nexport { SignedIn, SignedOut } from './internal/session-gates.tsx';\nexport type { NodeHiveAuthConfig } from './internal/config.ts';\nexport type { ProxyContext } from './internal/next-cookie-storage.ts';\nexport type { PerformLogoutOptions } from './internal/logout.ts';\n"],"mappings":"AAAA;AACA,SAASA,KAAK,QAAQ,OAAO;AAG7B,SAASC,eAAe,QAAQ,2BAA2B;AAC3D,SAASC,aAAa,QAAmC,sBAAsB;AAC/E,SACEC,iBAAiB,QAEZ,mCAAmC;AAC1C,SACEC,eAAe,EACfC,eAAe,QACV,+BAA+B;;AAEtC;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAACC,MAA0B,EAAE;EAC7D;AACF;AACA;AACA;AACA;AACA;EACE,MAAMC,gBAAgB,GAAIC,YAA2B,IACnDJ,eAAe,CAACE,MAAM,EAAEE,YAAY,EAAE;IAAEC,iBAAiB,EAAE,CAACD;EAAa,CAAC,CAAC;;EAE7E;AACF;AACA;AACA;AACA;EACE,IAAIE,UAAqD,GAAG,IAAI;EAChE,MAAMC,gBAAgB,GAAGA,CAAA,KAAM;IAC7B,IAAID,UAAU,EAAE,OAAOA,UAAU;IACjCA,UAAU,GAAGP,eAAe,CAACG,MAAM,CAAC;IACpC,OAAOI,UAAU;EACnB,CAAC;;EAED;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,MAAME,YAAY,GAAGb,KAAK,CAAC,YAAY;IACrC,MAAMc,OAAO,GAAG,IAAIX,iBAAiB,CAAC,CAAC;IACvC,MAAMY,KAAK,GAAG,MAAMD,OAAO,CAACE,GAAG,CAAC,OAAO,CAAC;IACxC,OAAOD,KAAK,GAAGP,gBAAgB,CAAC,CAAC,GAAGI,gBAAgB,CAAC,CAAC;EACxD,CAAC,CAAC;EAEF,MAAMK,eAAe,GAAGjB,KAAK,CAACC,eAAe,CAAC;EAE9C,OAAO;IACLY,YAAY;IACZL,gBAAgB;IAChBI,gBAAgB;IAChBK,eAAe;IACff,aAAa,EAAGgB,OAA8B,IAC5ChB,aAAa,CAACK,MAAM,EAAEW,OAAO;EACjC,CAAC;AACH;AAEA,SAASC,qBAAqB,QAAQ,0BAA0B;AAChE,SAASC,cAAc,QAAQ,6BAA6B;AAC5D,SAASnB,eAAe,QAAQ,2BAA2B;AAC3D,SACEoB,eAAe,EACfC,mBAAmB,QACd,6BAA6B;AACpC,SAASC,WAAW,QAAQ,4BAA4B;AACxD,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,mBAAmB,QAAQ,2BAA2B;AAC/D,SAASC,QAAQ,EAAEC,SAAS,QAAQ,6BAA8B","ignoreList":[]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SmartActionsToolbarAction } from './toolbar/types.js';
|
|
2
|
+
type Insertable = SmartActionsToolbarAction | SmartActionsToolbarAction[];
|
|
3
|
+
export declare function insertBefore(actions: SmartActionsToolbarAction[], anchorId: string, items: Insertable): SmartActionsToolbarAction[];
|
|
4
|
+
export declare function insertAfter(actions: SmartActionsToolbarAction[], anchorId: string, items: Insertable): SmartActionsToolbarAction[];
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function toList(items) {
|
|
2
|
+
return Array.isArray(items) ? items : [items];
|
|
3
|
+
}
|
|
4
|
+
export function insertBefore(actions, anchorId, items) {
|
|
5
|
+
const additions = toList(items);
|
|
6
|
+
const index = actions.findIndex(action => action.id === anchorId);
|
|
7
|
+
if (index === -1) return [...actions, ...additions];
|
|
8
|
+
return [...actions.slice(0, index), ...additions, ...actions.slice(index)];
|
|
9
|
+
}
|
|
10
|
+
export function insertAfter(actions, anchorId, items) {
|
|
11
|
+
const additions = toList(items);
|
|
12
|
+
const index = actions.findIndex(action => action.id === anchorId);
|
|
13
|
+
if (index === -1) return [...actions, ...additions];
|
|
14
|
+
return [...actions.slice(0, index + 1), ...additions, ...actions.slice(index + 1)];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=ordering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ordering.js","names":["toList","items","Array","isArray","insertBefore","actions","anchorId","additions","index","findIndex","action","id","slice","insertAfter"],"sources":["../../../src/smart-actions/internal/ordering.ts"],"sourcesContent":["import type { SmartActionsToolbarAction } from './toolbar/types.ts';\n\ntype Insertable = SmartActionsToolbarAction | SmartActionsToolbarAction[];\n\nfunction toList(items: Insertable): SmartActionsToolbarAction[] {\n return Array.isArray(items) ? items : [items];\n}\n\nexport function insertBefore(\n actions: SmartActionsToolbarAction[],\n anchorId: string,\n items: Insertable\n): SmartActionsToolbarAction[] {\n const additions = toList(items);\n const index = actions.findIndex((action) => action.id === anchorId);\n if (index === -1) return [...actions, ...additions];\n return [...actions.slice(0, index), ...additions, ...actions.slice(index)];\n}\n\nexport function insertAfter(\n actions: SmartActionsToolbarAction[],\n anchorId: string,\n items: Insertable\n): SmartActionsToolbarAction[] {\n const additions = toList(items);\n const index = actions.findIndex((action) => action.id === anchorId);\n if (index === -1) return [...actions, ...additions];\n return [\n ...actions.slice(0, index + 1),\n ...additions,\n ...actions.slice(index + 1),\n ];\n}\n"],"mappings":"AAIA,SAASA,MAAMA,CAACC,KAAiB,EAA+B;EAC9D,OAAOC,KAAK,CAACC,OAAO,CAACF,KAAK,CAAC,GAAGA,KAAK,GAAG,CAACA,KAAK,CAAC;AAC/C;AAEA,OAAO,SAASG,YAAYA,CAC1BC,OAAoC,EACpCC,QAAgB,EAChBL,KAAiB,EACY;EAC7B,MAAMM,SAAS,GAAGP,MAAM,CAACC,KAAK,CAAC;EAC/B,MAAMO,KAAK,GAAGH,OAAO,CAACI,SAAS,CAAEC,MAAM,IAAKA,MAAM,CAACC,EAAE,KAAKL,QAAQ,CAAC;EACnE,IAAIE,KAAK,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,GAAGH,OAAO,EAAE,GAAGE,SAAS,CAAC;EACnD,OAAO,CAAC,GAAGF,OAAO,CAACO,KAAK,CAAC,CAAC,EAAEJ,KAAK,CAAC,EAAE,GAAGD,SAAS,EAAE,GAAGF,OAAO,CAACO,KAAK,CAACJ,KAAK,CAAC,CAAC;AAC5E;AAEA,OAAO,SAASK,WAAWA,CACzBR,OAAoC,EACpCC,QAAgB,EAChBL,KAAiB,EACY;EAC7B,MAAMM,SAAS,GAAGP,MAAM,CAACC,KAAK,CAAC;EAC/B,MAAMO,KAAK,GAAGH,OAAO,CAACI,SAAS,CAAEC,MAAM,IAAKA,MAAM,CAACC,EAAE,KAAKL,QAAQ,CAAC;EACnE,IAAIE,KAAK,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,GAAGH,OAAO,EAAE,GAAGE,SAAS,CAAC;EACnD,OAAO,CACL,GAAGF,OAAO,CAACO,KAAK,CAAC,CAAC,EAAEJ,KAAK,GAAG,CAAC,CAAC,EAC9B,GAAGD,SAAS,EACZ,GAAGF,OAAO,CAACO,KAAK,CAACJ,KAAK,GAAG,CAAC,CAAC,CAC5B;AACH","ignoreList":[]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { NodeHiveClient } from 'nodehive-js';
|
|
2
|
-
import type { SmartActionsDictionaryOverrides
|
|
2
|
+
import type { SmartActionsDictionaryOverrides } from './i18n.js';
|
|
3
3
|
import { type SmartActionsBuilder } from './smart-actions-config.js';
|
|
4
|
-
import type { SmartActionsToolbarAction } from './toolbar/types.js';
|
|
5
4
|
interface SmartActionsButtonProps {
|
|
6
5
|
lang: string;
|
|
7
6
|
nodeId?: number;
|
|
@@ -17,16 +16,12 @@ interface SmartActionsButtonProps {
|
|
|
17
16
|
dictionaryOverrides?: SmartActionsDictionaryOverrides;
|
|
18
17
|
/** Account link target; null omits the profile action. Defaults to /{lang}/nodehive/account. */
|
|
19
18
|
accountHref?: string | null;
|
|
20
|
-
extraActions?: (context: {
|
|
21
|
-
lang: string;
|
|
22
|
-
labels: SmartActionsLabels;
|
|
23
|
-
/** Resolved editor UI locale (Drupal user preference, falls back to lang). */
|
|
24
|
-
editorLocale: string;
|
|
25
|
-
}) => SmartActionsToolbarAction[];
|
|
26
19
|
/**
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
20
|
+
* Composes the toolbar actions (same pattern as PuckWrapper's plugins
|
|
21
|
+
* callback). Receives the default list (profile, backend edit, refresh,
|
|
22
|
+
* logout) plus { lang, labels, editorLocale } and returns the final list.
|
|
23
|
+
* Use it to add, reorder, or remove actions; build locale-aware actions
|
|
24
|
+
* (e.g. the Puck actions) with the provided editorLocale.
|
|
30
25
|
*/
|
|
31
26
|
actions?: SmartActionsBuilder;
|
|
32
27
|
}
|
|
@@ -38,5 +33,5 @@ interface SmartActionsButtonProps {
|
|
|
38
33
|
*
|
|
39
34
|
* Requires the `motion` peer (toolbar animation); see the module README.
|
|
40
35
|
*/
|
|
41
|
-
export default function SmartActionsButton({ lang, nodeId, drupalBaseUrl, launcherIconSrc, createUserClient, logout, dictionaryOverrides, accountHref,
|
|
36
|
+
export default function SmartActionsButton({ lang, nodeId, drupalBaseUrl, launcherIconSrc, createUserClient, logout, dictionaryOverrides, accountHref, actions, }: SmartActionsButtonProps): Promise<import("react").JSX.Element>;
|
|
42
37
|
export {};
|
|
@@ -20,7 +20,6 @@ export default async function SmartActionsButton({
|
|
|
20
20
|
logout,
|
|
21
21
|
dictionaryOverrides,
|
|
22
22
|
accountHref,
|
|
23
|
-
extraActions,
|
|
24
23
|
actions
|
|
25
24
|
}) {
|
|
26
25
|
const {
|
|
@@ -37,16 +36,12 @@ export default async function SmartActionsButton({
|
|
|
37
36
|
});
|
|
38
37
|
const toolbarActions = getSmartActionsConfig({
|
|
39
38
|
lang,
|
|
39
|
+
editorLocale,
|
|
40
40
|
backendEditUrl,
|
|
41
41
|
userImageUrl,
|
|
42
42
|
labels,
|
|
43
43
|
logout,
|
|
44
44
|
accountHref,
|
|
45
|
-
extraActions: extraActions?.({
|
|
46
|
-
lang,
|
|
47
|
-
labels,
|
|
48
|
-
editorLocale
|
|
49
|
-
}),
|
|
50
45
|
buildActions: actions
|
|
51
46
|
});
|
|
52
47
|
return /*#__PURE__*/_jsx(SignedIn, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-actions-button.js","names":["SignedIn","getSmartActionsContext","getSmartActionsConfig","SmartActionsToolbarClient","jsx","_jsx","SmartActionsButton","lang","nodeId","drupalBaseUrl","launcherIconSrc","createUserClient","logout","dictionaryOverrides","accountHref","
|
|
1
|
+
{"version":3,"file":"smart-actions-button.js","names":["SignedIn","getSmartActionsContext","getSmartActionsConfig","SmartActionsToolbarClient","jsx","_jsx","SmartActionsButton","lang","nodeId","drupalBaseUrl","launcherIconSrc","createUserClient","logout","dictionaryOverrides","accountHref","actions","labels","editorLocale","userImageUrl","backendEditUrl","toolbarActions","buildActions","children","collapse","launcherAction"],"sources":["../../../src/smart-actions/internal/smart-actions-button.tsx"],"sourcesContent":["import type { NodeHiveClient } from 'nodehive-js';\n\nimport { SignedIn } from '../../auth/server.ts';\nimport { getSmartActionsContext } from './get-smart-actions-context.ts';\nimport type { SmartActionsDictionaryOverrides } from './i18n.ts';\nimport {\n getSmartActionsConfig,\n type SmartActionsBuilder,\n} from './smart-actions-config.tsx';\nimport SmartActionsToolbarClient from './smart-actions-toolbar-client.tsx';\n\ninterface SmartActionsButtonProps {\n lang: string;\n nodeId?: number;\n /** Drupal base URL for the backend edit deep link. */\n drupalBaseUrl?: string;\n /** Toolbar launcher icon; defaults to /metadata/nodehive-icon.svg from the project public folder. */\n launcherIconSrc?: string;\n /** Project client factory, e.g. createUserClient from the auth binding. */\n createUserClient: () => NodeHiveClient;\n /** Project logout Server Action (Server Action so Next's CSRF applies). */\n logout: () => Promise<void>;\n /** Per-section label overrides merged over the resolved dictionary. */\n dictionaryOverrides?: SmartActionsDictionaryOverrides;\n /** Account link target; null omits the profile action. Defaults to /{lang}/nodehive/account. */\n accountHref?: string | null;\n /**\n * Composes the toolbar actions (same pattern as PuckWrapper's plugins\n * callback). Receives the default list (profile, backend edit, refresh,\n * logout) plus { lang, labels, editorLocale } and returns the final list.\n * Use it to add, reorder, or remove actions; build locale-aware actions\n * (e.g. the Puck actions) with the provided editorLocale.\n */\n actions?: SmartActionsBuilder;\n}\n\n/**\n * Server entry point for the floating editor toolbar. Renders only for a\n * signed-in session (via `<SignedIn>`).\n *\n * Dynamic RSC (reads `cookies()` via the session gate); under `cacheComponents`, mount inside a `<Suspense>` boundary. See the smart-actions README.\n *\n * Requires the `motion` peer (toolbar animation); see the module README.\n */\nexport default async function SmartActionsButton({\n lang,\n nodeId,\n drupalBaseUrl,\n launcherIconSrc,\n createUserClient,\n logout,\n dictionaryOverrides,\n accountHref,\n actions,\n}: SmartActionsButtonProps) {\n const { labels, editorLocale, userImageUrl, backendEditUrl } =\n await getSmartActionsContext({\n createUserClient,\n lang,\n nodeId,\n drupalBaseUrl,\n dictionaryOverrides,\n });\n const toolbarActions = getSmartActionsConfig({\n lang,\n editorLocale,\n backendEditUrl,\n userImageUrl,\n labels,\n logout,\n accountHref,\n buildActions: actions,\n });\n return (\n <SignedIn>\n <SmartActionsToolbarClient\n launcherIconSrc={launcherIconSrc}\n actions={toolbarActions}\n labels={{\n collapse: labels.collapse,\n launcherAction: labels.launcherAction,\n toolbarActions: labels.toolbarActions,\n }}\n />\n </SignedIn>\n );\n}\n"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,sBAAsB;AAC/C,SAASC,sBAAsB,QAAQ,gCAAgC;AAEvE,SACEC,qBAAqB,QAEhB,2BAA4B;AACnC,OAAOC,yBAAyB,MAAM,mCAAoC;AAAC,SAAAC,GAAA,IAAAC,IAAA;AA2B3E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,eAAeC,kBAAkBA,CAAC;EAC/CC,IAAI;EACJC,MAAM;EACNC,aAAa;EACbC,eAAe;EACfC,gBAAgB;EAChBC,MAAM;EACNC,mBAAmB;EACnBC,WAAW;EACXC;AACuB,CAAC,EAAE;EAC1B,MAAM;IAAEC,MAAM;IAAEC,YAAY;IAAEC,YAAY;IAAEC;EAAe,CAAC,GAC1D,MAAMlB,sBAAsB,CAAC;IAC3BU,gBAAgB;IAChBJ,IAAI;IACJC,MAAM;IACNC,aAAa;IACbI;EACF,CAAC,CAAC;EACJ,MAAMO,cAAc,GAAGlB,qBAAqB,CAAC;IAC3CK,IAAI;IACJU,YAAY;IACZE,cAAc;IACdD,YAAY;IACZF,MAAM;IACNJ,MAAM;IACNE,WAAW;IACXO,YAAY,EAAEN;EAChB,CAAC,CAAC;EACF,oBACEV,IAAA,CAACL,QAAQ;IAAAsB,QAAA,eACPjB,IAAA,CAACF,yBAAyB;MACxBO,eAAe,EAAEA,eAAgB;MACjCK,OAAO,EAAEK,cAAe;MACxBJ,MAAM,EAAE;QACNO,QAAQ,EAAEP,MAAM,CAACO,QAAQ;QACzBC,cAAc,EAAER,MAAM,CAACQ,cAAc;QACrCJ,cAAc,EAAEJ,MAAM,CAACI;MACzB;IAAE,CACH;EAAC,CACM,CAAC;AAEf","ignoreList":[]}
|
|
@@ -3,19 +3,20 @@ import type { SmartActionsToolbarAction } from './toolbar/types.js';
|
|
|
3
3
|
export type SmartActionsBuilderContext = {
|
|
4
4
|
lang: string;
|
|
5
5
|
labels: SmartActionsLabels;
|
|
6
|
+
editorLocale: string;
|
|
6
7
|
};
|
|
7
8
|
export type SmartActionsBuilder = (defaults: SmartActionsToolbarAction[], context: SmartActionsBuilderContext) => SmartActionsToolbarAction[];
|
|
8
9
|
type SmartActionsConfigContext = {
|
|
9
10
|
lang: string;
|
|
11
|
+
editorLocale: string;
|
|
10
12
|
backendEditUrl: string | null;
|
|
11
13
|
userImageUrl?: string | null;
|
|
12
14
|
labels: SmartActionsLabels;
|
|
13
15
|
logout: () => Promise<void>;
|
|
14
16
|
/** Account link target; null omits the profile action. Defaults to /{lang}/nodehive/account. */
|
|
15
17
|
accountHref?: string | null;
|
|
16
|
-
|
|
17
|
-
/** Reorders/filters the default actions (profile, extras, backend edit, refresh, logout). */
|
|
18
|
+
/** Composes the default actions (profile, backend edit, refresh, logout). */
|
|
18
19
|
buildActions?: SmartActionsBuilder;
|
|
19
20
|
};
|
|
20
|
-
export declare function getSmartActionsConfig({ lang, backendEditUrl, userImageUrl, labels, logout, accountHref,
|
|
21
|
+
export declare function getSmartActionsConfig({ lang, editorLocale, backendEditUrl, userImageUrl, labels, logout, accountHref, buildActions, }: SmartActionsConfigContext): SmartActionsToolbarAction[];
|
|
21
22
|
export {};
|
|
@@ -4,12 +4,12 @@ import RefreshPage from "./refresh-page.js";
|
|
|
4
4
|
import UserProfile from "./user-profile.js";
|
|
5
5
|
export function getSmartActionsConfig({
|
|
6
6
|
lang,
|
|
7
|
+
editorLocale,
|
|
7
8
|
backendEditUrl,
|
|
8
9
|
userImageUrl,
|
|
9
10
|
labels,
|
|
10
11
|
logout,
|
|
11
12
|
accountHref,
|
|
12
|
-
extraActions = [],
|
|
13
13
|
buildActions
|
|
14
14
|
}) {
|
|
15
15
|
const profileHref = accountHref === undefined ? `/${lang}/nodehive/account` : accountHref;
|
|
@@ -48,10 +48,11 @@ export function getSmartActionsConfig({
|
|
|
48
48
|
label: labels.logout
|
|
49
49
|
}
|
|
50
50
|
}];
|
|
51
|
-
const defaults = [...(profile ? [profile] : []), ...
|
|
51
|
+
const defaults = [...(profile ? [profile] : []), ...rest];
|
|
52
52
|
return buildActions ? buildActions(defaults, {
|
|
53
53
|
lang,
|
|
54
|
-
labels
|
|
54
|
+
labels,
|
|
55
|
+
editorLocale
|
|
55
56
|
}) : defaults;
|
|
56
57
|
}
|
|
57
58
|
//# sourceMappingURL=smart-actions-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-actions-config.js","names":["BackendEditLink","LogoutForm","RefreshPage","UserProfile","getSmartActionsConfig","lang","backendEditUrl","userImageUrl","labels","logout","accountHref","
|
|
1
|
+
{"version":3,"file":"smart-actions-config.js","names":["BackendEditLink","LogoutForm","RefreshPage","UserProfile","getSmartActionsConfig","lang","editorLocale","backendEditUrl","userImageUrl","labels","logout","accountHref","buildActions","profileHref","undefined","profile","id","label","account","Component","props","href","imageUrl","rest","nodeHive","isVisible","Boolean","refresh","defaults"],"sources":["../../../src/smart-actions/internal/smart-actions-config.tsx"],"sourcesContent":["import type { ComponentType } from 'react';\n\nimport BackendEditLink from './backend-edit-link.tsx';\nimport type { SmartActionsLabels } from './i18n.ts';\nimport LogoutForm from './logout-form.tsx';\nimport RefreshPage from './refresh-page.tsx';\nimport type { SmartActionsToolbarAction } from './toolbar/types.ts';\nimport UserProfile from './user-profile.tsx';\n\nexport type SmartActionsBuilderContext = {\n lang: string;\n labels: SmartActionsLabels;\n editorLocale: string;\n};\n\nexport type SmartActionsBuilder = (\n defaults: SmartActionsToolbarAction[],\n context: SmartActionsBuilderContext\n) => SmartActionsToolbarAction[];\n\ntype ActionComponent = ComponentType<Record<string, unknown>>;\n\ntype SmartActionsConfigContext = {\n lang: string;\n editorLocale: string;\n backendEditUrl: string | null;\n userImageUrl?: string | null;\n labels: SmartActionsLabels;\n logout: () => Promise<void>;\n /** Account link target; null omits the profile action. Defaults to /{lang}/nodehive/account. */\n accountHref?: string | null;\n /** Composes the default actions (profile, backend edit, refresh, logout). */\n buildActions?: SmartActionsBuilder;\n};\n\nexport function getSmartActionsConfig({\n lang,\n editorLocale,\n backendEditUrl,\n userImageUrl,\n labels,\n logout,\n accountHref,\n buildActions,\n}: SmartActionsConfigContext): SmartActionsToolbarAction[] {\n const profileHref =\n accountHref === undefined ? `/${lang}/nodehive/account` : accountHref;\n\n const profile: SmartActionsToolbarAction | null =\n profileHref === null\n ? null\n : {\n id: 'user-profile',\n label: labels.account,\n Component: UserProfile as unknown as ActionComponent,\n props: {\n href: profileHref,\n imageUrl: userImageUrl,\n label: labels.account,\n },\n };\n\n const rest: SmartActionsToolbarAction[] = [\n {\n id: 'backend-edit',\n label: labels.nodeHive,\n isVisible: Boolean(backendEditUrl),\n Component: BackendEditLink as unknown as ActionComponent,\n props: { href: backendEditUrl, label: labels.nodeHive },\n },\n {\n id: 'refresh-page',\n label: labels.refresh,\n Component: RefreshPage as unknown as ActionComponent,\n props: { label: labels.refresh },\n },\n {\n id: 'logout',\n label: labels.logout,\n Component: LogoutForm as unknown as ActionComponent,\n props: { logout, label: labels.logout },\n },\n ];\n\n const defaults = [...(profile ? [profile] : []), ...rest];\n return buildActions\n ? buildActions(defaults, { lang, labels, editorLocale })\n : defaults;\n}\n"],"mappings":"AAEA,OAAOA,eAAe,MAAM,wBAAyB;AAErD,OAAOC,UAAU,MAAM,kBAAmB;AAC1C,OAAOC,WAAW,MAAM,mBAAoB;AAE5C,OAAOC,WAAW,MAAM,mBAAoB;AA4B5C,OAAO,SAASC,qBAAqBA,CAAC;EACpCC,IAAI;EACJC,YAAY;EACZC,cAAc;EACdC,YAAY;EACZC,MAAM;EACNC,MAAM;EACNC,WAAW;EACXC;AACyB,CAAC,EAA+B;EACzD,MAAMC,WAAW,GACfF,WAAW,KAAKG,SAAS,GAAG,IAAIT,IAAI,mBAAmB,GAAGM,WAAW;EAEvE,MAAMI,OAAyC,GAC7CF,WAAW,KAAK,IAAI,GAChB,IAAI,GACJ;IACEG,EAAE,EAAE,cAAc;IAClBC,KAAK,EAAER,MAAM,CAACS,OAAO;IACrBC,SAAS,EAAEhB,WAAyC;IACpDiB,KAAK,EAAE;MACLC,IAAI,EAAER,WAAW;MACjBS,QAAQ,EAAEd,YAAY;MACtBS,KAAK,EAAER,MAAM,CAACS;IAChB;EACF,CAAC;EAEP,MAAMK,IAAiC,GAAG,CACxC;IACEP,EAAE,EAAE,cAAc;IAClBC,KAAK,EAAER,MAAM,CAACe,QAAQ;IACtBC,SAAS,EAAEC,OAAO,CAACnB,cAAc,CAAC;IAClCY,SAAS,EAAEnB,eAA6C;IACxDoB,KAAK,EAAE;MAAEC,IAAI,EAAEd,cAAc;MAAEU,KAAK,EAAER,MAAM,CAACe;IAAS;EACxD,CAAC,EACD;IACER,EAAE,EAAE,cAAc;IAClBC,KAAK,EAAER,MAAM,CAACkB,OAAO;IACrBR,SAAS,EAAEjB,WAAyC;IACpDkB,KAAK,EAAE;MAAEH,KAAK,EAAER,MAAM,CAACkB;IAAQ;EACjC,CAAC,EACD;IACEX,EAAE,EAAE,QAAQ;IACZC,KAAK,EAAER,MAAM,CAACC,MAAM;IACpBS,SAAS,EAAElB,UAAwC;IACnDmB,KAAK,EAAE;MAAEV,MAAM;MAAEO,KAAK,EAAER,MAAM,CAACC;IAAO;EACxC,CAAC,CACF;EAED,MAAMkB,QAAQ,GAAG,CAAC,IAAIb,OAAO,GAAG,CAACA,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,GAAGQ,IAAI,CAAC;EACzD,OAAOX,YAAY,GACfA,YAAY,CAACgB,QAAQ,EAAE;IAAEvB,IAAI;IAAEI,MAAM;IAAEH;EAAa,CAAC,CAAC,GACtDsB,QAAQ;AACd","ignoreList":[]}
|
|
@@ -2,4 +2,5 @@ export { getSmartActionsContext, type SmartActionsContext, } from './internal/ge
|
|
|
2
2
|
export type { SmartActionsDictionaryOverrides } from './internal/i18n.js';
|
|
3
3
|
export { default as SmartActionsButton } from './internal/smart-actions-button.js';
|
|
4
4
|
export type { SmartActionsBuilder, SmartActionsBuilderContext, } from './internal/smart-actions-config.js';
|
|
5
|
+
export { insertAfter, insertBefore } from './internal/ordering.js';
|
|
5
6
|
export type { SmartActionsToolbarAction } from './internal/toolbar/types.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Server entry: keeps next/headers-dependent code out of the client index.
|
|
2
2
|
export { getSmartActionsContext } from "./internal/get-smart-actions-context.js";
|
|
3
3
|
export { default as SmartActionsButton } from "./internal/smart-actions-button.js";
|
|
4
|
+
export { insertAfter, insertBefore } from "./internal/ordering.js";
|
|
4
5
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","names":["getSmartActionsContext","default","SmartActionsButton"],"sources":["../../src/smart-actions/server.ts"],"sourcesContent":["// Server entry: keeps next/headers-dependent code out of the client index.\nexport {\n getSmartActionsContext,\n type SmartActionsContext,\n} from './internal/get-smart-actions-context.ts';\nexport type { SmartActionsDictionaryOverrides } from './internal/i18n.ts';\nexport { default as SmartActionsButton } from './internal/smart-actions-button.tsx';\nexport type {\n SmartActionsBuilder,\n SmartActionsBuilderContext,\n} from './internal/smart-actions-config.tsx';\nexport type { SmartActionsToolbarAction } from './internal/toolbar/types.ts';\n"],"mappings":"AAAA;AACA,SACEA,sBAAsB,QAEjB,yCAAyC;AAEhD,SAASC,OAAO,IAAIC,kBAAkB,QAAQ,oCAAqC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"server.js","names":["getSmartActionsContext","default","SmartActionsButton","insertAfter","insertBefore"],"sources":["../../src/smart-actions/server.ts"],"sourcesContent":["// Server entry: keeps next/headers-dependent code out of the client index.\nexport {\n getSmartActionsContext,\n type SmartActionsContext,\n} from './internal/get-smart-actions-context.ts';\nexport type { SmartActionsDictionaryOverrides } from './internal/i18n.ts';\nexport { default as SmartActionsButton } from './internal/smart-actions-button.tsx';\nexport type {\n SmartActionsBuilder,\n SmartActionsBuilderContext,\n} from './internal/smart-actions-config.tsx';\nexport { insertAfter, insertBefore } from './internal/ordering.ts';\nexport type { SmartActionsToolbarAction } from './internal/toolbar/types.ts';\n"],"mappings":"AAAA;AACA,SACEA,sBAAsB,QAEjB,yCAAyC;AAEhD,SAASC,OAAO,IAAIC,kBAAkB,QAAQ,oCAAqC;AAKnF,SAASC,WAAW,EAAEC,YAAY,QAAQ,wBAAwB","ignoreList":[]}
|
package/package.json
CHANGED