@qelos/integrator-next 4.0.1 → 4.1.1

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.
@@ -0,0 +1,90 @@
1
+ import { NextResponse } from 'next/server';
2
+ import { rewriteSetCookieDomain } from '../cookies';
3
+ import { resolveQelosProxyTarget } from '../proxy-target';
4
+ const HOP_BY_HOP = new Set([
5
+ 'connection',
6
+ 'keep-alive',
7
+ 'proxy-authenticate',
8
+ 'proxy-authorization',
9
+ 'te',
10
+ 'trailers',
11
+ 'transfer-encoding',
12
+ 'upgrade',
13
+ ]);
14
+ function buildUpstreamHeaders(req) {
15
+ const out = new Headers();
16
+ req.headers.forEach((value, key) => {
17
+ const lk = key.toLowerCase();
18
+ if (HOP_BY_HOP.has(lk))
19
+ return;
20
+ if (lk === 'host')
21
+ return;
22
+ out.append(key, value);
23
+ });
24
+ return out;
25
+ }
26
+ async function proxyRequest(req, config) {
27
+ const base = resolveQelosProxyTarget(config);
28
+ if (!base) {
29
+ return NextResponse.json({
30
+ error: '[@qelos/integrator-next] Qelos API proxy is not configured. Set appUrl (or NEXT_QELOS_PROXY_TARGET / QELOS_IP / QELOS_API_IP in development).',
31
+ }, { status: 503 });
32
+ }
33
+ const pathWithSearch = req.nextUrl.pathname + req.nextUrl.search;
34
+ const targetUrl = `${base.replace(/\/+$/, '')}${pathWithSearch}`;
35
+ const originalHost = req.headers.get('host');
36
+ const init = {
37
+ method: req.method,
38
+ headers: buildUpstreamHeaders(req),
39
+ redirect: 'manual',
40
+ };
41
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
42
+ init.body = req.body;
43
+ init.duplex = 'half';
44
+ }
45
+ let upstream;
46
+ try {
47
+ upstream = await fetch(targetUrl, init);
48
+ }
49
+ catch {
50
+ return NextResponse.json({ error: 'upstream fetch failed' }, { status: 502 });
51
+ }
52
+ const outHeaders = new Headers();
53
+ upstream.headers.forEach((value, key) => {
54
+ const lk = key.toLowerCase();
55
+ if (lk === 'set-cookie')
56
+ return;
57
+ if (HOP_BY_HOP.has(lk))
58
+ return;
59
+ outHeaders.append(key, value);
60
+ });
61
+ const rawCookies = upstream.headers.getSetCookie?.() ?? [];
62
+ for (const c of rawCookies) {
63
+ outHeaders.append('set-cookie', rewriteSetCookieDomain(c, originalHost ?? undefined));
64
+ }
65
+ return new Response(upstream.body, {
66
+ status: upstream.status,
67
+ statusText: upstream.statusText,
68
+ headers: outHeaders,
69
+ });
70
+ }
71
+ /**
72
+ * Handlers for a catch-all App Router route (e.g. `app/api/[...qelos]/route.ts`)
73
+ * that reverse-proxies every `/api/**` call to Qelos with `Set-Cookie` domain
74
+ * rewriting. Use `export const runtime = 'nodejs'`.
75
+ */
76
+ export function createQelosApiProxyHandlers(config) {
77
+ async function handle(req) {
78
+ return proxyRequest(req, config);
79
+ }
80
+ return {
81
+ runtime: 'nodejs',
82
+ GET: handle,
83
+ POST: handle,
84
+ PUT: handle,
85
+ PATCH: handle,
86
+ DELETE: handle,
87
+ OPTIONS: handle,
88
+ };
89
+ }
90
+ //# sourceMappingURL=api-proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-proxy.js","sourceRoot":"","sources":["../../src/runtime/api-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,YAAY,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAG1D,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC;IACzB,YAAY;IACZ,YAAY;IACZ,oBAAoB;IACpB,qBAAqB;IACrB,IAAI;IACJ,UAAU;IACV,mBAAmB;IACnB,SAAS;CACV,CAAC,CAAC;AAEH,SAAS,oBAAoB,CAAC,GAAgB;IAC5C,MAAM,GAAG,GAAG,IAAI,OAAO,EAAE,CAAC;IAC1B,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE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,EAAE,MAAM;QACX,IAAI,EAAE,MAAM;QACZ,GAAG,EAAE,MAAM;QACX,KAAK,EAAE,MAAM;QACb,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,MAAM;KAChB,CAAC;AACJ,CAAC"}
@@ -1,20 +1,17 @@
1
- import QelosSDK from '@qelos/sdk';
2
- import type { QelosNextConfig, QelosTokenPair, TokenRefreshHook } from './types';
3
- export interface CreateSdkParams<TRefreshTarget = unknown> {
1
+ import type QelosSDKInstance from '@qelos/sdk';
2
+ import type { QelosNextConfig } from './types';
3
+ export interface CreateSdkParams {
4
4
  config: QelosNextConfig;
5
5
  /**
6
- * Tokens for the current request. The factory mutates this object in place
7
- * when a token refresh occurs, so callers can read the latest pair after
8
- * the SDK has been used.
6
+ * Live header source so every SDK call forwards the current request cookies
7
+ * and `Authorization` (no mutable token state).
9
8
  */
10
- tokens: QelosTokenPair;
11
- /**
12
- * Transport-specific carrier passed through to `onTokenRefresh`. Edge
13
- * middleware passes the outbound `NextResponse`; Pages Router passes the
14
- * `NextApiResponse` / `ServerResponse`; App Router server components pass
15
- * `null` because they cannot mutate cookies after rendering starts.
16
- */
17
- refreshTarget: TRefreshTarget;
18
- onTokenRefresh?: TokenRefreshHook<TRefreshTarget>;
9
+ getHeaders: () => {
10
+ cookie?: string;
11
+ authorization?: string;
12
+ } | Promise<{
13
+ cookie?: string;
14
+ authorization?: string;
15
+ }>;
19
16
  }
20
- export declare function createRequestSdk<TRefreshTarget = unknown>({ config, tokens, refreshTarget, onTokenRefresh, }: CreateSdkParams<TRefreshTarget>): QelosSDK;
17
+ export declare function createRequestSdk({ config, getHeaders, }: CreateSdkParams): QelosSDKInstance;
@@ -1,90 +1,40 @@
1
- import QelosSDK from '@qelos/sdk';
2
- const NO_AUTH_URLS = new Set([
3
- '/api/token/refresh',
4
- '/api/cookie/refresh',
5
- '/api/signin',
6
- '/api/signup',
7
- ]);
8
- export function createRequestSdk({ config, tokens, refreshTarget, onTokenRefresh, }) {
9
- let sdk;
10
- let refreshInFlight = null;
11
- const baseOptions = config.sdkOptions || {};
12
- async function performRefresh() {
13
- if (!tokens.refreshToken && !tokens.accessToken) {
14
- throw new Error('no refresh token available');
15
- }
16
- const previous = {
17
- accessToken: tokens.accessToken,
18
- refreshToken: tokens.refreshToken,
19
- };
20
- let refreshed;
21
- if (tokens.refreshToken) {
22
- const result = await sdk.authentication.refreshToken(tokens.refreshToken);
23
- refreshed = {
24
- accessToken: result.payload.token,
25
- refreshToken: result.payload.refreshToken,
26
- };
27
- }
28
- else {
29
- const result = await sdk.authentication.refreshCookieToken(tokens.accessToken);
30
- refreshed = {
31
- accessToken: result.payload.cookieToken,
32
- };
33
- }
34
- tokens.accessToken = refreshed.accessToken;
35
- tokens.refreshToken = refreshed.refreshToken;
36
- if (onTokenRefresh) {
37
- await onTokenRefresh({
38
- target: refreshTarget,
39
- oldTokens: previous,
40
- newTokens: refreshed,
41
- sdk,
42
- });
43
- }
1
+ import sdkModule from '@qelos/sdk';
2
+ function resolveQelosSdkConstructor() {
3
+ const top = sdkModule;
4
+ if (typeof top === 'function') {
5
+ return top;
6
+ }
7
+ const once = top.default;
8
+ if (typeof once === 'function') {
9
+ return once;
44
10
  }
45
- function ensureRefresh() {
46
- if (!refreshInFlight) {
47
- refreshInFlight = performRefresh().finally(() => {
48
- refreshInFlight = null;
49
- });
50
- }
51
- return refreshInFlight;
11
+ const twice = once?.default;
12
+ if (typeof twice === 'function') {
13
+ return twice;
52
14
  }
15
+ throw new Error('[@qelos/integrator-next] Could not resolve QelosSDK constructor from @qelos/sdk');
16
+ }
17
+ const QelosSDK = resolveQelosSdkConstructor();
18
+ export function createRequestSdk({ config, getHeaders, }) {
19
+ const baseOptions = config.sdkOptions || {};
53
20
  const options = {
54
21
  appUrl: config.appUrl,
55
- fetch: globalThis.fetch.bind(globalThis),
56
- forceRefresh: !config.apiToken,
22
+ fetch: globalThis.fetch,
57
23
  ...baseOptions,
58
24
  };
59
25
  if (config.apiToken) {
60
26
  options.apiToken = config.apiToken;
27
+ return new QelosSDK(options);
61
28
  }
62
- else {
63
- if (tokens.accessToken) {
64
- options.accessToken = tokens.accessToken;
65
- }
66
- if (tokens.refreshToken) {
67
- options.refreshToken = tokens.refreshToken;
68
- }
69
- options.extraHeaders = async (relativeUrl, forceRefresh) => {
70
- const headers = {};
71
- if (NO_AUTH_URLS.has(relativeUrl)) {
72
- return headers;
73
- }
74
- if (forceRefresh && (tokens.refreshToken || tokens.accessToken)) {
75
- await ensureRefresh();
76
- }
77
- const token = sdk?.authentication?.accessToken || tokens.accessToken;
78
- if (token) {
79
- headers.authorization = 'Bearer ' + token;
80
- }
81
- return headers;
82
- };
83
- options.onFailedRefreshToken = async () => {
84
- await ensureRefresh();
85
- };
86
- }
87
- sdk = new QelosSDK(options);
88
- return sdk;
29
+ options.extraHeaders = async () => {
30
+ const h = await getHeaders();
31
+ const headers = {};
32
+ if (h.cookie)
33
+ headers.cookie = h.cookie;
34
+ if (h.authorization)
35
+ headers.authorization = h.authorization;
36
+ return headers;
37
+ };
38
+ return new QelosSDK(options);
89
39
  }
90
40
  //# sourceMappingURL=sdk-factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sdk-factory.js","sourceRoot":"","sources":["../src/sdk-factory.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,YAAY,CAAC;AASlC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC;IAC3B,oBAAoB;IACpB,qBAAqB;IACrB,aAAa;IACb,aAAa;CACd,CAAC,CAAC;AAoBH,MAAM,UAAU,gBAAgB,CAA2B,EACzD,MAAM,EACN,MAAM,EACN,aAAa,EACb,cAAc,GACkB;IAChC,IAAI,GAAa,CAAC;IAClB,IAAI,eAAe,GAAyB,IAAI,CAAC;IACjD,MAAM,WAAW,GAAG,MAAM,CAAC,UAAU,IAAI,EAAE,CAAC;IAE5C,KAAK,UAAU,cAAc;QAC3B,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,CAAC,MAAM,CAAC,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AC3C,IAAI,CAAC,CAAC,MAAM;YAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;QACxC,IAAI,CAAC,CAAC,aAAa;YAAE,OAAO,CAAC,aAAa,GAAG,CAAC,CAAC,aAAa,CAAC;QAC7D,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;IAEF,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC/B,CAAC"}
package/dist/types.d.ts CHANGED
@@ -2,30 +2,42 @@ import type QelosSDK from '@qelos/sdk';
2
2
  import type { IUser } from '@qelos/sdk/dist/authentication';
3
3
  import type { IWorkspace } from '@qelos/sdk/workspaces';
4
4
  import type { QelosSDKOptions } from '@qelos/sdk/types';
5
- import type { QelosConfig, QelosContext, QelosTokenPair, ResolvedTokens } from '@qelos/global-types';
6
- export type { QelosTokenPair, ResolvedTokens } from '@qelos/global-types';
7
- export interface QelosNextConfig extends QelosConfig {
5
+ export interface QelosNextConfig {
6
+ /**
7
+ * Base URL of the Qelos backend (e.g. https://yourdomain.com).
8
+ */
9
+ appUrl: string;
10
+ /**
11
+ * Static API token used for service-to-service calls. When provided, no
12
+ * cookie-based `/api/me` identification is required for anonymous access.
13
+ */
14
+ apiToken?: string;
15
+ /**
16
+ * If true, the request is rejected (401) when the user cannot be resolved.
17
+ * Defaults to `false` — anonymous requests pass through with `user = null`.
18
+ */
19
+ requireAuth?: boolean;
20
+ /**
21
+ * Skip the middleware / resolver entirely for requests matching any of these
22
+ * path prefixes. Useful for `/_next`, `/favicon.ico`, `/health`, etc.
23
+ */
24
+ skipPaths?: string[];
8
25
  /**
9
26
  * Optional extra options merged into the per-request SDK instance.
10
27
  */
11
28
  sdkOptions?: Partial<QelosSDKOptions>;
12
- }
13
- export interface TokenRefreshContext<TRefreshTarget = unknown> {
14
29
  /**
15
- * The transport-specific carrier for the refresh hook. For App Router edge
16
- * middleware this is the outbound `NextResponse`; for Pages Router API
17
- * routes it is the `NextApiResponse`; for `getServerSideProps` it is the
18
- * raw `ServerResponse`. App Router server components / route handlers do
19
- * not call this hook because cookies cannot be set after the response has
20
- * started — the refreshed tokens are only mutated on the in-memory pair.
30
+ * When `false` (default), Edge middleware prepends `/api/` to `skipPaths` so
31
+ * the catch-all BFF proxy route is not shadowed by the `/api/me` probe.
21
32
  */
22
- target: TRefreshTarget;
23
- oldTokens: QelosTokenPair;
24
- newTokens: ResolvedTokens;
33
+ disableProxy?: boolean;
34
+ }
35
+ export interface QelosRequestContext {
36
+ user: IUser | null;
37
+ workspace: IWorkspace | null;
38
+ workspaces: IWorkspace[];
25
39
  sdk: QelosSDK;
26
40
  }
27
- export type TokenRefreshHook<TRefreshTarget = unknown> = (ctx: TokenRefreshContext<TRefreshTarget>) => void | Promise<void>;
28
- export type QelosRequestContext = QelosContext<QelosSDK, IUser, IWorkspace>;
29
41
  /**
30
42
  * Header name used to forward the resolved user id from edge middleware to
31
43
  * downstream App Router handlers. Handlers that want the full user object
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAyCA;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA2CA;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAEnD;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,sBAAsB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qelos/integrator-next",
3
- "version": "4.0.1",
3
+ "version": "4.1.1",
4
4
  "description": "Qelos integrator middleware for Next.js (App Router and Pages Router): identifies the user and workspace via the Qelos SDK before the application's own handler runs.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -70,7 +70,7 @@
70
70
  }
71
71
  },
72
72
  "dependencies": {
73
- "@qelos/sdk": "4.0.0"
73
+ "@qelos/sdk": "4.1.1"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@types/node": "^22.5.4",