ras-stack 0.10.0 → 0.11.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/README.md +12 -2
- package/dist/tanstack/server.d.ts +14 -1
- package/dist/tanstack/server.js +18 -1
- package/dist/tanstack/server.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,7 +70,13 @@ The optional TanStack entrypoints bind the shared primitives to TanStack Start's
|
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
72
|
import { createStackQueryClient } from 'ras-stack/tanstack/query'
|
|
73
|
-
import {
|
|
73
|
+
import {
|
|
74
|
+
betterAuthHandlers,
|
|
75
|
+
canonicalHostMiddleware,
|
|
76
|
+
createTanStackRpc,
|
|
77
|
+
requireTanStackMutationOrigin,
|
|
78
|
+
tanStackHealthHandler,
|
|
79
|
+
} from 'ras-stack/tanstack/server'
|
|
74
80
|
|
|
75
81
|
export const { rpc, mutationRpc } = createTanStackRpc({
|
|
76
82
|
requireMutation: (request) =>
|
|
@@ -84,9 +90,13 @@ export const { rpc, mutationRpc } = createTanStackRpc({
|
|
|
84
90
|
})
|
|
85
91
|
|
|
86
92
|
export const queryClient = createStackQueryClient()
|
|
93
|
+
|
|
94
|
+
export const authHandlers = betterAuthHandlers(() => app().auth)
|
|
95
|
+
export const healthHandler = tanStackHealthHandler(() => app().database.get(sql`SELECT 1`))
|
|
96
|
+
export const canonicalHost = canonicalHostMiddleware(() => ({ canonicalUrl: process.env.APP_URL }))
|
|
87
97
|
```
|
|
88
98
|
|
|
89
|
-
Applications still own their auth clients, authorization,
|
|
99
|
+
Applications still own their auth clients, authorization, file-route declarations, router, logging, health-check work, and Query configuration. Both integrations remain optional, and their upstream libraries remain directly accessible.
|
|
90
100
|
|
|
91
101
|
Only enable `trustForwardedHeaders` behind a proxy that replaces incoming forwarded headers. Otherwise a client could choose the origin used by the check.
|
|
92
102
|
|
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { type OriginOptions } from '../auth/index.js';
|
|
2
|
-
import { type RpcOptions } from '../server/index.js';
|
|
2
|
+
import { type CanonicalRedirectOptions, type HealthResponseOptions, type RpcOptions } from '../server/index.js';
|
|
3
3
|
export type TanStackRpcOptions = Omit<RpcOptions, 'getRequest'> & Pick<RpcOptions, 'getRequest'>;
|
|
4
4
|
export declare function createTanStackRpc(options?: TanStackRpcOptions): {
|
|
5
5
|
rpc: <T>(work: () => Promise<T> | T) => Promise<T>;
|
|
6
6
|
mutationRpc: <T>(work: () => Promise<T> | T, request?: Request | undefined) => Promise<T>;
|
|
7
7
|
};
|
|
8
8
|
export declare function requireTanStackMutationOrigin(options?: OriginOptions, request?: Request): void;
|
|
9
|
+
type RequestContext = {
|
|
10
|
+
request: Request;
|
|
11
|
+
};
|
|
12
|
+
export declare function betterAuthHandlers(resolveAuth: () => {
|
|
13
|
+
handler(request: Request): Response | Promise<Response>;
|
|
14
|
+
}): {
|
|
15
|
+
GET: ({ request }: RequestContext) => Promise<Response> | Response;
|
|
16
|
+
POST: ({ request }: RequestContext) => Promise<Response> | Response;
|
|
17
|
+
};
|
|
18
|
+
export declare function tanStackHealthHandler(check: () => void | Promise<void>, options?: HealthResponseOptions): () => Promise<Response>;
|
|
19
|
+
export declare function canonicalHostRequest<T>(request: Request, next: () => T, options: CanonicalRedirectOptions): Response | T;
|
|
20
|
+
export declare function canonicalHostMiddleware(resolveOptions: () => CanonicalRedirectOptions): import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
21
|
+
export {};
|
package/dist/tanstack/server.js
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import { getRequest } from '@tanstack/react-start/server';
|
|
2
|
+
import { createMiddleware } from '@tanstack/react-start';
|
|
2
3
|
import { requireSameOrigin } from '../auth/index.js';
|
|
3
|
-
import { createRpc } from '../server/index.js';
|
|
4
|
+
import { canonicalRedirect, createRpc, healthResponse, } from '../server/index.js';
|
|
4
5
|
export function createTanStackRpc(options = {}) {
|
|
5
6
|
return createRpc({ ...options, getRequest: options.getRequest ?? getRequest });
|
|
6
7
|
}
|
|
7
8
|
export function requireTanStackMutationOrigin(options = {}, request = getRequest()) {
|
|
8
9
|
return requireSameOrigin(request, options);
|
|
9
10
|
}
|
|
11
|
+
export function betterAuthHandlers(resolveAuth) {
|
|
12
|
+
const handle = ({ request }) => resolveAuth().handler(request);
|
|
13
|
+
return { GET: handle, POST: handle };
|
|
14
|
+
}
|
|
15
|
+
export function tanStackHealthHandler(check, options = {}) {
|
|
16
|
+
return () => healthResponse(check, options);
|
|
17
|
+
}
|
|
18
|
+
export function canonicalHostRequest(request, next, options) {
|
|
19
|
+
const redirect = canonicalRedirect(request.url, options);
|
|
20
|
+
return redirect ? Response.redirect(redirect, 301) : next();
|
|
21
|
+
}
|
|
22
|
+
export function canonicalHostMiddleware(resolveOptions) {
|
|
23
|
+
return createMiddleware({ type: 'request' }).server(({ request, next }) => {
|
|
24
|
+
return canonicalHostRequest(request, next, resolveOptions());
|
|
25
|
+
});
|
|
26
|
+
}
|
|
10
27
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/tanstack/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAsB,MAAM,kBAAkB,CAAA;AACxE,OAAO,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/tanstack/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAsB,MAAM,kBAAkB,CAAA;AACxE,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,cAAc,GAIf,MAAM,oBAAoB,CAAA;AAI3B,MAAM,UAAU,iB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,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { getRequest } from '@tanstack/react-start/server'\nimport { createMiddleware } from '@tanstack/react-start'\nimport { requireSameOrigin, type OriginOptions } from '../auth/index.js'\nimport {\n canonicalRedirect,\n createRpc,\n healthResponse,\n type CanonicalRedirectOptions,\n type HealthResponseOptions,\n type RpcOptions,\n} from '../server/index.js'\n\nexport type TanStackRpcOptions = Omit<RpcOptions, 'getRequest'> & Pick<RpcOptions, 'getRequest'>\n\nexport function createTanStackRpc(options: TanStackRpcOptions = {}) {\n return createRpc({ ...options, getRequest: options.getRequest ?? getRequest })\n}\n\nexport function requireTanStackMutationOrigin(options: OriginOptions = {}, request = getRequest()) {\n return requireSameOrigin(request, options)\n}\n\ntype RequestContext = { request: Request }\n\nexport function betterAuthHandlers(resolveAuth: () => { handler(request: Request): Response | Promise<Response> }) {\n const handle = ({ request }: RequestContext) => resolveAuth().handler(request)\n return { GET: handle, POST: handle }\n}\n\nexport function tanStackHealthHandler(check: () => void | Promise<void>, options: HealthResponseOptions = {}) {\n return () => healthResponse(check, options)\n}\n\nexport function canonicalHostRequest<T>(request: Request, next: () => T, options: CanonicalRedirectOptions): Response | T {\n const redirect = canonicalRedirect(request.url, options)\n return redirect ? Response.redirect(redirect, 301) : next()\n}\n\nexport function canonicalHostMiddleware(resolveOptions: () => CanonicalRedirectOptions) {\n return createMiddleware({ type: 'request' }).server(({ request, next }) => {\n return canonicalHostRequest(request, next, resolveOptions())\n })\n}\n"]}
|