ras-stack 4.2.0 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/auth/secret.js +5 -6
- package/dist/auth/secret.js.map +1 -1
- package/dist/build/index.js +1 -3
- package/dist/build/index.js.map +1 -1
- package/dist/changesets/index.js +2 -1
- package/dist/changesets/index.js.map +1 -1
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +9 -3
- package/dist/cli.js.map +1 -1
- package/dist/conformance/index.d.ts +3 -11
- package/dist/conformance/index.js +11 -6
- package/dist/conformance/index.js.map +1 -1
- package/dist/email/index.d.ts +2 -2
- package/dist/email/index.js +3 -6
- package/dist/email/index.js.map +1 -1
- package/dist/posthog/react.js +36 -18
- package/dist/posthog/react.js.map +1 -1
- package/dist/posthog/server.js +13 -28
- package/dist/posthog/server.js.map +1 -1
- package/dist/preview/cloudflare.js +2 -4
- package/dist/preview/cloudflare.js.map +1 -1
- package/dist/preview/dokploy-cli.js +14 -28
- package/dist/preview/dokploy-cli.js.map +1 -1
- package/dist/preview/dokploy-preview.d.ts +3 -0
- package/dist/preview/dokploy-preview.js +15 -21
- package/dist/preview/dokploy-preview.js.map +1 -1
- package/dist/preview/environment.d.ts +6 -14
- package/dist/preview/environment.js +12 -19
- package/dist/preview/environment.js.map +1 -1
- package/dist/preview/github.d.ts +12 -5
- package/dist/preview/github.js +22 -22
- package/dist/preview/github.js.map +1 -1
- package/dist/realtime/environment.js +2 -1
- package/dist/realtime/environment.js.map +1 -1
- package/dist/realtime/publisher.d.ts +1 -0
- package/dist/realtime/publisher.js +7 -5
- package/dist/realtime/publisher.js.map +1 -1
- package/dist/runtime/dev.d.ts +2 -2
- package/dist/runtime/dev.js +47 -71
- package/dist/runtime/dev.js.map +1 -1
- package/dist/runtime/stack.d.ts +2 -1
- package/dist/runtime/stack.js +14 -40
- package/dist/runtime/stack.js.map +1 -1
- package/dist/server/canonical-host.d.ts +1 -0
- package/dist/server/canonical-host.js +1 -1
- package/dist/server/canonical-host.js.map +1 -1
- package/dist/spacetime/index.js +2 -1
- package/dist/spacetime/index.js.map +1 -1
- package/dist/tanstack/server.d.ts +1 -1
- package/dist/tanstack/server.js.map +1 -1
- package/package.json +1 -1
- package/dist/posthog/client.d.ts +0 -9
- package/dist/posthog/client.js +0 -34
- package/dist/posthog/client.js.map +0 -1
- package/dist/runtime/dev-cli.d.ts +0 -1
- package/dist/runtime/dev-cli.js +0 -11
- package/dist/runtime/dev-cli.js.map +0 -1
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ An application can use one surface without adopting the others. The npm package
|
|
|
33
33
|
| Layer | Supported technology | What `ras-stack` centralizes |
|
|
34
34
|
| ------------------- | ---------------------------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
35
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
|
|
36
|
+
| Web application | TanStack Start, React | Request binding, mutation-origin checks, canonical hosts, health handlers, and conformance checks |
|
|
37
37
|
| Authentication | Better Auth | Secure option builders, origins, secrets, redirects, failure classification, and React action state |
|
|
38
38
|
| Data | Drizzle, `better-sqlite3`, libsql, Postgres.js | Connection lifecycle, safety defaults, migrations, target selection, and conformance checks |
|
|
39
39
|
| Realtime | Centrifuge, Centrifugo, Caddy | Publishing, tokens, browser/React lifecycle, proxy configuration, binaries, and supervision |
|
package/dist/auth/secret.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import crypto from 'node:crypto';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
+
import { errorHasCode } from '../server/errors.js';
|
|
5
|
+
import { randomToken } from './random.js';
|
|
4
6
|
export function persistedSecret(options) {
|
|
5
7
|
const environment = options.environment ?? process.env;
|
|
6
8
|
const configured = environment[options.environmentKey ?? 'AUTH_SECRET']?.trim();
|
|
@@ -11,11 +13,11 @@ export function persistedSecret(options) {
|
|
|
11
13
|
return readSecret(file);
|
|
12
14
|
}
|
|
13
15
|
catch (error) {
|
|
14
|
-
if (!
|
|
16
|
+
if (!errorHasCode(error, 'ENOENT'))
|
|
15
17
|
throw error;
|
|
16
18
|
}
|
|
17
19
|
fs.mkdirSync(options.directory, { recursive: true });
|
|
18
|
-
const secret =
|
|
20
|
+
const secret = randomToken(options.bytes ?? 32);
|
|
19
21
|
const temporary = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
20
22
|
try {
|
|
21
23
|
fs.writeFileSync(temporary, secret, { mode: 0o600, flag: 'wx' });
|
|
@@ -24,7 +26,7 @@ export function persistedSecret(options) {
|
|
|
24
26
|
return secret;
|
|
25
27
|
}
|
|
26
28
|
catch (error) {
|
|
27
|
-
if (!
|
|
29
|
+
if (!errorHasCode(error, 'EEXIST'))
|
|
28
30
|
throw error;
|
|
29
31
|
return readSecret(file);
|
|
30
32
|
}
|
|
@@ -39,7 +41,4 @@ function readSecret(file) {
|
|
|
39
41
|
throw new Error(`Secret file is empty: ${file}`);
|
|
40
42
|
return secret;
|
|
41
43
|
}
|
|
42
|
-
function isErrnoException(error) {
|
|
43
|
-
return error instanceof Error && 'code' in error;
|
|
44
|
-
}
|
|
45
44
|
//# sourceMappingURL=secret.js.map
|
package/dist/auth/secret.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secret.js","sourceRoot":"","sources":["../../src/auth/secret.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"secret.js","sourceRoot":"","sources":["../../src/auth/secret.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,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AAE,CAAC;YACf,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC;gBAAE,MAAM,KAAK,CAAA;YAC/C,OAAO,UAAU,CAAC,IAAI,CAAC,CAAA;QACzB,CAAC;IACH,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IACvC,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CAAA;IACnD,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAA;IAC7D,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import crypto from 'node:crypto'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { errorHasCode } from '../server/errors.js'\nimport { randomToken } from './random.js'\n\nexport type PersistedSecretOptions = {\n directory: string\n environment?: NodeJS.ProcessEnv\n environmentKey?: string\n filename?: string\n bytes?: number\n}\n\nexport function persistedSecret(options: PersistedSecretOptions) {\n const environment = options.environment ?? process.env\n const configured = environment[options.environmentKey ?? 'AUTH_SECRET']?.trim()\n if (configured) return configured\n\n const file = path.join(options.directory, options.filename ?? 'auth.secret')\n try {\n return readSecret(file)\n } catch (error) {\n if (!errorHasCode(error, 'ENOENT')) throw error\n }\n\n fs.mkdirSync(options.directory, { recursive: true })\n const secret = randomToken(options.bytes ?? 32)\n const temporary = `${file}.${process.pid}.${crypto.randomUUID()}.tmp`\n try {\n fs.writeFileSync(temporary, secret, { mode: 0o600, flag: 'wx' })\n try {\n fs.linkSync(temporary, file)\n return secret\n } catch (error) {\n if (!errorHasCode(error, 'EEXIST')) throw error\n return readSecret(file)\n }\n } finally {\n fs.rmSync(temporary, { force: true })\n }\n}\n\nfunction readSecret(file: string) {\n const secret = fs.readFileSync(file, 'utf8').trim()\n if (!secret) throw new Error(`Secret file is empty: ${file}`)\n return secret\n}\n"]}
|
package/dist/build/index.js
CHANGED
|
@@ -63,10 +63,8 @@ function containedPath(parent, child, name) {
|
|
|
63
63
|
if (!child.trim())
|
|
64
64
|
throw new Error(`${name} must not be empty`);
|
|
65
65
|
const resolved = path.resolve(parent, child);
|
|
66
|
-
|
|
67
|
-
if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {
|
|
66
|
+
if (resolved === parent || !contains(parent, resolved))
|
|
68
67
|
throw new Error(`${name} must stay inside ${parent}`);
|
|
69
|
-
}
|
|
70
68
|
return resolved;
|
|
71
69
|
}
|
|
72
70
|
async function manifest(root) {
|
package/dist/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAC1E,OAAO,IAAI,MAAM,WAAW,CAAA;AAK5B,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAAY,EAAE,UAAU,GAAG,uBAAuB;IAC7F,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAY,CAAA;IAC5F,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,iBAAiB,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,IAAI,MAAM,CAAC,EAAE,CAAC;QACrG,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,0CAA0C,CAAC,CAAA;IAC1E,CAAC;IACD,IAAI,OAA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tC,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAC7E,CAAC,CAAA;IACD,MAAM,KAAK,CAAC,IAAI,CAAC,CAAA;IACjB,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,aAAa,CAAC,IAAyB,EAAE,KAA0B;IAC1E,OAAO,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,CAAA;AACpG,CAAC","sourcesContent":["import { createHash } from 'node:crypto'\nimport { cp, lstat, mkdir, readFile, readdir, rm } from 'node:fs/promises'\nimport path from 'node:path'\n\nexport type ServerAsset = { source: string; destination: string }\nexport type ServerAssetsConfig = { outputDirectory: string; assets: ServerAsset[] }\n\nexport async function loadServerAssetsConfig(root: string, configFile = 'ras-stack.assets.json') {\n const source = JSON.parse(await readFile(path.resolve(root, configFile), 'utf8')) as unknown\n if (!source || typeof source !== 'object' || !('outputDirectory' in source) || !('assets' in source)) {\n throw new Error(`${configFile} must contain outputDirectory and assets`)\n }\n if (typeof source.outputDirectory !== 'string' || !Array.isArray(source.assets)) {\n throw new Error(`${configFile} must contain a string outputDirectory and an assets array`)\n }\n const assets = source.assets.map((asset, index) => {\n if (\n !asset ||\n typeof asset !== 'object' ||\n !('source' in asset) ||\n typeof asset.source !== 'string' ||\n !('destination' in asset) ||\n typeof asset.destination !== 'string'\n ) {\n throw new Error(`${configFile} assets[${index}] must contain string source and destination paths`)\n }\n return { source: asset.source, destination: asset.destination }\n })\n return { outputDirectory: source.outputDirectory, assets } satisfies ServerAssetsConfig\n}\n\nexport async function syncServerAssets(root: string, config: ServerAssetsConfig) {\n const paths = assetPaths(root, config)\n await Promise.all(\n paths.map(async (asset) => {\n await manifest(asset.source)\n await rm(asset.destination, { force: true, recursive: true })\n await mkdir(path.dirname(asset.destination), { recursive: true })\n await cp(asset.source, asset.destination, { recursive: true })\n }),\n )\n}\n\nexport async function checkServerAssets(root: string, config: ServerAssetsConfig) {\n const compared = await Promise.all(\n assetPaths(root, config).map(async (asset) => {\n const [source, destination] = await Promise.all([manifest(asset.source), manifest(asset.destination).catch(() => undefined)])\n return !destination || !equalManifest(source, destination) ? asset.label : undefined\n }),\n )\n return compared.filter((destination) => destination !== undefined)\n}\n\nfunction assetPaths(root: string, config: ServerAssetsConfig) {\n const repository = path.resolve(root)\n const output = containedPath(repository, config.outputDirectory, 'outputDirectory')\n const assets = config.assets.map((asset, index) => ({\n source: containedPath(repository, asset.source, `assets[${index}].source`),\n destination: containedPath(output, asset.destination, `assets[${index}].destination`),\n label: asset.destination,\n }))\n for (const [index, asset] of assets.entries()) {\n for (const other of assets.slice(index + 1)) {\n if (contains(asset.destination, other.destination) || contains(other.destination, asset.destination)) {\n throw new Error(`asset destinations must not overlap: ${asset.label} and ${other.label}`)\n }\n }\n }\n return assets\n}\n\nfunction contains(parent: string, child: string) {\n const relative = path.relative(parent, child)\n return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative))\n}\n\nfunction containedPath(parent: string, child: string, name: string) {\n if (!child.trim()) throw new Error(`${name} must not be empty`)\n const resolved = path.resolve(parent, child)\n const relative = path.relative(parent, resolved)\n if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative)) {\n throw new Error(`${name} must stay inside ${parent}`)\n }\n return resolved\n}\n\nasync function manifest(root: string) {\n const files = new Map<string, string>()\n const visit = async (current: string) => {\n const info = await lstat(current)\n if (info.isSymbolicLink()) throw new Error(`server assets must not contain symbolic links: ${current}`)\n if (info.isFile()) {\n files.set(\n path.relative(root, current) || '.',\n createHash('sha256')\n .update(await readFile(current))\n .digest('hex'),\n )\n return\n }\n if (!info.isDirectory()) throw new Error(`server assets must contain only files and directories: ${current}`)\n const entries = await readdir(current)\n await Promise.all(entries.map((entry) => visit(path.join(current, entry))))\n }\n await visit(root)\n return files\n}\n\nfunction equalManifest(left: Map<string, string>, right: Map<string, string>) {\n return left.size === right.size && [...left].every(([name, digest]) => right.get(name) === digest)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAC1E,OAAO,IAAI,MAAM,WAAW,CAAA;AAK5B,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAAY,EAAE,UAAU,GAAG,uBAAuB;IAC7F,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAY,CAAA;IAC5F,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,iBAAiB,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,IAAI,MAAM,CAAC,EAAE,CAAC;QACrG,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,0CAA0C,CAAC,CAAA;IAC1E,CAAC;IACD,IAAI,OAAO,MAAM,CAAC,eAAe,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QAChF,MAAM,IAAI,KAAK,CAAC,GAAG,UAAU,4DAA4D,CAAC,CAAA;IAC5F,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,C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,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,MAAM,CAAC,CAAA;AACpG,CAAC","sourcesContent":["import { createHash } from 'node:crypto'\nimport { cp, lstat, mkdir, readFile, readdir, rm } from 'node:fs/promises'\nimport path from 'node:path'\n\nexport type ServerAsset = { source: string; destination: string }\nexport type ServerAssetsConfig = { outputDirectory: string; assets: ServerAsset[] }\n\nexport async function loadServerAssetsConfig(root: string, configFile = 'ras-stack.assets.json') {\n const source = JSON.parse(await readFile(path.resolve(root, configFile), 'utf8')) as unknown\n if (!source || typeof source !== 'object' || !('outputDirectory' in source) || !('assets' in source)) {\n throw new Error(`${configFile} must contain outputDirectory and assets`)\n }\n if (typeof source.outputDirectory !== 'string' || !Array.isArray(source.assets)) {\n throw new Error(`${configFile} must contain a string outputDirectory and an assets array`)\n }\n const assets = source.assets.map((asset, index) => {\n if (\n !asset ||\n typeof asset !== 'object' ||\n !('source' in asset) ||\n typeof asset.source !== 'string' ||\n !('destination' in asset) ||\n typeof asset.destination !== 'string'\n ) {\n throw new Error(`${configFile} assets[${index}] must contain string source and destination paths`)\n }\n return { source: asset.source, destination: asset.destination }\n })\n return { outputDirectory: source.outputDirectory, assets } satisfies ServerAssetsConfig\n}\n\nexport async function syncServerAssets(root: string, config: ServerAssetsConfig) {\n const paths = assetPaths(root, config)\n await Promise.all(\n paths.map(async (asset) => {\n await manifest(asset.source)\n await rm(asset.destination, { force: true, recursive: true })\n await mkdir(path.dirname(asset.destination), { recursive: true })\n await cp(asset.source, asset.destination, { recursive: true })\n }),\n )\n}\n\nexport async function checkServerAssets(root: string, config: ServerAssetsConfig) {\n const compared = await Promise.all(\n assetPaths(root, config).map(async (asset) => {\n const [source, destination] = await Promise.all([manifest(asset.source), manifest(asset.destination).catch(() => undefined)])\n return !destination || !equalManifest(source, destination) ? asset.label : undefined\n }),\n )\n return compared.filter((destination) => destination !== undefined)\n}\n\nfunction assetPaths(root: string, config: ServerAssetsConfig) {\n const repository = path.resolve(root)\n const output = containedPath(repository, config.outputDirectory, 'outputDirectory')\n const assets = config.assets.map((asset, index) => ({\n source: containedPath(repository, asset.source, `assets[${index}].source`),\n destination: containedPath(output, asset.destination, `assets[${index}].destination`),\n label: asset.destination,\n }))\n for (const [index, asset] of assets.entries()) {\n for (const other of assets.slice(index + 1)) {\n if (contains(asset.destination, other.destination) || contains(other.destination, asset.destination)) {\n throw new Error(`asset destinations must not overlap: ${asset.label} and ${other.label}`)\n }\n }\n }\n return assets\n}\n\nfunction contains(parent: string, child: string) {\n const relative = path.relative(parent, child)\n return relative === '' || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative))\n}\n\nfunction containedPath(parent: string, child: string, name: string) {\n if (!child.trim()) throw new Error(`${name} must not be empty`)\n const resolved = path.resolve(parent, child)\n if (resolved === parent || !contains(parent, resolved)) throw new Error(`${name} must stay inside ${parent}`)\n return resolved\n}\n\nasync function manifest(root: string) {\n const files = new Map<string, string>()\n const visit = async (current: string) => {\n const info = await lstat(current)\n if (info.isSymbolicLink()) throw new Error(`server assets must not contain symbolic links: ${current}`)\n if (info.isFile()) {\n files.set(\n path.relative(root, current) || '.',\n createHash('sha256')\n .update(await readFile(current))\n .digest('hex'),\n )\n return\n }\n if (!info.isDirectory()) throw new Error(`server assets must contain only files and directories: ${current}`)\n const entries = await readdir(current)\n await Promise.all(entries.map((entry) => visit(path.join(current, entry))))\n }\n await visit(root)\n return files\n}\n\nfunction equalManifest(left: Map<string, string>, right: Map<string, string>) {\n return left.size === right.size && [...left].every(([name, digest]) => right.get(name) === digest)\n}\n"]}
|
package/dist/changesets/index.js
CHANGED
|
@@ -2,9 +2,10 @@ import { parseChangesetFile } from '@changesets/parse';
|
|
|
2
2
|
import { getPackages } from '@manypkg/get-packages';
|
|
3
3
|
import { readdir, readFile } from 'node:fs/promises';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
+
import { errorHasCode } from '../server/errors.js';
|
|
5
6
|
export async function checkChangesets(root) {
|
|
6
7
|
const files = await readdir(join(root, '.changeset')).catch((error) => {
|
|
7
|
-
if (error
|
|
8
|
+
if (errorHasCode(error, 'ENOENT'))
|
|
8
9
|
return [];
|
|
9
10
|
throw error;
|
|
10
11
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/changesets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/changesets/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAElD,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAY;IAChD,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QAC7E,IAAI,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC;YAAE,OAAO,EAAE,CAAA;QAC5C,MAAM,KAAK,CAAA;IACb,CAAC,CAAC,CAAA;IACF,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,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dir, readFile } from 'node:fs/promises'\nimport { join } from 'node:path'\nimport { errorHasCode } from '../server/errors.js'\n\nexport async function checkChangesets(root: string): Promise<string[]> {\n const files = await readdir(join(root, '.changeset')).catch((error: unknown) => {\n if (errorHasCode(error, 'ENOENT')) return []\n throw error\n })\n const changesets = files.filter((file) => file.endsWith('.md') && file !== 'README.md').toSorted()\n if (changesets.length === 0) return []\n const { packages } = await getPackages(root)\n const names = new Set(packages.map(({ packageJson }) => packageJson.name))\n const errors: string[] = []\n for (const file of changesets) {\n const path = `.changeset/${file}`\n // Read serially so a large changeset directory does not open every file at once.\n // oxlint-disable-next-line no-await-in-loop\n const contents = await readFile(join(root, path), 'utf8')\n let releases\n try {\n releases = parseChangesetFile(contents).releases\n } catch {\n errors.push(`${path}: missing or invalid frontmatter`)\n continue\n }\n for (const { name } of releases) {\n if (!names.has(name)) errors.push(`${path}: unknown package ${JSON.stringify(name)}`)\n }\n }\n return errors\n}\n"]}
|
package/dist/cli.d.ts
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
import { runAssetsCli } from './build/cli.js';
|
|
3
3
|
import { runChangesetsCli } from './changesets/cli.js';
|
|
4
4
|
import { runPreviewCli } from './preview/cli.js';
|
|
5
|
-
import { runRealtimeCli } from './runtime/dev-cli.js';
|
|
6
5
|
declare const commands: {
|
|
7
6
|
readonly assets: typeof runAssetsCli;
|
|
8
7
|
readonly changesets: typeof runChangesetsCli;
|
|
9
8
|
readonly preview: typeof runPreviewCli;
|
|
10
|
-
readonly realtime:
|
|
9
|
+
readonly realtime: (arguments_: string[]) => Promise<void>;
|
|
11
10
|
};
|
|
12
11
|
export type RasCommand = keyof typeof commands;
|
|
13
12
|
export declare function parseRasCommand(arguments_: string[]): {
|
package/dist/cli.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { runAssetsCli } from './build/cli.js';
|
|
3
3
|
import { runChangesetsCli } from './changesets/cli.js';
|
|
4
4
|
import { runPreviewCli } from './preview/cli.js';
|
|
5
|
-
import {
|
|
5
|
+
import { parseRealtimeDevArguments, runRealtimeDev } from './runtime/dev.js';
|
|
6
6
|
const commands = {
|
|
7
7
|
assets: runAssetsCli,
|
|
8
8
|
changesets: runChangesetsCli,
|
|
9
9
|
preview: runPreviewCli,
|
|
10
|
-
realtime:
|
|
10
|
+
realtime: (arguments_) => runRealtimeDev(parseRealtimeDevArguments(arguments_)),
|
|
11
11
|
};
|
|
12
12
|
export function parseRasCommand(arguments_) {
|
|
13
13
|
const [command, ...argumentsRest] = arguments_;
|
|
@@ -22,7 +22,13 @@ export async function runRasCli(arguments_) {
|
|
|
22
22
|
process.exitCode = 2;
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
try {
|
|
26
|
+
await commands[parsed.command](parsed.arguments);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(error instanceof Error ? error.message : error);
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
33
|
if (import.meta.main)
|
|
28
34
|
await runRasCli(process.argv.slice(2));
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,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AAK,CAAC,CAAC,CAAC,CAAC,CAAA","sourcesContent":["#!/usr/bin/env node\nimport { runAssetsCli } from './build/cli.js'\nimport { runChangesetsCli } from './changesets/cli.js'\nimport { runPreviewCli } from './preview/cli.js'\nimport { parseRealtimeDevArguments, runRealtimeDev } from './runtime/dev.js'\n\nconst commands = {\n assets: runAssetsCli,\n changesets: runChangesetsCli,\n preview: runPreviewCli,\n realtime: (arguments_: string[]) => runRealtimeDev(parseRealtimeDevArguments(arguments_)),\n} as const\n\nexport type RasCommand = keyof typeof commands\n\nexport function parseRasCommand(arguments_: string[]): { arguments: string[]; command: RasCommand } | undefined {\n const [command, ...argumentsRest] = arguments_\n if (!(command && Object.hasOwn(commands, command))) return undefined\n return { arguments: argumentsRest, command: command as RasCommand }\n}\n\nexport async function runRasCli(arguments_: string[]): Promise<void> {\n const parsed = parseRasCommand(arguments_)\n if (!parsed) {\n console.error('usage: ras <assets|changesets|preview|realtime> [arguments]')\n process.exitCode = 2\n return\n }\n try {\n await commands[parsed.command](parsed.arguments)\n } catch (error) {\n console.error(error instanceof Error ? error.message : error)\n process.exitCode = 1\n }\n}\n\nif (import.meta.main) await runRasCli(process.argv.slice(2))\n"]}
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
+
import type { databaseTarget } from '../database/index.js';
|
|
2
|
+
export type { DatabaseTarget } from '../database/index.js';
|
|
1
3
|
export declare function assertMutationOriginConformance(guard: (request: Request) => void | Promise<void>, options?: {
|
|
2
4
|
trustForwardedHeaders?: boolean;
|
|
3
5
|
}): Promise<void>;
|
|
4
6
|
export type SqlitePragmaReader = (name: 'journal_mode' | 'synchronous' | 'busy_timeout' | 'foreign_keys') => unknown;
|
|
5
7
|
export declare function assertSqliteConformance(readPragma: SqlitePragmaReader): Promise<void>;
|
|
6
|
-
export type
|
|
7
|
-
provider: 'sqlite';
|
|
8
|
-
file: string;
|
|
9
|
-
} | {
|
|
10
|
-
provider: 'postgres';
|
|
11
|
-
url: string;
|
|
12
|
-
};
|
|
13
|
-
export type DatabaseTargetResolver = (options: {
|
|
14
|
-
databaseUrl?: string;
|
|
15
|
-
sqliteFile: string;
|
|
16
|
-
}) => DatabaseTarget;
|
|
8
|
+
export type DatabaseTargetResolver = typeof databaseTarget;
|
|
17
9
|
export declare function assertDatabaseTargetConformance(resolve: DatabaseTargetResolver): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolveSqlitePragmas } from '../database/pragmas.js';
|
|
1
2
|
class ConformanceError extends Error {
|
|
2
3
|
scenario;
|
|
3
4
|
constructor(scenario, message, options = {}) {
|
|
@@ -27,6 +28,7 @@ export async function assertMutationOriginConformance(guard, options = {}) {
|
|
|
27
28
|
})));
|
|
28
29
|
}
|
|
29
30
|
}
|
|
31
|
+
const synchronousLevels = { OFF: 0, NORMAL: 1, FULL: 2, EXTRA: 3 };
|
|
30
32
|
export async function assertSqliteConformance(readPragma) {
|
|
31
33
|
const values = {
|
|
32
34
|
journalMode: String(await readPragma('journal_mode')).toLowerCase(),
|
|
@@ -34,14 +36,17 @@ export async function assertSqliteConformance(readPragma) {
|
|
|
34
36
|
busyTimeout: Number(await readPragma('busy_timeout')),
|
|
35
37
|
foreignKeys: Number(await readPragma('foreign_keys')),
|
|
36
38
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
const expected = resolveSqlitePragmas();
|
|
40
|
+
const journalMode = expected.journalMode.toLowerCase();
|
|
41
|
+
if (values.journalMode !== journalMode && values.journalMode !== 'memory') {
|
|
42
|
+
throw new ConformanceError('SQLite journal mode', `expected ${journalMode} or memory, received ${values.journalMode}`);
|
|
39
43
|
}
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
const synchronous = synchronousLevels[expected.synchronous];
|
|
45
|
+
if (values.synchronous !== synchronous) {
|
|
46
|
+
throw new ConformanceError('SQLite synchronous mode', `expected ${expected.synchronous} (${synchronous}), received ${values.synchronous}`);
|
|
42
47
|
}
|
|
43
|
-
if (values.busyTimeout !==
|
|
44
|
-
throw new ConformanceError('SQLite busy timeout', `expected
|
|
48
|
+
if (values.busyTimeout !== expected.busyTimeout) {
|
|
49
|
+
throw new ConformanceError('SQLite busy timeout', `expected ${expected.busyTimeout}, received ${values.busyTimeout}`);
|
|
45
50
|
}
|
|
46
51
|
if (values.foreignKeys !== 1) {
|
|
47
52
|
throw new ConformanceError('SQLite foreign keys', `expected enabled (1), received ${values.foreignKeys}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/conformance/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/conformance/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,wBAAwB,CAAA;AAIjF,MAAM,gBAAiB,SAAQ,KAAK;IAEvB,QAAQ;IADnB,YACW,QAAgB,EACzB,OAAe,EACf,OAAO,GAAwB,EAAE;QAEjC,KAAK,CAAC,GAAG,QAAQ,KAAK,OAAO,EAAE,EAAE,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAA;wBAJ3F,QAAQ;QAKjB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;IAChC,CAAC;CACF;AAED,MAAM,CAAC,KAAK,UAAU,+BAA+B,CACnD,KAAiD,EACjD,OAAO,GAAwC,EAAE;IAEjD,MAAM,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE,CACzC,KAAK,CACH,IAAI,OAAO,CAAC,4BAA4B,EAAE;QACxC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,MAAM,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,aAAa,EAAE;KAC5E,CAAC,CACH,CACF,CAAA;IACD,MAAM,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE,CAC1C,KAAK,CACH,IAAI,OAAO,CAA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EAAE,CAAC;QACnH,MAAM,MAAM,GAAG,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAA;QACxD,IAAI,MAAM,CAAC,QAAQ,KAAK,UAAU,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,EAAE,CAAC;YACzD,MAAM,IAAI,gBAAgB,CAAC,4BAA4B,EAAE,2BAA2B,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,MAAM,CAAC,CAAA;QAClH,CAAC;IACH,CAAC;IAED,IAAI,CAAC;QACH,OAAO,CAAC,EAAE,WAAW,EAAE,sCAAsC,EAAE,UAAU,EAAE,CAAC,CAAA;IAC9E,CAAC;IAAC,MAAM,CAAC;QACP,OAAM;IACR,CAAC;IACD,MAAM,IAAI,gBAAgB,CAAC,yBAAyB,EAAE,8CAA8C,CAAC,CAAA;AACvG,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,QAAgB,EAAE,IAAgC;IACxE,IAAI,CAAC;QACH,MAAM,IAAI,EAAE,CAAA;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,gBAAgB,CAAC,QAAQ,EAAE,iCAAiC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IAC3F,CAAC;AACH,CAAC;AAED,KAAK,UAAU,QAAQ,CAAC,QAAgB,EAAE,IAAgC;IACxE,IAAI,CAAC;QACH,MAAM,IAAI,EAAE,CAAA;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAM;IACR,CAAC;IACD,MAAM,IAAI,gBAAgB,CAAC,QAAQ,EAAE,iCAAiC,CAAC,CAAA;AACzE,CAAC","sourcesContent":["import type { databaseTarget } from '../database/index.js'\nimport { resolveSqlitePragmas, type SqlitePragmas } from '../database/pragmas.js'\n\nexport type { DatabaseTarget } from '../database/index.js'\n\nclass ConformanceError extends Error {\n constructor(\n readonly scenario: string,\n message: string,\n options: { cause?: unknown } = {},\n ) {\n super(`${scenario}: ${message}`, options.cause === undefined ? undefined : { cause: options.cause })\n this.name = 'ConformanceError'\n }\n}\n\nexport async function assertMutationOriginConformance(\n guard: (request: Request) => void | Promise<void>,\n options: { trustForwardedHeaders?: boolean } = {},\n) {\n await accepted('same-origin request', () =>\n guard(\n new Request('https://app.example/action', {\n method: 'POST',\n headers: { origin: 'https://app.example', 'sec-fetch-site': 'same-origin' },\n }),\n ),\n )\n await rejected('cross-origin request', () =>\n guard(\n new Request('https://app.example/action', {\n method: 'POST',\n headers: { origin: 'https://attacker.example', 'sec-fetch-site': 'cross-site' },\n }),\n ),\n )\n await rejected('missing-origin request', () => guard(new Request('https://app.example/action', { method: 'POST' })))\n if (!options.trustForwardedHeaders) {\n await rejected('spoofed forwarded-origin request', () =>\n guard(\n new Request('https://app.example/action', {\n method: 'POST',\n headers: {\n origin: 'https://attacker.example',\n 'x-forwarded-host': 'attacker.example',\n 'x-forwarded-proto': 'https',\n },\n }),\n ),\n )\n }\n}\n\nconst synchronousLevels = { OFF: 0, NORMAL: 1, FULL: 2, EXTRA: 3 } satisfies Record<Required<SqlitePragmas>['synchronous'], number>\n\nexport type SqlitePragmaReader = (name: 'journal_mode' | 'synchronous' | 'busy_timeout' | 'foreign_keys') => unknown\n\nexport async function assertSqliteConformance(readPragma: SqlitePragmaReader) {\n const values = {\n journalMode: String(await readPragma('journal_mode')).toLowerCase(),\n synchronous: Number(await readPragma('synchronous')),\n busyTimeout: Number(await readPragma('busy_timeout')),\n foreignKeys: Number(await readPragma('foreign_keys')),\n }\n const expected = resolveSqlitePragmas()\n const journalMode = expected.journalMode.toLowerCase()\n if (values.journalMode !== journalMode && values.journalMode !== 'memory') {\n throw new ConformanceError('SQLite journal mode', `expected ${journalMode} or memory, received ${values.journalMode}`)\n }\n const synchronous = synchronousLevels[expected.synchronous]\n if (values.synchronous !== synchronous) {\n throw new ConformanceError(\n 'SQLite synchronous mode',\n `expected ${expected.synchronous} (${synchronous}), received ${values.synchronous}`,\n )\n }\n if (values.busyTimeout !== expected.busyTimeout) {\n throw new ConformanceError('SQLite busy timeout', `expected ${expected.busyTimeout}, received ${values.busyTimeout}`)\n }\n if (values.foreignKeys !== 1) {\n throw new ConformanceError('SQLite foreign keys', `expected enabled (1), received ${values.foreignKeys}`)\n }\n}\n\nexport type DatabaseTargetResolver = typeof databaseTarget\n\nexport function assertDatabaseTargetConformance(resolve: DatabaseTargetResolver) {\n const sqliteFile = '/data/application.sqlite'\n const sqlite = resolve({ sqliteFile })\n if (sqlite.provider !== 'sqlite' || sqlite.file !== sqliteFile) {\n throw new ConformanceError('default database target', 'expected the configured SQLite file')\n }\n\n for (const url of ['postgres://user:secret@database/application', 'postgresql://user:secret@database/application']) {\n const target = resolve({ databaseUrl: url, sqliteFile })\n if (target.provider !== 'postgres' || target.url !== url) {\n throw new ConformanceError('PostgreSQL database target', `expected the configured ${new URL(url).protocol} URL`)\n }\n }\n\n try {\n resolve({ databaseUrl: 'https://database.example/application', sqliteFile })\n } catch {\n return\n }\n throw new ConformanceError('invalid database target', 'expected a non-PostgreSQL URL to be rejected')\n}\n\nasync function accepted(scenario: string, work: () => void | Promise<void>) {\n try {\n await work()\n } catch (error) {\n throw new ConformanceError(scenario, 'expected request to be accepted', { cause: error })\n }\n}\n\nasync function rejected(scenario: string, work: () => void | Promise<void>) {\n try {\n await work()\n } catch {\n return\n }\n throw new ConformanceError(scenario, 'expected request to be rejected')\n}\n"]}
|
package/dist/email/index.d.ts
CHANGED
|
@@ -43,6 +43,6 @@ export declare function standardAuthEmails<User extends {
|
|
|
43
43
|
} = {
|
|
44
44
|
email: string;
|
|
45
45
|
}>(delivery: EmailDelivery, options: StandardAuthEmailOptions): {
|
|
46
|
-
sendResetPassword: (
|
|
47
|
-
sendVerificationEmail: (
|
|
46
|
+
sendResetPassword: ({ user, url }: AuthEmailInput<User>) => Promise<void>;
|
|
47
|
+
sendVerificationEmail: ({ user, url }: AuthEmailInput<User>) => Promise<void>;
|
|
48
48
|
};
|
package/dist/email/index.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { createTransport } from 'nodemailer';
|
|
2
|
-
function createAuthEmailHandler(delivery, message) {
|
|
3
|
-
return async (input, request) => delivery.send(await message(input, request));
|
|
4
|
-
}
|
|
5
2
|
export function smtpConfigFromEnvironment(environment = process.env, keys = {}) {
|
|
6
3
|
const host = environment[keys.host ?? 'SMTP_HOST']?.trim();
|
|
7
4
|
const from = environment[keys.from ?? 'EMAIL_FROM']?.trim();
|
|
@@ -43,15 +40,15 @@ export function createSmtpDelivery(config) {
|
|
|
43
40
|
}
|
|
44
41
|
export function standardAuthEmails(delivery, options) {
|
|
45
42
|
const expiry = 'This link expires in one hour.';
|
|
46
|
-
const
|
|
43
|
+
const send = (subject, label) => async ({ user, url }) => delivery.send({
|
|
47
44
|
to: user.email,
|
|
48
45
|
subject,
|
|
49
46
|
text: `${subject} using this link: ${url}\n\n${expiry}`,
|
|
50
47
|
html: `<p>${escapeHtml(subject)} using the link below.</p><p><a href="${escapeHtml(url)}">${label}</a></p><p>${expiry}</p>`,
|
|
51
48
|
});
|
|
52
49
|
return {
|
|
53
|
-
sendResetPassword:
|
|
54
|
-
sendVerificationEmail:
|
|
50
|
+
sendResetPassword: send(`Reset your ${options.productName} password`, 'Reset password'),
|
|
51
|
+
sendVerificationEmail: send(`Verify your ${options.productName} email address`, 'Verify email address'),
|
|
55
52
|
};
|
|
56
53
|
}
|
|
57
54
|
function escapeHtml(value) {
|
package/dist/email/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/email/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/email/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAiC5C,MAAM,UAAU,yBAAyB,CACvC,WAA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AAQ,CAAC,IAAI,CAAC;QACZ,EAAE,EAAE,IAAI,CAAC,KAAK;QACd,OAAO;QACP,IAAI,EAAE,GAAG,OAAO,qBAAqB,GAAG,OAAO,MAAM,EAAE;QACvD,IAAI,EAAE,MAAM,UAAU,CAAC,OAAO,CAAC,yCAAyC,UAAU,CAAC,GAAG,CAAC,KAAK,KAAK,cAAc,MAAM,MAAM;KAC5H,CAAC,CAAA;IACN,OAAO;QACL,iBAAiB,EAAE,IAAI,CAAC,cAAc,OAAO,CAAC,WAAW,WAAW,EAAE,gBAAgB,CAAC;QACvF,qBAAqB,EAAE,IAAI,CAAC,eAAe,OAAO,CAAC,WAAW,gBAAgB,EAAE,sBAAsB,CAAC;KACxG,CAAA;AACH,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAA;AACjH,CAAC","sourcesContent":["import { createTransport } from 'nodemailer'\n\nexport type EmailMessage = { to: string; subject: string; text: string; html?: string }\n\nexport type SmtpConfig = {\n from: string\n host: string\n port: number\n secure: boolean\n user?: string\n password?: string\n}\n\nexport type SmtpEnvironmentOptions = {\n host?: string\n port?: string\n secure?: string\n user?: string\n password?: string\n from?: string\n}\n\nexport type EmailDelivery = {\n send(message: EmailMessage): Promise<void>\n verify(): Promise<void>\n}\n\nexport type AuthEmailInput<User extends { email: string } = { email: string }> = {\n user: User\n url: string\n token: string\n}\n\nexport function smtpConfigFromEnvironment(\n environment: NodeJS.ProcessEnv = process.env,\n keys: SmtpEnvironmentOptions = {},\n): SmtpConfig | undefined {\n const host = environment[keys.host ?? 'SMTP_HOST']?.trim()\n const from = environment[keys.from ?? 'EMAIL_FROM']?.trim()\n if (!host && !from) return undefined\n if (!host) throw new Error(`${keys.host ?? 'SMTP_HOST'} is required for SMTP email`)\n if (!from) throw new Error(`${keys.from ?? 'EMAIL_FROM'} is required for SMTP email`)\n\n const portKey = keys.port ?? 'SMTP_PORT'\n const port = Number(environment[portKey] ?? 587)\n if (!Number.isInteger(port) || port < 1 || port > 65_535) throw new Error(`${portKey} must be a valid TCP port`)\n\n const userKey = keys.user ?? 'SMTP_USER'\n const passwordKey = keys.password ?? 'SMTP_PASSWORD'\n const user = environment[userKey]?.trim()\n const password = environment[passwordKey]\n if (Boolean(user) !== Boolean(password)) throw new Error(`${userKey} and ${passwordKey} must be configured together`)\n\n return {\n from,\n host,\n port,\n secure: environment[keys.secure ?? 'SMTP_SECURE']?.trim().toLowerCase() === 'true',\n ...(user && password ? { user, password } : {}),\n }\n}\n\nexport function createSmtpDelivery(config: SmtpConfig): EmailDelivery {\n const transport = createTransport({\n host: config.host,\n port: config.port,\n secure: config.secure,\n auth: config.user ? { user: config.user, pass: config.password } : undefined,\n })\n return {\n send: async (message) => transport.sendMail({ from: config.from, ...message }).then(() => undefined),\n verify: async () => transport.verify().then(() => undefined),\n }\n}\n\nexport type StandardAuthEmailOptions = { productName: string }\n\nexport function standardAuthEmails<User extends { email: string } = { email: string }>(\n delivery: EmailDelivery,\n options: StandardAuthEmailOptions,\n) {\n const expiry = 'This link expires in one hour.'\n const send =\n (subject: string, label: string) =>\n async ({ user, url }: AuthEmailInput<User>) =>\n delivery.send({\n to: user.email,\n subject,\n text: `${subject} using this link: ${url}\\n\\n${expiry}`,\n html: `<p>${escapeHtml(subject)} using the link below.</p><p><a href=\"${escapeHtml(url)}\">${label}</a></p><p>${expiry}</p>`,\n })\n return {\n sendResetPassword: send(`Reset your ${options.productName} password`, 'Reset password'),\n sendVerificationEmail: send(`Verify your ${options.productName} email address`, 'Verify email address'),\n }\n}\n\nfunction escapeHtml(value: string) {\n return value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('\"', '"')\n}\n"]}
|
package/dist/posthog/react.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PostHogErrorBoundary, PostHogProvider, usePostHog } from '@posthog/react';
|
|
2
2
|
import { createContext, createElement, useContext, useEffect, useRef, useState } from 'react';
|
|
3
|
-
import { postHogBrowserOptions } from './client.js';
|
|
4
3
|
import { POSTHOG_DEFAULT_INGEST_PATH } from './config.js';
|
|
4
|
+
const POSTHOG_BROWSER_DEFAULTS = '2026-05-30';
|
|
5
5
|
const PostHogLoadedContext = createContext(true);
|
|
6
6
|
export function PostHogIntegration({ children, environment, fallback = createElement('main', null, 'Something went wrong. Refresh the page to try again.'), ingestPath = POSTHOG_DEFAULT_INGEST_PATH, options, service, }) {
|
|
7
7
|
const [isLoaded, setIsLoaded] = useState(false);
|
|
@@ -9,23 +9,35 @@ export function PostHogIntegration({ children, environment, fallback = createEle
|
|
|
9
9
|
loadedRef.current = options?.loaded;
|
|
10
10
|
if (!environment)
|
|
11
11
|
return children;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
...(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
12
|
+
const { session_recording: sessionRecording, ...overrides } = options ?? {};
|
|
13
|
+
const serviceOptions = service
|
|
14
|
+
? {
|
|
15
|
+
serviceName: required(service.name, 'service.name'),
|
|
16
|
+
...(service.version ? { serviceVersion: service.version } : {}),
|
|
17
|
+
...(service.environment ? { environment: service.environment } : {}),
|
|
18
|
+
...(service.resourceAttributes ? { resourceAttributes: service.resourceAttributes } : {}),
|
|
19
|
+
}
|
|
20
|
+
: undefined;
|
|
21
|
+
const browserOptions = {
|
|
22
|
+
api_host: required(ingestPath, 'apiHost'),
|
|
23
|
+
ui_host: environment.uiHost,
|
|
24
|
+
defaults: POSTHOG_BROWSER_DEFAULTS,
|
|
25
|
+
capture_exceptions: true,
|
|
26
|
+
capture_pageview: 'history_change',
|
|
27
|
+
capture_performance: true,
|
|
28
|
+
custom_personal_data_properties: ['token'],
|
|
29
|
+
mask_personal_data_properties: true,
|
|
30
|
+
person_profiles: 'identified_only',
|
|
31
|
+
session_recording: { maskAllInputs: true, blockSelector: '.ph-no-capture', ...sessionRecording },
|
|
32
|
+
...(serviceOptions ? { logs: serviceOptions, metrics: serviceOptions } : {}),
|
|
33
|
+
...(typeof window === 'undefined' ? {} : { tracing_headers: [window.location.hostname] }),
|
|
34
|
+
...overrides,
|
|
35
|
+
loaded: (posthog) => {
|
|
36
|
+
setIsLoaded(true);
|
|
37
|
+
loadedRef.current?.(posthog);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
return createElement(PostHogProvider, { apiKey: environment.projectToken, options: browserOptions }, createElement(PostHogLoadedContext.Provider, { value: isLoaded }, createElement(PostHogErrorBoundary, { fallback }, children)));
|
|
29
41
|
}
|
|
30
42
|
export function PostHogBetterAuthIdentity({ authClient, properties, }) {
|
|
31
43
|
const session = authClient.useSession();
|
|
@@ -53,4 +65,10 @@ export function PostHogBetterAuthIdentity({ authClient, properties, }) {
|
|
|
53
65
|
}, [isReady, posthog, session.data?.user, session.error, session.isPending]);
|
|
54
66
|
return null;
|
|
55
67
|
}
|
|
68
|
+
function required(value, name) {
|
|
69
|
+
const normalized = value.trim();
|
|
70
|
+
if (!normalized)
|
|
71
|
+
throw new Error(`${name} is required`);
|
|
72
|
+
return normalized;
|
|
73
|
+
}
|
|
56
74
|
//# sourceMappingURL=react.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../../src/posthog/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAClF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAkB,UAAU,EAAE,SAAS,EAAE,MA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AAC,OAAO,IAAI,eAAe,EAAE,CAAC;YACjD,OAAO,CAAC,KAAK,EAAE,CAAA;YACf,UAAU,CAAC,OAAO,GAAG,SAAS,CAAA;QAChC,CAAC;IACH,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAA;IAE5E,OAAO,IAAI,CAAA;AACb,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 { PostHogErrorBoundary, PostHogProvider, usePostHog } from '@posthog/react'\nimport { createContext, createElement, type ReactNode, useContext, useEffect, useRef, useState } from 'react'\nimport type { PostHogConfig, Properties } from 'posthog-js'\nimport { POSTHOG_DEFAULT_INGEST_PATH, type PostHogBrowserService, type PostHogEnvironment } from './config.js'\n\nconst POSTHOG_BROWSER_DEFAULTS = '2026-05-30'\n\nconst PostHogLoadedContext = createContext(true)\n\nexport function PostHogIntegration({\n children,\n environment,\n fallback = createElement('main', null, 'Something went wrong. Refresh the page to try again.'),\n ingestPath = POSTHOG_DEFAULT_INGEST_PATH,\n options,\n service,\n}: {\n children?: ReactNode\n environment: PostHogEnvironment | undefined\n fallback?: ReactNode\n ingestPath?: string\n options?: Partial<PostHogConfig>\n service?: PostHogBrowserService\n}) {\n const [isLoaded, setIsLoaded] = useState(false)\n const loadedRef = useRef(options?.loaded)\n loadedRef.current = options?.loaded\n if (!environment) return children\n const { session_recording: sessionRecording, ...overrides } = options ?? {}\n const serviceOptions = service\n ? {\n serviceName: required(service.name, 'service.name'),\n ...(service.version ? { serviceVersion: service.version } : {}),\n ...(service.environment ? { environment: service.environment } : {}),\n ...(service.resourceAttributes ? { resourceAttributes: service.resourceAttributes } : {}),\n }\n : undefined\n const browserOptions: Partial<PostHogConfig> = {\n api_host: required(ingestPath, 'apiHost'),\n ui_host: environment.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 ...(serviceOptions ? { logs: serviceOptions, metrics: serviceOptions } : {}),\n ...(typeof window === 'undefined' ? {} : { tracing_headers: [window.location.hostname] }),\n ...overrides,\n loaded: (posthog) => {\n setIsLoaded(true)\n loadedRef.current?.(posthog)\n },\n }\n return createElement(\n PostHogProvider,\n { apiKey: environment.projectToken, options: browserOptions },\n createElement(PostHogLoadedContext.Provider, { value: isLoaded }, createElement(PostHogErrorBoundary, { fallback }, children)),\n )\n}\n\nexport type BetterAuthUser = { id: string }\nexport type BetterAuthSession<User extends BetterAuthUser = BetterAuthUser> = { user: User }\nexport type BetterAuthSessionState<User extends BetterAuthUser = BetterAuthUser> = {\n data?: BetterAuthSession<User> | null\n error?: unknown\n isPending: boolean\n}\nexport type BetterAuthReactClient<User extends BetterAuthUser = BetterAuthUser> = {\n useSession: () => BetterAuthSessionState<User>\n}\n\nexport function PostHogBetterAuthIdentity<User extends BetterAuthUser>({\n authClient,\n properties,\n}: {\n authClient: BetterAuthReactClient<User>\n properties?: (user: User) => Properties\n}) {\n const session = authClient.useSession()\n const posthog = usePostHog()\n const isLoaded = useContext(PostHogLoadedContext)\n const isReady = isLoaded || posthog['__loaded']\n const identified = useRef<string | undefined>(undefined)\n const propertiesRef = useRef(properties)\n propertiesRef.current = properties\n\n useEffect(() => {\n if (!isReady || session.isPending || session.error) return\n const user = session.data?.user\n const persistedUserId = posthog.get_property('$user_id')\n if (user) {\n if (persistedUserId && persistedUserId !== user.id) posthog.reset()\n posthog.identify(user.id, propertiesRef.current?.(user))\n identified.current = user.id\n } else if (identified.current || persistedUserId) {\n posthog.reset()\n identified.current = undefined\n }\n }, [isReady, posthog, session.data?.user, session.error, session.isPending])\n\n return null\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"]}
|