@qelos/integrator-next 4.0.1 → 4.1.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/context.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { IUser } from '@qelos/sdk/dist/authentication';
2
2
  import type { IWorkspace } from '@qelos/sdk/workspaces';
3
- import type { QelosNextConfig, QelosRequestContext, TokenRefreshHook } from './types';
3
+ import type { QelosNextConfig, QelosRequestContext } from './types';
4
4
  /**
5
5
  * Run `fn` with `ctx` as the active Qelos request context. Code anywhere in
6
6
  * the resulting async stack can call `getStoredQelosContext()` to retrieve it
@@ -15,15 +15,9 @@ export declare function getStoredQelosContext(): QelosRequestContext | null;
15
15
  export interface GetQelosContextOptions {
16
16
  config: QelosNextConfig;
17
17
  /**
18
- * Hook invoked after a successful token refresh. App Router server
19
- * components and route handlers cannot mutate cookies after rendering
20
- * starts, so the default is a no-op. Callers handling refresh through a
21
- * route handler can override this to call `cookies().set(...)`.
22
- */
23
- onTokenRefresh?: TokenRefreshHook<null>;
24
- /**
25
- * Resolve the active workspace for a request. Defaults to picking the first
26
- * workspace returned from `sdk.workspaces.getList()`.
18
+ * Resolve the active workspace for a request. Defaults to whatever
19
+ * `/api/me` reports on `user.workspace` (the user's currently activated
20
+ * workspace, or `null` when none is active).
27
21
  */
