ras-stack 3.1.1 → 3.2.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 +10 -10
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.js +1 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/origins.d.ts +2 -0
- package/dist/auth/origins.js +6 -0
- package/dist/auth/origins.js.map +1 -1
- package/dist/database/libsql.d.ts +14 -0
- package/dist/database/libsql.js +31 -0
- package/dist/database/libsql.js.map +1 -0
- package/dist/database/pragmas.d.ts +7 -0
- package/dist/database/pragmas.js +12 -0
- package/dist/database/pragmas.js.map +1 -0
- package/dist/database/sqlite.d.ts +2 -6
- package/dist/database/sqlite.js +2 -6
- package/dist/database/sqlite.js.map +1 -1
- package/dist/posthog/client.js +3 -2
- package/dist/posthog/client.js.map +1 -1
- package/dist/tanstack/client.d.ts +11 -0
- package/dist/tanstack/client.js +33 -0
- package/dist/tanstack/client.js.map +1 -0
- package/dist/tanstack/middleware.d.ts +5 -0
- package/dist/tanstack/middleware.js +18 -0
- package/dist/tanstack/middleware.js.map +1 -1
- package/package.json +15 -2
package/README.md
CHANGED
|
@@ -30,16 +30,16 @@ An application can use one surface without adopting the others. The npm package
|
|
|
30
30
|
|
|
31
31
|
## The stack 🧰
|
|
32
32
|
|
|
33
|
-
| Layer | Supported technology
|
|
34
|
-
| ------------------- |
|
|
35
|
-
| Runtime and tooling | Node, ESM TypeScript, pnpm, Just, Oxlint
|
|
36
|
-
| Web application | TanStack Start, React
|
|
37
|
-
| Authentication | Better Auth
|
|
38
|
-
| Data | Drizzle, `better-sqlite3`, Postgres.js
|
|
39
|
-
| Realtime | Centrifuge, Centrifugo, Caddy
|
|
40
|
-
| Email and uploads | Nodemailer 9/10, `tus-js-client`
|
|
41
|
-
| Observability | PostHog JS, React, Node, and OpenTelemetry
|
|
42
|
-
| Delivery | GitHub Actions, Changesets, Dokploy, Docker
|
|
33
|
+
| Layer | Supported technology | What `ras-stack` centralizes |
|
|
34
|
+
| ------------------- | ---------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
|
|
35
|
+
| Runtime and tooling | Node, ESM TypeScript, pnpm, Just, Oxlint | Setup actions and version synchronization |
|
|
36
|
+
| Web application | TanStack Start, React | Request binding, mutation-origin checks, canonical hosts, health handlers |
|
|
37
|
+
| Authentication | Better Auth | Secure option builders, origins, secrets, redirects, failure classification, and React action state |
|
|
38
|
+
| Data | Drizzle, `better-sqlite3`, libsql, Postgres.js | Connection lifecycle, safety defaults, migrations, target selection, and conformance checks |
|
|
39
|
+
| Realtime | Centrifuge, Centrifugo, Caddy | Publishing, tokens, browser/React lifecycle, presence, proxy configuration, binaries, and supervision |
|
|
40
|
+
| Email and uploads | Nodemailer 9/10, `tus-js-client` | SMTP configuration/delivery, auth callbacks, and promise-based resumable uploads |
|
|
41
|
+
| Observability | PostHog JS, React, Node, and OpenTelemetry | Analytics, replay, errors, logs, metrics, tracing, correlation, proxying, and shutdown |
|
|
42
|
+
| Delivery | GitHub Actions, Changesets, Dokploy, Docker | Checks, releases, preview lifecycle/status, production assets, and runtime binaries |
|
|
43
43
|
|
|
44
44
|
Applications still configure every upstream library directly. This table describes what is tested together, not a replacement API.
|
|
45
45
|
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { acceptedOrigins, forwardedOrigin, parseOrigin, requireSameOrigin, trustedOrigins, validSameOriginRequest } from './origins.js';
|
|
1
|
+
export { acceptedOrigins, forwardedOrigin, parseOrigin, publicOrigin, requireSameOrigin, trustedOrigins, validSameOriginRequest, } from './origins.js';
|
|
2
2
|
export type { OriginOptions } from './origins.js';
|
|
3
3
|
export { configuredProviderOptions, configuredProviders, providerCredentials } from './providers.js';
|
|
4
4
|
export type { ProviderCredentials, ProviderEnvironmentOptions } from './providers.js';
|
package/dist/auth/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { acceptedOrigins, forwardedOrigin, parseOrigin, requireSameOrigin, trustedOrigins, validSameOriginRequest } from './origins.js';
|
|
1
|
+
export { acceptedOrigins, forwardedOrigin, parseOrigin, publicOrigin, requireSameOrigin, trustedOrigins, validSameOriginRequest, } from './origins.js';
|
|
2
2
|
export { configuredProviderOptions, configuredProviders, providerCredentials } from './providers.js';
|
|
3
3
|
export { randomId, randomToken } from './random.js';
|
|
4
4
|
export { persistedSecret } from './secret.js';
|
package/dist/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,sBAAsB,GACvB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,yBAAyB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAEpG,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,EAAE,sBAAsB,EAAE,+BAA+B,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA","sourcesContent":["export {\n acceptedOrigins,\n forwardedOrigin,\n parseOrigin,\n publicOrigin,\n requireSameOrigin,\n trustedOrigins,\n validSameOriginRequest,\n} from './origins.js'\nexport type { OriginOptions } from './origins.js'\nexport { configuredProviderOptions, configuredProviders, providerCredentials } from './providers.js'\nexport type { ProviderCredentials, ProviderEnvironmentOptions } from './providers.js'\nexport { randomId, randomToken } from './random.js'\nexport { persistedSecret } from './secret.js'\nexport type { PersistedSecretOptions } from './secret.js'\nexport { standardAccountOptions, standardEmailAndPasswordOptions, standardRateLimitOptions, standardSessionOptions } from './settings.js'\nexport type { RateLimitRule, SessionOptions, StandardAccountOptions, StandardEmailAndPasswordOptions } from './settings.js'\n"]}
|
package/dist/auth/origins.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export type OriginOptions = {
|
|
|
6
6
|
export declare function parseOrigin(value: string | undefined): string | undefined;
|
|
7
7
|
export declare function forwardedOrigin(request: Request): string | undefined;
|
|
8
8
|
export declare function acceptedOrigins(request: Request, options?: OriginOptions): string[];
|
|
9
|
+
/** Where users reach the application, for absolute links: the first configured origin, then a trusted forwarded origin, then the request's. */
|
|
10
|
+
export declare function publicOrigin(request: Request, options?: OriginOptions): string;
|
|
9
11
|
export declare function validSameOriginRequest(request: Request, options?: OriginOptions): boolean;
|
|
10
12
|
export declare function requireSameOrigin(request: Request, options?: OriginOptions): void;
|
|
11
13
|
export declare function trustedOrigins(options?: OriginOptions): (request?: Request) => string[];
|
package/dist/auth/origins.js
CHANGED
|
@@ -20,6 +20,12 @@ export function acceptedOrigins(request, options = {}) {
|
|
|
20
20
|
...(options.configured ?? []).map(parseOrigin),
|
|
21
21
|
].filter((origin) => Boolean(origin));
|
|
22
22
|
}
|
|
23
|
+
/** Where users reach the application, for absolute links: the first configured origin, then a trusted forwarded origin, then the request's. */
|
|
24
|
+
export function publicOrigin(request, options = {}) {
|
|
25
|
+
return (options.configured?.map(parseOrigin).find(Boolean) ??
|
|
26
|
+
(options.trustForwardedHeaders ? forwardedOrigin(request) : undefined) ??
|
|
27
|
+
new URL(request.url).origin);
|
|
28
|
+
}
|
|
23
29
|
export function validSameOriginRequest(request, options = {}) {
|
|
24
30
|
const origin = request.headers.get('origin') || (options.allowReferer ? parseOrigin(request.headers.get('referer') ?? undefined) : undefined);
|
|
25
31
|
const site = request.headers.get('sec-fetch-site');
|
package/dist/auth/origins.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"origins.js","sourceRoot":"","sources":["../../src/auth/origins.ts"],"names":[],"mappings":"AAMA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?: boolean\n}\n\nexport function parseOrigin(value: string | undefined) {\n if (!value?.trim()) return undefined\n try {\n return new URL(value).origin\n } catch {\n return undefined\n }\n}\n\nexport function forwardedOrigin(request: Request) {\n const host = request.headers.get('x-forwarded-host')?.split(',')[0]?.trim() || request.headers.get('host')?.trim()\n const protocol = request.headers.get('x-forwarded-proto')?.split(',')[0]?.trim()\n return host && (protocol === 'http' || protocol === 'https') ? parseOrigin(`${protocol}://${host}`) : undefined\n}\n\nexport function acceptedOrigins(request: Request, options: OriginOptions = {}) {\n return [\n new URL(request.url).origin,\n ...(options.trustForwardedHeaders ? [forwardedOrigin(request)] : []),\n ...(options.configured ?? []).map(parseOrigin),\n ].filter((origin): origin is string => Boolean(origin))\n}\n\nexport function validSameOriginRequest(request: Request, options: OriginOptions = {}) {\n const origin =\n request.headers.get('origin') || (options.allowReferer ? parseOrigin(request.headers.get('referer') ?? undefined) : undefined)\n const site = request.headers.get('sec-fetch-site')\n return Boolean(origin && (!site || site === 'same-origin') && acceptedOrigins(request, options).includes(origin))\n}\n\nexport function requireSameOrigin(request: Request, options: OriginOptions = {}) {\n if (!validSameOriginRequest(request, options)) throw new Response('cross-origin mutation rejected', { status: 403 })\n}\n\nexport function trustedOrigins(options: OriginOptions = {}) {\n return (request?: Request) =>\n request ? acceptedOrigins(request, options).filter((origin) => origin !== new URL(request.url).origin) : []\n}\n"]}
|
|
1
|
+
{"version":3,"file":"origins.js","sourceRoot":"","sources":["../../src/auth/origins.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE;QAAE,OAAO,SAAS,CAAA;IACpC,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,MAAM,CAAA;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAA;IAClB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,OAAgB;IAC9C,M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["export type OriginOptions = {\n configured?: readonly (string | undefined)[]\n allowReferer?: boolean\n trustForwardedHeaders?: boolean\n}\n\nexport function parseOrigin(value: string | undefined) {\n if (!value?.trim()) return undefined\n try {\n return new URL(value).origin\n } catch {\n return undefined\n }\n}\n\nexport function forwardedOrigin(request: Request) {\n const host = request.headers.get('x-forwarded-host')?.split(',')[0]?.trim() || request.headers.get('host')?.trim()\n const protocol = request.headers.get('x-forwarded-proto')?.split(',')[0]?.trim()\n return host && (protocol === 'http' || protocol === 'https') ? parseOrigin(`${protocol}://${host}`) : undefined\n}\n\nexport function acceptedOrigins(request: Request, options: OriginOptions = {}) {\n return [\n new URL(request.url).origin,\n ...(options.trustForwardedHeaders ? [forwardedOrigin(request)] : []),\n ...(options.configured ?? []).map(parseOrigin),\n ].filter((origin): origin is string => Boolean(origin))\n}\n\n/** Where users reach the application, for absolute links: the first configured origin, then a trusted forwarded origin, then the request's. */\nexport function publicOrigin(request: Request, options: OriginOptions = {}) {\n return (\n options.configured?.map(parseOrigin).find(Boolean) ??\n (options.trustForwardedHeaders ? forwardedOrigin(request) : undefined) ??\n new URL(request.url).origin\n )\n}\n\nexport function validSameOriginRequest(request: Request, options: OriginOptions = {}) {\n const origin =\n request.headers.get('origin') || (options.allowReferer ? parseOrigin(request.headers.get('referer') ?? undefined) : undefined)\n const site = request.headers.get('sec-fetch-site')\n return Boolean(origin && (!site || site === 'same-origin') && acceptedOrigins(request, options).includes(origin))\n}\n\nexport function requireSameOrigin(request: Request, options: OriginOptions = {}) {\n if (!validSameOriginRequest(request, options)) throw new Response('cross-origin mutation rejected', { status: 403 })\n}\n\nexport function trustedOrigins(options: OriginOptions = {}) {\n return (request?: Request) =>\n request ? acceptedOrigins(request, options).filter((origin) => origin !== new URL(request.url).origin) : []\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Client, type Config } from '@libsql/client';
|
|
2
|
+
import { type LibSQLDatabase } from 'drizzle-orm/libsql';
|
|
3
|
+
import { type SqlitePragmas } from './pragmas.js';
|
|
4
|
+
export type LibsqlPragmas = Pick<SqlitePragmas, 'journalMode' | 'busyTimeout'>;
|
|
5
|
+
export type OpenDrizzleLibsqlOptions<TSchema extends Record<string, unknown>> = {
|
|
6
|
+
file: string;
|
|
7
|
+
schema: TSchema;
|
|
8
|
+
migrationsFolder?: string;
|
|
9
|
+
client?: Omit<Config, 'url'>;
|
|
10
|
+
pragmas?: LibsqlPragmas | false;
|
|
11
|
+
};
|
|
12
|
+
export declare function openDrizzleLibsql<TSchema extends Record<string, unknown>>(options: OpenDrizzleLibsqlOptions<TSchema>): Promise<LibSQLDatabase<TSchema> & {
|
|
13
|
+
$client: Client;
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createClient } from '@libsql/client';
|
|
2
|
+
import { drizzle } from 'drizzle-orm/libsql';
|
|
3
|
+
import { migrate } from 'drizzle-orm/libsql/migrator';
|
|
4
|
+
import { mkdirSync } from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
7
|
+
import { resolveSqlitePragmas } from './pragmas.js';
|
|
8
|
+
export async function openDrizzleLibsql(options) {
|
|
9
|
+
const memory = options.file === ':memory:';
|
|
10
|
+
const pragmas = options.pragmas === false ? undefined : resolveSqlitePragmas(options.pragmas);
|
|
11
|
+
if (!memory)
|
|
12
|
+
mkdirSync(path.dirname(path.resolve(options.file)), { recursive: true });
|
|
13
|
+
const client = createClient({
|
|
14
|
+
url: memory ? ':memory:' : pathToFileURL(path.resolve(options.file)).href,
|
|
15
|
+
...(pragmas ? { timeout: pragmas.busyTimeout } : {}),
|
|
16
|
+
...options.client,
|
|
17
|
+
});
|
|
18
|
+
try {
|
|
19
|
+
if (pragmas)
|
|
20
|
+
await client.execute(`pragma journal_mode = ${pragmas.journalMode}`);
|
|
21
|
+
const database = drizzle({ client, schema: options.schema });
|
|
22
|
+
if (options.migrationsFolder)
|
|
23
|
+
await migrate(database, { migrationsFolder: options.migrationsFolder });
|
|
24
|
+
return database;
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
client.close();
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=libsql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libsql.js","sourceRoot":"","sources":["../../src/database/libsql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA4B,MAAM,gBAAgB,CAAA;AACvE,OAAO,EAAE,OAAO,EAAuB,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,oBAAoB,EAAsB,MAAM,cAAc,CAAA;AAevE,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAA0C;IAE1C,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,KAAK,UAAU,CAAA;IAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC7F,IAAI,CAAC,MAAM;QAAE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACrF,MAAM,MAAM,GAAG,YAAY,CAAC;QAC1B,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;QACzE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpD,GAAG,OAAO,CAAC,MAAM;KAClB,CAAC,CAAA;IACF,IAAI,CAAC;QACH,IAAI,OAAO;YAAE,MAAM,MAAM,CAAC,OAAO,CAAC,yBAAyB,OAAO,CAAC,WAAW,EAAE,CAAC,CAAA;QACjF,MAAM,QAAQ,GAAG,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;QAC5D,IAAI,OAAO,CAAC,gBAAgB;YAAE,MAAM,OAAO,CAAC,QAAQ,EAAE,EAAE,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAA;QACrG,OAAO,QAAQ,CAAA;IACjB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,EAAE,CAAA;QACd,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC","sourcesContent":["import { createClient, type Client, type Config } from '@libsql/client'\nimport { drizzle, type LibSQLDatabase } from 'drizzle-orm/libsql'\nimport { migrate } from 'drizzle-orm/libsql/migrator'\nimport { mkdirSync } from 'node:fs'\nimport path from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { resolveSqlitePragmas, type SqlitePragmas } from './pragmas.js'\n\n// The client pools connections and opens each with libsql's defaults, so a per-connection pragma run through `execute`\n// reaches only one of them. Those defaults are already synchronous FULL and foreign keys on; the busy timeout goes\n// through `timeout`, which every connection receives, and WAL persists in the file once set.\nexport type LibsqlPragmas = Pick<SqlitePragmas, 'journalMode' | 'busyTimeout'>\n\nexport type OpenDrizzleLibsqlOptions<TSchema extends Record<string, unknown>> = {\n file: string\n schema: TSchema\n migrationsFolder?: string\n client?: Omit<Config, 'url'>\n pragmas?: LibsqlPragmas | false\n}\n\nexport async function openDrizzleLibsql<TSchema extends Record<string, unknown>>(\n options: OpenDrizzleLibsqlOptions<TSchema>,\n): Promise<LibSQLDatabase<TSchema> & { $client: Client }> {\n const memory = options.file === ':memory:'\n const pragmas = options.pragmas === false ? undefined : resolveSqlitePragmas(options.pragmas)\n if (!memory) mkdirSync(path.dirname(path.resolve(options.file)), { recursive: true })\n const client = createClient({\n url: memory ? ':memory:' : pathToFileURL(path.resolve(options.file)).href,\n ...(pragmas ? { timeout: pragmas.busyTimeout } : {}),\n ...options.client,\n })\n try {\n if (pragmas) await client.execute(`pragma journal_mode = ${pragmas.journalMode}`)\n const database = drizzle({ client, schema: options.schema })\n if (options.migrationsFolder) await migrate(database, { migrationsFolder: options.migrationsFolder })\n return database\n } catch (error) {\n client.close()\n throw error\n }\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type SqlitePragmas = {
|
|
2
|
+
journalMode?: 'DELETE' | 'TRUNCATE' | 'PERSIST' | 'MEMORY' | 'WAL' | 'OFF';
|
|
3
|
+
synchronous?: 'OFF' | 'NORMAL' | 'FULL' | 'EXTRA';
|
|
4
|
+
busyTimeout?: number;
|
|
5
|
+
foreignKeys?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function resolveSqlitePragmas(pragmas?: SqlitePragmas): Required<SqlitePragmas>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export function resolveSqlitePragmas(pragmas = {}) {
|
|
2
|
+
const busyTimeout = pragmas.busyTimeout ?? 5000;
|
|
3
|
+
if (!Number.isInteger(busyTimeout) || busyTimeout < 0)
|
|
4
|
+
throw new Error('busyTimeout must be a non-negative integer');
|
|
5
|
+
return {
|
|
6
|
+
journalMode: pragmas.journalMode ?? 'WAL',
|
|
7
|
+
synchronous: pragmas.synchronous ?? 'FULL',
|
|
8
|
+
busyTimeout,
|
|
9
|
+
foreignKeys: pragmas.foreignKeys ?? true,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=pragmas.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pragmas.js","sourceRoot":"","sources":["../../src/database/pragmas.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,oBAAoB,CAAC,OAAO,GAAkB,EAAE;IAC9D,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAA;IAC/C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,IAAI,WAAW,GAAG,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;IACpH,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,KAAK;QACzC,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,MAAM;QAC1C,WAAW;QACX,WAAW,EAAE,OAAO,CAAC,WAAW,IAAI,IAAI;KACzC,CAAA;AACH,CAAC","sourcesContent":["export type SqlitePragmas = {\n journalMode?: 'DELETE' | 'TRUNCATE' | 'PERSIST' | 'MEMORY' | 'WAL' | 'OFF'\n synchronous?: 'OFF' | 'NORMAL' | 'FULL' | 'EXTRA'\n busyTimeout?: number\n foreignKeys?: boolean\n}\n\nexport function resolveSqlitePragmas(pragmas: SqlitePragmas = {}): Required<SqlitePragmas> {\n const busyTimeout = pragmas.busyTimeout ?? 5000\n if (!Number.isInteger(busyTimeout) || busyTimeout < 0) throw new Error('busyTimeout must be a non-negative integer')\n return {\n journalMode: pragmas.journalMode ?? 'WAL',\n synchronous: pragmas.synchronous ?? 'FULL',\n busyTimeout,\n foreignKeys: pragmas.foreignKeys ?? true,\n }\n}\n"]}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import Database from 'better-sqlite3';
|
|
2
2
|
import { type BetterSQLite3Database } from 'drizzle-orm/better-sqlite3';
|
|
3
3
|
import { type RateLimitStore } from '../server/rate-limit.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
synchronous?: 'OFF' | 'NORMAL' | 'FULL' | 'EXTRA';
|
|
7
|
-
busyTimeout?: number;
|
|
8
|
-
foreignKeys?: boolean;
|
|
9
|
-
};
|
|
4
|
+
import { type SqlitePragmas } from './pragmas.js';
|
|
5
|
+
export type { SqlitePragmas } from './pragmas.js';
|
|
10
6
|
export type OpenSqliteOptions = {
|
|
11
7
|
database?: Database.Options;
|
|
12
8
|
pragmas?: SqlitePragmas | false;
|
package/dist/database/sqlite.js
CHANGED
|
@@ -4,6 +4,7 @@ import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
|
|
|
4
4
|
import { mkdirSync } from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { rateLimitTable } from '../server/rate-limit.js';
|
|
7
|
+
import { resolveSqlitePragmas } from './pragmas.js';
|
|
7
8
|
export function openSqliteClient(file, options = {}) {
|
|
8
9
|
if (file !== ':memory:')
|
|
9
10
|
mkdirSync(path.dirname(path.resolve(file)), { recursive: true });
|
|
@@ -19,12 +20,7 @@ export function openSqliteClient(file, options = {}) {
|
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
export function configureSqlite(client, pragmas = {}) {
|
|
22
|
-
const journalMode = pragmas
|
|
23
|
-
const synchronous = pragmas.synchronous ?? 'FULL';
|
|
24
|
-
const busyTimeout = pragmas.busyTimeout ?? 5000;
|
|
25
|
-
const foreignKeys = pragmas.foreignKeys ?? true;
|
|
26
|
-
if (!Number.isInteger(busyTimeout) || busyTimeout < 0)
|
|
27
|
-
throw new Error('busyTimeout must be a non-negative integer');
|
|
23
|
+
const { journalMode, synchronous, busyTimeout, foreignKeys } = resolveSqlitePragmas(pragmas);
|
|
28
24
|
client.pragma(`journal_mode = ${journalMode}`);
|
|
29
25
|
client.pragma(`synchronous = ${synchronous}`);
|
|
30
26
|
client.pragma(`busy_timeout = ${busyTimeout}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/database/sqlite.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAA;AACrC,OAAO,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C,CAAA;IAClC,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAgF;kBAChG,IAAI;;0BAEI,IAAI,8BAA8B,IAAI;6BACnC,IAAI,8BAA8B,IAAI;;GAEhE,CAAC,CAAA;IACF,OAAO;QACL,SAAS,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG;YAC/B,MAAM,OAAO,GAAG,GAAG,GAAG,aAAa,CAAA;YACnC,MAAM,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,CAAA;YAC1D,IAAI,CAAC,GAAG;gBAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;YACjE,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAA;QACpD,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["import Database from 'better-sqlite3'\nimport { drizzle, type BetterSQLite3Database } from 'drizzle-orm/better-sqlite3'\nimport { migrate } from 'drizzle-orm/better-sqlite3/migrator'\nimport { mkdirSync } from 'node:fs'\nimport path from 'node:path'\nimport { rateLimitTable, type RateLimitStore } from '../server/rate-limit.js'\nimport { resolveSqlitePragmas, type SqlitePragmas } from './pragmas.js'\n\nexport type { SqlitePragmas } from './pragmas.js'\n\nexport type OpenSqliteOptions = {\n database?: Database.Options\n pragmas?: SqlitePragmas | false\n}\n\nexport function openSqliteClient(file: string, options: OpenSqliteOptions = {}): Database.Database {\n if (file !== ':memory:') mkdirSync(path.dirname(path.resolve(file)), { recursive: true })\n const client = new Database(file, options.database)\n try {\n if (options.pragmas !== false) configureSqlite(client, options.pragmas)\n return client\n } catch (error) {\n client.close()\n throw error\n }\n}\n\nexport function configureSqlite(client: Database.Database, pragmas: SqlitePragmas = {}): Database.Database {\n const { journalMode, synchronous, busyTimeout, foreignKeys } = resolveSqlitePragmas(pragmas)\n client.pragma(`journal_mode = ${journalMode}`)\n client.pragma(`synchronous = ${synchronous}`)\n client.pragma(`busy_timeout = ${busyTimeout}`)\n client.pragma(`foreign_keys = ${foreignKeys ? 'ON' : 'OFF'}`)\n return client\n}\n\nexport type OpenDrizzleSqliteOptions<TSchema extends Record<string, unknown>> = OpenSqliteOptions & {\n file: string\n schema: TSchema\n migrationsFolder?: string\n}\n\nexport function openDrizzleSqlite<TSchema extends Record<string, unknown>>(\n options: OpenDrizzleSqliteOptions<TSchema>,\n): BetterSQLite3Database<TSchema> & { $client: Database.Database } {\n const client = openSqliteClient(options.file, options)\n try {\n const database = drizzle({ client, schema: options.schema })\n if (options.migrationsFolder) migrate(database, { migrationsFolder: options.migrationsFolder })\n return database\n } catch (error) {\n client.close()\n throw error\n }\n}\n\nexport function closeDrizzleSqlite(database: { $client: Database.Database }) {\n database.$client.close()\n}\n\n// One statement so concurrent requests cannot both read a stale count and write the same increment.\nexport function sqliteRateLimitStore(client: Database.Database, table = 'rate_limit'): RateLimitStore {\n const name = rateLimitTable(table)\n const statement = client.prepare<[string, number, number, number, number], { count: number; reset_at: number }>(`\n insert into ${name} (key, count, reset_at) values (?, 1, ?)\n on conflict(key) do update set\n count = case when ${name}.reset_at <= ? then 1 else ${name}.count + 1 end,\n reset_at = case when ${name}.reset_at <= ? then ? else ${name}.reset_at end\n returning count, reset_at\n `)\n return {\n increment(key, windowSeconds, now) {\n const resetAt = now + windowSeconds\n const row = statement.get(key, resetAt, now, now, resetAt)\n if (!row) throw new Error('rate limit increment returned no row')\n return { count: row.count, resetAt: row.reset_at }\n },\n }\n}\n"]}
|
package/dist/posthog/client.js
CHANGED
|
@@ -2,6 +2,7 @@ import { POSTHOG_DISTINCT_ID_HEADER, POSTHOG_SESSION_ID_HEADER, postHogIdentifie
|
|
|
2
2
|
export { POSTHOG_DISTINCT_ID_HEADER, POSTHOG_SESSION_ID_HEADER } from './request.js';
|
|
3
3
|
export const POSTHOG_BROWSER_DEFAULTS = '2026-05-30';
|
|
4
4
|
export function postHogBrowserOptions(input) {
|
|
5
|
+
const { session_recording: sessionRecording, ...options } = input.options ?? {};
|
|
5
6
|
const service = input.service
|
|
6
7
|
? {
|
|
7
8
|
serviceName: required(input.service.name, 'service.name'),
|
|
@@ -20,10 +21,10 @@ export function postHogBrowserOptions(input) {
|
|
|
20
21
|
custom_personal_data_properties: ['token'],
|
|
21
22
|
mask_personal_data_properties: true,
|
|
22
23
|
person_profiles: 'identified_only',
|
|
23
|
-
session_recording: { maskAllInputs: true, blockSelector: '.ph-no-capture' },
|
|
24
|
+
session_recording: { maskAllInputs: true, blockSelector: '.ph-no-capture', ...sessionRecording },
|
|
24
25
|
...(service ? { logs: service, metrics: service } : {}),
|
|
25
26
|
...(input.tracingHostnames ? { tracing_headers: input.tracingHostnames } : {}),
|
|
26
|
-
...
|
|
27
|
+
...options,
|
|
27
28
|
};
|
|
28
29
|
}
|
|
29
30
|
export function postHogBrowserHeaders(client) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/posthog/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEvG,OAAO,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACpF,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAA;AAEpD,MAAM,UAAU,qBAAqB,CAAC,KAMrC;IACC,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO;QAC3B,CAAC,CAAC;YACE,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,cAAc,CAAC;YACzD,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3E,GAAG,CAAC,KAAK,CAAC,O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AE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9E,GAAG,OAAO;KACX,CAAA;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,MAA2E;IAC/G,MAAM,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC,CAAA;IAC9D,MAAM,SAAS,GAAG,iBAAiB,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,CAAA;IAC5D,OAAO;QACL,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,0BAA0B,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnE,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,yBAAyB,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjE,CAAA;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,KAAa,EAAE,IAAY;IAC3C,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;IAC/B,IAAI,CAAC,UAAU;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,cAAc,CAAC,CAAA;IACvD,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import type { PostHogConfig } from 'posthog-js'\nimport type { PostHogBrowserService } from './config.js'\nimport { POSTHOG_DISTINCT_ID_HEADER, POSTHOG_SESSION_ID_HEADER, postHogIdentifier } from './request.js'\n\nexport { POSTHOG_DISTINCT_ID_HEADER, POSTHOG_SESSION_ID_HEADER } from './request.js'\nexport const POSTHOG_BROWSER_DEFAULTS = '2026-05-30'\n\nexport function postHogBrowserOptions(input: {\n apiHost: string\n uiHost: string\n tracingHostnames?: string[]\n service?: PostHogBrowserService\n options?: Partial<PostHogConfig>\n}): Partial<PostHogConfig> {\n const { session_recording: sessionRecording, ...options } = input.options ?? {}\n const service = input.service\n ? {\n serviceName: required(input.service.name, 'service.name'),\n ...(input.service.version ? { serviceVersion: input.service.version } : {}),\n ...(input.service.environment ? { environment: input.service.environment } : {}),\n ...(input.service.resourceAttributes ? { resourceAttributes: input.service.resourceAttributes } : {}),\n }\n : undefined\n return {\n api_host: required(input.apiHost, 'apiHost'),\n ui_host: required(input.uiHost, 'uiHost'),\n defaults: POSTHOG_BROWSER_DEFAULTS,\n capture_exceptions: true,\n capture_pageview: 'history_change',\n capture_performance: true,\n custom_personal_data_properties: ['token'],\n mask_personal_data_properties: true,\n person_profiles: 'identified_only',\n session_recording: { maskAllInputs: true, blockSelector: '.ph-no-capture', ...sessionRecording },\n ...(service ? { logs: service, metrics: service } : {}),\n ...(input.tracingHostnames ? { tracing_headers: input.tracingHostnames } : {}),\n ...options,\n }\n}\n\nexport function postHogBrowserHeaders(client: { get_distinct_id(): string; get_session_id(): string | undefined }): Record<string, string> {\n const distinctId = postHogIdentifier(client.get_distinct_id())\n const sessionId = postHogIdentifier(client.get_session_id())\n return {\n ...(distinctId ? { [POSTHOG_DISTINCT_ID_HEADER]: distinctId } : {}),\n ...(sessionId ? { [POSTHOG_SESSION_ID_HEADER]: sessionId } : {}),\n }\n}\n\nfunction required(value: string, name: string) {\n const normalized = value.trim()\n if (!normalized) throw new Error(`${name} is required`)\n return normalized\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type ChunkRecoveryOptions = {
|
|
2
|
+
storageKey: string;
|
|
3
|
+
noticeId?: string;
|
|
4
|
+
retryWindowMs?: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* An inline script that reloads the page, at most once per retry window, when an entry module fails to load after a
|
|
8
|
+
* deploy replaced the build. Without it the server-rendered HTML stays inert. TanStack Router already reloads for lazy
|
|
9
|
+
* route chunks; this covers the entry graph it cannot reach. Optionally reveals a hidden element once reloading stops.
|
|
10
|
+
*/
|
|
11
|
+
export declare function chunkRecoveryScript(options: ChunkRecoveryOptions): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Serialized into an inline <head> script, so it must stay self-contained: no imports, helpers, or closures.
|
|
2
|
+
function installChunkRecovery(win, { storageKey, noticeId, retryWindowMs = 10_000 }) {
|
|
3
|
+
win.addEventListener('error', (event) => {
|
|
4
|
+
const script = event.target;
|
|
5
|
+
if (script?.tagName !== 'SCRIPT' || script.type !== 'module' || !script.src)
|
|
6
|
+
return;
|
|
7
|
+
// Module scripts from elsewhere, such as browser extensions, are not part of the application's build.
|
|
8
|
+
if (new URL(script.src).origin !== win.location.origin)
|
|
9
|
+
return;
|
|
10
|
+
try {
|
|
11
|
+
if (Date.now() - Number(win.sessionStorage.getItem(storageKey)) >= retryWindowMs) {
|
|
12
|
+
win.sessionStorage.setItem(storageKey, String(Date.now()));
|
|
13
|
+
win.location.reload();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// Without sessionStorage a reload cannot be bounded, so fall through to the notice.
|
|
19
|
+
}
|
|
20
|
+
const notice = noticeId ? win.document.getElementById(noticeId) : null;
|
|
21
|
+
if (notice)
|
|
22
|
+
notice.hidden = false;
|
|
23
|
+
}, true);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* An inline script that reloads the page, at most once per retry window, when an entry module fails to load after a
|
|
27
|
+
* deploy replaced the build. Without it the server-rendered HTML stays inert. TanStack Router already reloads for lazy
|
|
28
|
+
* route chunks; this covers the entry graph it cannot reach. Optionally reveals a hidden element once reloading stops.
|
|
29
|
+
*/
|
|
30
|
+
export function chunkRecoveryScript(options) {
|
|
31
|
+
return `(${installChunkRecovery.toString()})(window, ${JSON.stringify(options)})`;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/tanstack/client.ts"],"names":[],"mappings":"AAMA,6GAA6G;AAC7G,SAAS,oBAAoB,CAAC,GAAW,EAAE,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,GAAG,MAAM,EA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n\n// Serialized into an inline <head> script, so it must stay self-contained: no imports, helpers, or closures.\nfunction installChunkRecovery(win: Window, { storageKey, noticeId, retryWindowMs = 10_000 }: ChunkRecoveryOptions) {\n win.addEventListener(\n 'error',\n (event) => {\n const script = event.target as HTMLScriptElement | null\n if (script?.tagName !== 'SCRIPT' || script.type !== 'module' || !script.src) return\n // Module scripts from elsewhere, such as browser extensions, are not part of the application's build.\n if (new URL(script.src).origin !== win.location.origin) return\n try {\n if (Date.now() - Number(win.sessionStorage.getItem(storageKey)) >= retryWindowMs) {\n win.sessionStorage.setItem(storageKey, String(Date.now()))\n win.location.reload()\n return\n }\n } catch {\n // Without sessionStorage a reload cannot be bounded, so fall through to the notice.\n }\n const notice = noticeId ? win.document.getElementById(noticeId) : null\n if (notice) notice.hidden = false\n },\n true,\n )\n}\n\n/**\n * An inline script that reloads the page, at most once per retry window, when an entry module fails to load after a\n * deploy replaced the build. Without it the server-rendered HTML stays inert. TanStack Router already reloads for lazy\n * route chunks; this covers the entry graph it cannot reach. Optionally reveals a hidden element once reloading stops.\n */\nexport function chunkRecoveryScript(options: ChunkRecoveryOptions) {\n return `(${installChunkRecovery.toString()})(window, ${JSON.stringify(options)})`\n}\n"]}
|
|
@@ -3,3 +3,8 @@ export declare function canonicalHostRequest<T>(request: Request, next: () => T,
|
|
|
3
3
|
export declare function canonicalHostMiddleware(resolveOptions: () => CanonicalRedirectOptions): import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
4
4
|
/** Names each server function for telemetry recorded while it runs, such as the RPC observer's span and metrics. */
|
|
5
5
|
export declare function serverFunctionIdentityMiddleware(): import("@tanstack/react-start").FunctionMiddlewareAfterServer<{}, unknown, undefined, undefined, undefined, undefined, undefined>;
|
|
6
|
+
/**
|
|
7
|
+
* A tab opened before a deploy can call a server function the deploy removed. TanStack answers with a JSON 500 that
|
|
8
|
+
* its client returns as a successful result, so this replaces it with a plain-text 404 the client throws with `message`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function staleServerFunctionMiddleware(message: string): import("@tanstack/react-start").RequestMiddlewareAfterServer<{}, undefined, undefined>;
|
|
@@ -14,4 +14,22 @@ export function canonicalHostMiddleware(resolveOptions) {
|
|
|
14
14
|
export function serverFunctionIdentityMiddleware() {
|
|
15
15
|
return createMiddleware({ type: 'function' }).server(({ serverFnMeta, next }) => withServerFunction({ name: serverFnMeta.name, filename: serverFnMeta.filename }, next));
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* A tab opened before a deploy can call a server function the deploy removed. TanStack answers with a JSON 500 that
|
|
19
|
+
* its client returns as a successful result, so this replaces it with a plain-text 404 the client throws with `message`.
|
|
20
|
+
*/
|
|
21
|
+
export function staleServerFunctionMiddleware(message) {
|
|
22
|
+
return createMiddleware({ type: 'request' }).server(async ({ handlerType, next }) => {
|
|
23
|
+
if (handlerType !== 'serverFn')
|
|
24
|
+
return next();
|
|
25
|
+
try {
|
|
26
|
+
return await next();
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (!(error instanceof Error && error.message.startsWith('Server function info not found for ')))
|
|
30
|
+
throw error;
|
|
31
|
+
return new Response(message, { status: 404, headers: { 'content-type': 'text/plain; charset=utf-8' } });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
17
35
|
//# sourceMappingURL=middleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/tanstack/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAiC,MAAM,6BAA6B,CAAA;AAC9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AAEjE,MAAM,UAAU,oBAAoB,CAAI,OAAgB,EAAE,IAAa,EAAE,OAAiC;IACxG,MAAM,QAAQ,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACxD,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;AAC7D,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,cAA8C;IACpF,OAAO,gBAAgB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;QACxE,OAAO,oBAAoB,CAAC,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAA;IAC9D,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,oHAAoH;AACpH,MAAM,UAAU,gCAAgC;IAC9C,OAAO,gBAAgB,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,CAC9E,kBAAkB,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,CACvF,CAAA;AACH,CAAC","sourcesContent":["import { createMiddleware } from '@tanstack/react-start'\nimport { canonicalRedirect, type CanonicalRedirectOptions } from '../server/canonical-host.js'\nimport { withServerFunction } from '../server/server-function.js'\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\n/** Names each server function for telemetry recorded while it runs, such as the RPC observer's span and metrics. */\nexport function serverFunctionIdentityMiddleware() {\n return createMiddleware({ type: 'function' }).server(({ serverFnMeta, next }) =>\n withServerFunction({ name: serverFnMeta.name, filename: serverFnMeta.filename }, next),\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../src/tanstack/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAiC,MAAM,6BAA6B,CAAA;AAC9F,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AAEjE,MAAM,UAAU,oBAAoB,CAAI,OAAgB,EAAE,IAAa,EAAE,OAAiC;IACxG,MAAM,QAAQ,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACxD,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;AAC7D,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,cAA8C;IACpF,OAAO,gBAAgB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE;QACxE,OAAO,oBAAoB,CAAC,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAA;IAC9D,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,oHAAoH;AACpH,MAAM,UAAU,gCAAgC;IAC9C,OAAO,gBAAgB,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,CAC9E,kBAAkB,CAAC,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,CACvF,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAAC,OAAe;IAC3D,OAAO,gBAAgB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,EAAE;QAClF,IAAI,WAAW,KAAK,UAAU;YAAE,OAAO,IAAI,EAAE,CAAA;QAC7C,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,EAAE,CAAA;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,qCAAqC,CAAC,CAAC;gBAAE,MAAM,KAAK,CAAA;YAC7G,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,2BAA2B,EAAE,EAAE,CAAC,CAAA;QACzG,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { createMiddleware } from '@tanstack/react-start'\nimport { canonicalRedirect, type CanonicalRedirectOptions } from '../server/canonical-host.js'\nimport { withServerFunction } from '../server/server-function.js'\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\n/** Names each server function for telemetry recorded while it runs, such as the RPC observer's span and metrics. */\nexport function serverFunctionIdentityMiddleware() {\n return createMiddleware({ type: 'function' }).server(({ serverFnMeta, next }) =>\n withServerFunction({ name: serverFnMeta.name, filename: serverFnMeta.filename }, next),\n )\n}\n\n/**\n * A tab opened before a deploy can call a server function the deploy removed. TanStack answers with a JSON 500 that\n * its client returns as a successful result, so this replaces it with a plain-text 404 the client throws with `message`.\n */\nexport function staleServerFunctionMiddleware(message: string) {\n return createMiddleware({ type: 'request' }).server(async ({ handlerType, next }) => {\n if (handlerType !== 'serverFn') return next()\n try {\n return await next()\n } catch (error) {\n if (!(error instanceof Error && error.message.startsWith('Server function info not found for '))) throw error\n return new Response(message, { status: 404, headers: { 'content-type': 'text/plain; charset=utf-8' } })\n }\n })\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ras-stack",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Composable full-stack primitives shared across Richard Solomou's applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authentication",
|
|
@@ -54,6 +54,10 @@
|
|
|
54
54
|
"types": "./dist/database/sqlite.d.ts",
|
|
55
55
|
"default": "./dist/database/sqlite.js"
|
|
56
56
|
},
|
|
57
|
+
"./database/libsql": {
|
|
58
|
+
"types": "./dist/database/libsql.d.ts",
|
|
59
|
+
"default": "./dist/database/libsql.js"
|
|
60
|
+
},
|
|
57
61
|
"./database/postgres": {
|
|
58
62
|
"types": "./dist/database/postgres.d.ts",
|
|
59
63
|
"default": "./dist/database/postgres.js"
|
|
@@ -110,6 +114,10 @@
|
|
|
110
114
|
"types": "./dist/runtime/index.d.ts",
|
|
111
115
|
"default": "./dist/runtime/index.js"
|
|
112
116
|
},
|
|
117
|
+
"./tanstack/client": {
|
|
118
|
+
"types": "./dist/tanstack/client.d.ts",
|
|
119
|
+
"default": "./dist/tanstack/client.js"
|
|
120
|
+
},
|
|
113
121
|
"./tanstack/middleware": {
|
|
114
122
|
"types": "./dist/tanstack/middleware.d.ts",
|
|
115
123
|
"default": "./dist/tanstack/middleware.js"
|
|
@@ -135,6 +143,7 @@
|
|
|
135
143
|
"@manypkg/get-packages": "3.1.0"
|
|
136
144
|
},
|
|
137
145
|
"devDependencies": {
|
|
146
|
+
"@libsql/client": "0.18.0",
|
|
138
147
|
"@opentelemetry/api-logs": "^0.223.0",
|
|
139
148
|
"@opentelemetry/exporter-logs-otlp-http": "^0.223.0",
|
|
140
149
|
"@opentelemetry/resources": "^2.12.0",
|
|
@@ -164,9 +173,10 @@
|
|
|
164
173
|
"vite": "8.2.1",
|
|
165
174
|
"vitest": "^4.1.10",
|
|
166
175
|
"yaml": "^2.8.2",
|
|
167
|
-
"ras-stack-config": "
|
|
176
|
+
"ras-stack-config": "2.0.0"
|
|
168
177
|
},
|
|
169
178
|
"peerDependencies": {
|
|
179
|
+
"@libsql/client": ">=0.18 <1",
|
|
170
180
|
"@opentelemetry/api-logs": ">=0.221.0 <0.224.0",
|
|
171
181
|
"@opentelemetry/exporter-logs-otlp-http": ">=0.221.0 <0.224.0",
|
|
172
182
|
"@opentelemetry/resources": "^2.10.0",
|
|
@@ -184,6 +194,9 @@
|
|
|
184
194
|
"tus-js-client": ">=4 <5"
|
|
185
195
|
},
|
|
186
196
|
"peerDependenciesMeta": {
|
|
197
|
+
"@libsql/client": {
|
|
198
|
+
"optional": true
|
|
199
|
+
},
|
|
187
200
|
"@opentelemetry/api-logs": {
|
|
188
201
|
"optional": true
|
|
189
202
|
},
|