28
22
  resolveWorkspace?: (params: {
29
23
  user: IUser;
@@ -33,7 +27,7 @@ export interface GetQelosContextOptions {
33
27
  /**
34
28
  * Identify the user / workspace for the current App Router request and
35
29
  * return the Qelos context. Safe to call multiple times within the same
36
- * request — each call performs its own SDK round-trip, so wrap it with
30
+ * request — each call performs its own `/api/me` round-trip, so wrap it with
37
31
  * React's `cache()` if you want a single resolution per render.
38
32
  *
39
33
  * Calling without arguments uses the env-derived config (see
package/dist/context.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { rewriteSetCookieDomain } from './cookies';
2
3
  import { getDefaultQelosConfig } from './env-config';
4
+ import { fetchMeIdentity } from './me-client';
5
+ import { resolveQelosProxyTarget } from './proxy-target';
3
6
  import { createRequestSdk } from './sdk-factory';
4
- const DEFAULT_ACCESS_COOKIE = 'q_access_token';
5
- const DEFAULT_REFRESH_COOKIE = 'q_refresh_token';
6
7
  const storage = new AsyncLocalStorage();
7
8
  /**
8
9
  * Run `fn` with `ctx` as the active Qelos request context. Code anywhere in
@@ -29,27 +30,46 @@ function loadNextHeaders() {
29
30
  }
30
31
  return nextHeadersModulePromise;
31
32
  }
32
- async function readTokensFromHeaders(config) {
33
- const { cookies, headers } = await loadNextHeaders();
34
- const accessCookie = config.accessTokenCookie || DEFAULT_ACCESS_COOKIE;
35
- const refreshCookie = config.refreshTokenCookie || DEFAULT_REFRESH_COOKIE;
36
- const jar = await cookies();
37
- const hdr = await headers();
38
- const cookieAccess = jar.get(accessCookie)?.value;
39
- const cookieRefresh = jar.get(refreshCookie)?.value;
40
- const authHeader = hdr.get('authorization');
41
- const headerAccess = authHeader && authHeader.toLowerCase().startsWith('bearer ')
42
- ? authHeader.slice(7).trim()
43
- : undefined;
33
+ async function getInboundAuthHeaders() {
34
+ const { headers } = await loadNextHeaders();
35
+ const hdr = await Promise.resolve(headers());
44
36
  return {
45
- accessToken: headerAccess || cookieAccess || undefined,
46
- refreshToken: cookieRefresh || undefined,
37
+ cookie: hdr.get('cookie') ?? undefined,
38
+ authorization: hdr.get('authorization') ?? undefined,
39
+ host: hdr.get('host'),
47
40
  };
48
41
  }
42
+ async function forwardSetCookieThroughNextCookies(rawLines, originalHost) {
43
+ const rewritten = rawLines.map((v) => rewriteSetCookieDomain(v, originalHost ?? undefined));
44
+ try {
45
+ const { cookies } = await import('next/headers');
46
+ const jar = await Promise.resolve(cookies());
47
+ for (const line of rewritten) {
48
+ const semi = line.indexOf(';');
49
+ const nv = (semi === -1 ? line : line.slice(0, semi)).trim();
50
+ const eq = nv.indexOf('=');
51
+ if (eq <= 0)
52
+ continue;
53
+ const name = nv.slice(0, eq).trim();
54
+ const value = nv.slice(eq + 1).trim();
55
+ if (!name)
56
+ continue;
57
+ try {
58
+ jar.set(name, value, { path: '/' });
59
+ }
60
+ catch {
61
+ // not writable in this context
62
+ }
63
+ }
64
+ }
65
+ catch {
66
+ //
67
+ }
68
+ }
49
69
  /**
50
70
  * Identify the user / workspace for the current App Router request and
51
71
  * return the Qelos context. Safe to call multiple times within the same
52
- * request — each call performs its own SDK round-trip, so wrap it with
72
+ * request — each call performs its own `/api/me` round-trip, so wrap it with
53
73
  * React's `cache()` if you want a single resolution per render.
54
74
  *
55
75
  * Calling without arguments uses the env-derived config (see
@@ -59,49 +79,49 @@ async function readTokensFromHeaders(config) {
59
79
  export async function getQelosContext(options) {
60
80
  const resolved = options ?? { config: getDefaultQelosConfig() };
61
81
  const { config, resolveWorkspace } = resolved;
62
- const tokens = await readTokensFromHeaders(config);
63
- const sdk = createRequestSdk({
64
- config,
65
- tokens,
66
- refreshTarget: null,
67
- onTokenRefresh: resolved.onTokenRefresh,
68
- });
82
+ const getHeaders = () => getInboundAuthHeaders();
83
+ const sdk = createRequestSdk({ config, getHeaders });
69
84
  const ctx = {
70
85
  user: null,
71
86
  workspace: null,
72
87
  workspaces: [],
73
88
  sdk,
74
- tokens,
75
89
  };
76
- const hasAuthMaterial = Boolean(config.apiToken || tokens.accessToken || tokens.refreshToken);
77
- if (!hasAuthMaterial) {
90
+ const base = resolveQelosProxyTarget(config);
91
+ if (!base && !config.apiToken) {
78
92
  return ctx;
79
93
  }
80
- try {
81
- ctx.user = await sdk.authentication.getLoggedInUser();
94
+ if (base) {
95
+ const h = await getInboundAuthHeaders();
96
+ const { response, user } = await fetchMeIdentity({
97
+ base,
98
+ cookie: h.cookie,
99
+ authorization: h.authorization,
100
+ });
101
+ const setCookieValues = response.headers.getSetCookie?.() ?? [];
102
+ await forwardSetCookieThroughNextCookies(setCookieValues, h.host);
103
+ ctx.user = user;
82
104
  }
83
- catch {
105
+ if (!ctx.user) {
84
106
  return ctx;
85
107
  }
86
- if (!ctx.user)
87
- return ctx;
88
108
  try {
89
109
  ctx.workspaces = await sdk.workspaces.getList();
90
110
  }
91
111
  catch {
92
112
  ctx.workspaces = [];
93
113
  }
94
- if (ctx.workspaces.length) {
95
- if (resolveWorkspace) {
96
- ctx.workspace =
97
- (await resolveWorkspace({
98
- user: ctx.user,
99
- workspaces: ctx.workspaces,
100
- })) || null;
101
- }
102
- else {
103
- ctx.workspace = ctx.workspaces[0] || null;
104
- }
114
+ if (resolveWorkspace) {
115
+ ctx.workspace =
116
+ (await resolveWorkspace({
117
+ user: ctx.user,
118
+ workspaces: ctx.workspaces,
119
+ })) || null;
120
+ }
121
+ else {
122
+ ctx.workspace =
123
+ ctx.user.workspace ||
124
+ null;
105
125
  }
106
126
  return ctx;
107
127
  }
@@ -1 +1 @@
1
- {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAQjD,MAAM,qBAAqB,GAAG,gBAAgB,CAAC;AAC/C,MAAM,sBAAsB,GAAG,iBAAiB,CAAC;AAEjD,MAAM,OAAO,GAAG,IAAI,iBAAiB,EAAuB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAwB,EACxB,EAAwB;IAExB,OAAO,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;AAC9B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,OAAO,CAAC,QAAQ,EAAE,IAAI,IAAI,CAAC;AACpC,CAAC;AAsCD,IAAI,wBAAwB,GAAsC,IAAI,CAAC;AACvE,SAAS,eAAe;IACtB,IAAI,CAAC,wBAAwB,EAAE,CAAC;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GAAG,CAAC,UAAU;aAC3B,CAAC,CAAC,IAAI,IAAI,CAAC;IAChB,CAAC;SAAM,CAAC;QACN,GAAG,CAAC,SAAS;YACV,GAAG,CAAC,IAAqD,CAAC,SAAS;gBACpE,IAAI,CAAC;IACT,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAA+B,EAC/B,EAAgD;IAEhD,MAAM,GAAG,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC;IAC3C,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAChE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,GAAG,GAAG,qBAAqB,EAAE,CAAC;IACpC,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,IAAI,KAAK,CAAC,cAAc,CAAgC,CAAC;QACrE,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC;QACjB,MAAM,GAAG,CAAC;IACZ,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Rewrite the `Domain=` attribute of a single `Set-Cookie` header value.
3
+ *
4
+ * - If the cookie contains a `Domain=<value>` attribute (case-insensitive), its
5
+ * value is replaced with `newDomain`, with any trailing `:port` suffix
6
+ * stripped first (cookie `Domain` attributes do not include a port).
7
+ * - If `newDomain` is `undefined` (or empty), the entire `; Domain=<value>`
8
+ * segment is removed so the browser scopes the cookie to the current host.
9
+ * - If no `Domain=` attribute is present, the input is returned unchanged.
10
+ *
11
+ * All other attributes, their casing/order and the original cookie name/value
12
+ * bytes are preserved.
13
+ */
14
+ export declare function rewriteSetCookieDomain(setCookie: string, newDomain: string | undefined): string;
15
+ /**
16
+ * Apply {@link rewriteSetCookieDomain} to each entry of a `Set-Cookie` array
17
+ * (e.g. the result of `Headers.getSetCookie()`).
18
+ */
19
+ export declare function rewriteSetCookieDomains(values: string[], newDomain: string | undefined): string[];
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Rewrite the `Domain=` attribute of a single `Set-Cookie` header value.
3
+ *
4
+ * - If the cookie contains a `Domain=<value>` attribute (case-insensitive), its
5
+ * value is replaced with `newDomain`, with any trailing `:port` suffix
6
+ * stripped first (cookie `Domain` attributes do not include a port).
7
+ * - If `newDomain` is `undefined` (or empty), the entire `; Domain=<value>`
8
+ * segment is removed so the browser scopes the cookie to the current host.
9
+ * - If no `Domain=` attribute is present, the input is returned unchanged.
10
+ *
11
+ * All other attributes, their casing/order and the original cookie name/value
12
+ * bytes are preserved.
13
+ */
14
+ export function rewriteSetCookieDomain(setCookie, newDomain) {
15
+ const domainSegment = /;\s*Domain\s*=\s*[^;]+/i;
16
+ if (!domainSegment.test(setCookie))
17
+ return setCookie;
18
+ const stripped = newDomain ? stripPort(newDomain) : '';
19
+ if (!stripped) {
20
+ return setCookie.replace(domainSegment, '');
21
+ }
22
+ return setCookie.replace(/(;\s*Domain\s*=\s*)[^;]+/i, `$1${stripped}`);
23
+ }
24
+ /**
25
+ * Apply {@link rewriteSetCookieDomain} to each entry of a `Set-Cookie` array
26
+ * (e.g. the result of `Headers.getSetCookie()`).
27
+ */
28
+ export function rewriteSetCookieDomains(values, newDomain) {
29
+ return values.map((value) => rewriteSetCookieDomain(value, newDomain));
30
+ }
31
+ function stripPort(host) {
32
+ if (host.startsWith('[')) {
33
+ const end = host.indexOf(']');
34
+ return end === -1 ? host : host.slice(1, end);
35
+ }
36
+ const colon = host.indexOf(':');
37
+ return colon === -1 ? host : host.slice(0, colon);
38
+ }
39
+ //# sourceMappingURL=cookies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookies.js","sourceRoot":"","sources":["../src/cookies.ts"],"names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8,11 +8,11 @@ import type { QelosNextConfig } from './types';
8
8
  * Recognized variables:
9
9
  *
10
10
  * - `QELOS_APP_URL` (required) — Qelos backend base URL.
11
- * - `QELOS_API_TOKEN` — service-to-service token (skips refresh logic).
12
- * - `QELOS_ACCESS_TOKEN_COOKIE` — defaults to `q_access_token`.
13
- * - `QELOS_REFRESH_TOKEN_COOKIE` — defaults to `q_refresh_token`.
11
+ * - `QELOS_API_TOKEN` — service-to-service token (skips cookie identity).
14
12
  * - `QELOS_REQUIRE_AUTH` — `"true"` to reject anonymous requests.
15
13
  * - `QELOS_SKIP_PATHS` — comma-separated path prefixes to bypass.
14
+ * - `QELOS_DISABLE_PROXY` — `"true"` to disable auto `/api/` skip in middleware
15
+ * (when you are not using the BFF catch-all proxy).
16
16
  */
17
17
  export declare function loadQelosConfigFromEnv(env?: NodeJS.ProcessEnv): QelosNextConfig;
18
18
  /**
@@ -7,11 +7,11 @@
7
7
  * Recognized variables:
8
8
  *
9
9
  * - `QELOS_APP_URL` (required) — Qelos backend base URL.
10
- * - `QELOS_API_TOKEN` — service-to-service token (skips refresh logic).
11
- * - `QELOS_ACCESS_TOKEN_COOKIE` — defaults to `q_access_token`.
12
- * - `QELOS_REFRESH_TOKEN_COOKIE` — defaults to `q_refresh_token`.
10
+ * - `QELOS_API_TOKEN` — service-to-service token (skips cookie identity).
13
11
  * - `QELOS_REQUIRE_AUTH` — `"true"` to reject anonymous requests.
14
12
  * - `QELOS_SKIP_PATHS` — comma-separated path prefixes to bypass.
13
+ * - `QELOS_DISABLE_PROXY` — `"true"` to disable auto `/api/` skip in middleware
14
+ * (when you are not using the BFF catch-all proxy).
15
15
  */
16
16
  export function loadQelosConfigFromEnv(env = process.env) {
17
17
  const appUrl = env.QELOS_APP_URL;
@@ -23,13 +23,12 @@ export function loadQelosConfigFromEnv(env = process.env) {
23
23
  const config = { appUrl };
24
24
  if (env.QELOS_API_TOKEN)
25
25
  config.apiToken = env.QELOS_API_TOKEN;
26
- if (env.QELOS_ACCESS_TOKEN_COOKIE)
27
- config.accessTokenCookie = env.QELOS_ACCESS_TOKEN_COOKIE;
28
- if (env.QELOS_REFRESH_TOKEN_COOKIE)
29
- config.refreshTokenCookie = env.QELOS_REFRESH_TOKEN_COOKIE;
30
26
  if (env.QELOS_REQUIRE_AUTH === 'true' || env.QELOS_REQUIRE_AUTH === '1') {
31
27
  config.requireAuth = true;
32
28
  }
29
+ if (env.QELOS_DISABLE_PROXY === 'true' || env.QELOS_DISABLE_PROXY === '1') {
30
+ config.disableProxy = true;
31
+ }
33
32
  if (env.QELOS_SKIP_PATHS) {
34
33
  config.skipPaths = env.QELOS_SKIP_PATHS.split(',')
35
34
  .map((p) => p.trim())
@@ -1 +1 @@
1
- {"version":3,"file":"env-config.js","sourceRoot":"","sources":["../src/env-config.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAyB,OAAO,CAAC,GAAG;IACzE,MAAM,MAAM,GAAG,GAAG,CAAC,aAAa,CAAC;IACjC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CACb,2EAA2E;YACzE,0EAA0E;YAC1E,4DAA4D,CAC/D,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAoB,EAAE,MAAM,EAAE,CAAC;IAC3C,IAAI,GAAG,CAAC,eAAe;QAAE,MAAM,CAAC,QAAQ,GAAG,GAAG,CAAC,eAAe,CAAC;IAC/D,IAAI,GAAG,CAAC,yBAAyB;QAAE,MAAM,CAAC,iBAAiB,GAAG,GAAG,CAAC,yBAAyB,CAAC;IAC5F,IAAI,GAAG,CAAC,0BAA0B;QAAE,MAAM,CAAC,kBAAkB,GAAG,GAAG,CAAC,0BAA0B,CAAC;IAC/F,IAAI,GAAG,CAAC,kBAAkB,KAAK,MAAM,IAAI,GAAG,CAAC,kBAAkB,KAAK,GAAG,EAAE,CAAC;QACxE,MAAM,CAAC,WAAW,GAAG,IAAI,CAAC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AK,MAAM,IAAI,GAAG,CAAC,mBAAmB,KAAK,GAAG,EAAE,CAAC;QAC1E,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC;IAC7B,CAAC;IACD,IAAI,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACzB,MAAM,CAAC,SAAS,GAAG,GAAG,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC;aAC/C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aACpB,MAAM,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,IAAI,YAAY,GAA2B,IAAI,CAAC;AAEhD;;;;GAIG;AACH,MAAM,UAAU,qBAAqB;IACnC,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,sBAAsB,EAAE,CAAC;IAC1C,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB;IACvC,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- export { createQelosMiddleware, qelosMiddleware, type CreateMiddlewareOptions, type MiddlewareRefreshTarget, type PendingCookie, type QelosMiddleware, } from './middleware';
1
+ export { createQelosMiddleware, qelosMiddleware, type CreateMiddlewareOptions, type QelosMiddleware, } from './middleware';
2
2
  export { loadQelosConfigFromEnv, getDefaultQelosConfig, } from './env-config';
3
- export { createRequestSdk, type CreateSdkParams, } from './sdk-factory';
3
+ export { createRequestSdk, type CreateSdkParams } from './sdk-factory';
4
4
  export { getQelosContext, withQelosContext, runWithQelosContext, getStoredQelosContext, requireQelosUser, type GetQelosContextOptions, } from './context';
5
5
  export { withQelosApi, withQelosSSR, requireQelosApiUser, type PagesIntegratorOptions, } from './pages';
6
6
  export { withQelosRoute, type AppRouteHandler, type QelosAppRouteHandler, } from './route';
7
- export { QELOS_USER_HEADER, QELOS_WORKSPACE_HEADER, type QelosNextConfig, type QelosRequestContext, type QelosTokenPair, type ResolvedTokens, type TokenRefreshContext, type TokenRefreshHook, } from './types';
7
+ export { QELOS_USER_HEADER, QELOS_WORKSPACE_HEADER, type QelosNextConfig, type QelosRequestContext, } from './types';
8
+ export { rewriteSetCookieDomain, rewriteSetCookieDomains } from './cookies';
9
+ export { resolveQelosProxyTarget } from './proxy-target';
10
+ export { createQelosApiProxyHandlers } from './runtime/api-proxy';
8
11
  export { completeSocialAuthCallback, applySocialAuthCookiesToServerResponse, getSocialAuthSetCookieParts, parseSocialCallbackRefreshToken, type SocialAuthCallbackPayload, type SocialCallbackInput, } from './social-auth';
package/dist/index.js CHANGED
@@ -1,9 +1,12 @@
1
1
  export { createQelosMiddleware, qelosMiddleware, } from './middleware';
2
2
  export { loadQelosConfigFromEnv, getDefaultQelosConfig, } from './env-config';
3
- export { createRequestSdk, } from './sdk-factory';
3
+ export { createRequestSdk } from './sdk-factory';
4
4
  export { getQelosContext, withQelosContext, runWithQelosContext, getStoredQelosContext, requireQelosUser, } from './context';
5
5
  export { withQelosApi, withQelosSSR, requireQelosApiUser, } from './pages';
6
6
  export { withQelosRoute, } from './route';
7
7
  export { QELOS_USER_HEADER, QELOS_WORKSPACE_HEADER, } from './types';
8
+ export { rewriteSetCookieDomain, rewriteSetCookieDomains } from './cookies';
9
+ export { resolveQelosProxyTarget } from './proxy-target';
10
+ export { createQelosApiProxyHandlers } from './runtime/api-proxy';
8
11
  export { completeSocialAuthCallback, applySocialAuthCookiesToServerResponse, getSocialAuthSetCookieParts, parseSocialCallbackRefreshToken, } from './social-auth';
9
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,eAAe,GAKhB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,sBAAsB,EACtB,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EACtC,2BAA2B,EAC3B,+BAA+B,GAGhC,MAAM,eAAe,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { IUser } from '@qelos/sdk/dist/authentication';
2
+ export declare function buildMeUrl(base: string): string;
3
+ export interface FetchMeIdentityParams {
4
+ base: string;
5
+ cookie?: string;
6
+ authorization?: string;
7
+ }
8
+ /**
9
+ * Server-side `GET /api/me` against Qelos with inbound auth material forwarded.
10
+ * Does not rewrite `Set-Cookie`; callers apply {@link rewriteSetCookieDomain}.
11
+ */
12
+ export declare function fetchMeIdentity(params: FetchMeIdentityParams): Promise<{
13
+ response: Response;
14
+ user: IUser | null;
15
+ }>;
@@ -0,0 +1,35 @@
1
+ export function buildMeUrl(base) {
2
+ return `${base.replace(/\/+$/, '')}/api/me`;
3
+ }
4
+ /**
5
+ * Server-side `GET /api/me` against Qelos with inbound auth material forwarded.
6
+ * Does not rewrite `Set-Cookie`; callers apply {@link rewriteSetCookieDomain}.
7
+ */
8
+ export async function fetchMeIdentity(params) {
9
+ const headers = {};
10
+ if (params.cookie)
11
+ headers.cookie = params.cookie;
12
+ if (params.authorization)
13
+ headers.authorization = params.authorization;
14
+ let response;
15
+ try {
16
+ response = await fetch(buildMeUrl(params.base), {
17
+ method: 'GET',
18
+ headers,
19
+ redirect: 'manual',
20
+ });
21
+ }
22
+ catch {
23
+ return { response: new Response(null, { status: 502 }), user: null };
24
+ }
25
+ if (!response.ok) {
26
+ return { response, user: null };
27
+ }
28
+ try {
29
+ return { response, user: (await response.json()) };
30
+ }
31
+ catch {
32
+ return { response, user: null };
33
+ }
34
+ }
35
+ //# sourceMappingURL=me-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"me-client.js","sourceRoot":"","sources":["../src/me-client.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC;AAC9C,CAAC;AAQD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAA6B;IAE7B,MAAM,OAAO,GAA2B,EAAE,CAAC;IAC3C,IAAI,MAAM,CAAC,MAAM;QAAE,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAClD,IAAI,MAAM,CAAC,aAAa;QAAE,OAAO,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;IAEvE,IAAI,QAAkB,CAAC;IACvB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YAC9C,MAAM,EAAE,KAAK;YACb,OAAO;YACP,QAAQ,EAAE,QAAQ;SACnB,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,QAAQ,EAAE,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACvE,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAClC,CAAC;IAED,IAAI,CAAC;QACH,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAU,EAAE,CAAC;IAC9D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAClC,CAAC;AACH,CAAC"}
@@ -1,38 +1,13 @@
1
1
  import { NextResponse, type NextRequest } from 'next/server';
2
2
  import type { IUser } from '@qelos/sdk/dist/authentication';
3
3
  import type { IWorkspace } from '@qelos/sdk/workspaces';
4
- import type { QelosNextConfig, TokenRefreshHook } from './types';
5
- export interface PendingCookie {
6
- name: string;
7
- value: string;
8
- options: {
9
- httpOnly: boolean;
10
- secure: boolean;
11
- sameSite: 'lax' | 'strict' | 'none';
12
- path: string;
13
- };
14
- }
15
- /**
16
- * Carrier passed to the App Router middleware token-refresh hook. Cookies
17
- * pushed onto `pendingCookies` are written to the outbound `NextResponse`
18
- * after identification completes — Next.js does not let us mutate the
19
- * response headers after `NextResponse.next()` has been constructed, so we
20
- * stage them here and flush them once the response object exists.
21
- */
22
- export interface MiddlewareRefreshTarget {
23
- req: NextRequest;
24
- pendingCookies: PendingCookie[];
25
- }
4
+ import type { QelosNextConfig } from './types';
26
5
  export interface CreateMiddlewareOptions {
27
6
  config: QelosNextConfig;
28
7
  /**
29
- * Hook invoked after a successful token refresh. The default implementation
30
- * stages new cookies for the outbound response.
31
- */
32
- onTokenRefresh?: TokenRefreshHook<MiddlewareRefreshTarget>;
33
- /**
34
- * Resolve the active workspace for a request. Defaults to picking the first
35
- * workspace returned from `sdk.workspaces.getList()`.
8
+ * Resolve the active workspace for a request. Defaults to whatever
9
+ * `/api/me` reports on `user.workspace` (the user's currently activated
10
+ * workspace, or `null` when none is active).
36
11
  */
37
12
  resolveWorkspace?: (params: {
38
13
  req: NextRequest;
@@ -43,11 +18,12 @@ export interface CreateMiddlewareOptions {
43
18
  export type QelosMiddleware = (req: NextRequest) => Promise<NextResponse>;
44
19
  /**
45
20
  * Create a Next.js (App Router) edge middleware that identifies the user and
46
- * the active workspace via the Qelos SDK before the request reaches the
47
- * application's own handler. Resolved identity is forwarded to downstream
48
- * handlers via request headers (`x-qelos-user-id`, `x-qelos-workspace-id`);
49
- * use `getQelosContext()` from `@qelos/integrator-next/context` to obtain the
50
- * full user / workspace objects inside server components or route handlers.
21
+ * the active workspace via a same-origin BFF round-trip to Qelos `GET /api/me`
22
+ * before the request reaches the application's own handler. Resolved identity
23
+ * is forwarded to downstream handlers via request headers (`x-qelos-user-id`,
24
+ * `x-qelos-workspace-id`); use `getQelosContext()` from
25
+ * `@qelos/integrator-next/context` to obtain the full user / workspace objects
26
+ * inside server components or route handlers.
51
27
  */
52
28
  export declare function createQelosMiddleware(options: CreateMiddlewareOptions): QelosMiddleware;
53
29
  /**