@stacksjs/config 0.75.9 → 0.75.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export { FRAMEWORK_DEFAULTS } from './defaults';
13
13
  export { validateConfig, reportConfigIssues, type ConfigValidationIssue } from './validators';
14
14
  export { feature, enableFeature, disableFeature, resetFeature, listFeatures } from './features';
15
15
  export { packageComponentRoots, packageJobRoots, packageMigrationRoots, packageModelRoots, packageViewRoots, type PackageResourceOptions, type PackageResourceRoot } from './discovered-resources';
16
- export { resolveViewPatterns, type DefaultViewsSetting, type ViewPatternResolution } from './views';
16
+ export { DEFAULT_VIEW_ROUTE_BUNDLES, DEFAULT_VIEW_TEMPLATES, DEFAULT_VIEWS_ALWAYS, resolveViewPatterns, withheldDefaultViews, type DefaultViewsSetting, type ViewPatternResolution } from './views';
17
17
  export {
18
18
  createRequestContext,
19
19
  enterRequestScope,
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export*from"./config";export{FRAMEWORK_DEFAULTS}from"./defaults";export{validateConfig,reportConfigIssues}from"./validators";export{feature,enableFeature,disableFeature,resetFeature,listFeatures}from"./features";export{packageComponentRoots,packageJobRoots,packageMigrationRoots,packageModelRoots,packageViewRoots}from"./discovered-resources";export{resolveViewPatterns}from"./views";export{createRequestContext,enterRequestScope,installRequestContext,installRequestScope,parseCookieHeader,scopedRequestSnapshot,scopeStxServeContext,useRequestEvent}from"./request-context";export*from"./capabilities";
1
+ export*from"./config";export{FRAMEWORK_DEFAULTS}from"./defaults";export{validateConfig,reportConfigIssues}from"./validators";export{feature,enableFeature,disableFeature,resetFeature,listFeatures}from"./features";export{packageComponentRoots,packageJobRoots,packageMigrationRoots,packageModelRoots,packageViewRoots}from"./discovered-resources";export{DEFAULT_VIEW_ROUTE_BUNDLES,DEFAULT_VIEW_TEMPLATES,DEFAULT_VIEWS_ALWAYS,resolveViewPatterns,withheldDefaultViews}from"./views";export{createRequestContext,enterRequestScope,installRequestContext,installRequestScope,parseCookieHeader,scopedRequestSnapshot,scopeStxServeContext,useRequestEvent}from"./request-context";export*from"./capabilities";
package/dist/views.d.ts CHANGED
@@ -1,46 +1,72 @@
1
1
  import type { PackageResourceRoot } from './discovered-resources';
2
2
  /**
3
- * Compose the view patterns for the dev and production servers
4
- * (stacksjs/stacks#2237).
5
- *
6
- * Both servers registered `[userViewsPath, defaultViewsPath]` unconditionally,
7
- * so every Stacks app served the scaffold's demo storefront as live public
8
- * routes — `/cart`, `/checkout/payment`, `/orders/:id` — and enumerated them
9
- * into its sitemap. An analytics SaaS has no business answering `/checkout`.
3
+ * The default views withheld when `defaultViews` is unset: the pages of every
4
+ * bundle that is not mounted, and the templates that are never routes.
5
+ * Relative to the defaults views directory.
6
+ */
7
+ export declare function withheldDefaultViews(mountedBundles: ReadonlySet<string>): string[];
8
+ /*`.
10
9
  *
11
- * The route registry already lets an app decide what to spread; this is the
12
- * same lever for views.
10
+ * `mountedBundles` is what `mountedDefaultRouteBundles` in `@stacksjs/router`
11
+ * answers; it is a parameter because the router depends on this package. Left
12
+ * out, nothing counts as mounted: a caller that forgot it loses pages loudly,
13
+ * rather than serving forms into routes that are not there.
13
14
  *
14
- * Shared by both callers on purpose. They are in different packages and have
15
- * drifted before — `requestContext` is installed twice, differently, which is
16
- * its own report (#2232) — and a views policy that dev and production disagree
17
- * about is a defect you only find in production.
15
+ * The explicit settings keep their meaning and withhold nothing: `true` is
16
+ * every default view, `false` none, a list exactly the subtrees it names.
17
+ */
18
+ export declare function resolveViewPatterns(userViewsPath: string, defaultViewsPath: string, setting: DefaultViewsSetting | undefined, exists?: (path: string) => boolean, packageViews?: PackageResourceRoot[], mountedBundles?: ReadonlySet<string>): ViewPatternResolution;
19
+ /**
20
+ * The default views that are only as good as a route bundle behind them,
21
+ * keyed by bundle (`STACKS_DEFAULT_ROUTES`; see `resolveDefaultRouteBundles`
22
+ * in `@stacksjs/router`). Entries are files or directories under the defaults
23
+ * views directory.
18
24
  *
19
- * `exists` is injectable so the resolution is testable without a fixture tree;
20
- * it defaults to the real filesystem.
25
+ * `auth` - every page posts to `defaults/routes/auth.ts`: `/login` to
26
+ * `POST /login`, `/register` to `POST /register`, `/forgot-password` to
27
+ * `POST /password/forgot`, `/password/reset/{token}` to `POST /password/reset`,
28
+ * `/auth/magic/{token}` to `POST /auth/magic-link/consume`.
21
29
  *
22
- * Views a discovered package ships are appended LAST, after everything above.
23
- * stx's `getRoute()` returns the first pattern whose relative path matches, so
24
- * anything appended after the existing roots cannot change the answer for a
25
- * path that already resolves. That is what makes this additive for an app with
26
- * no packages, and for every pre-existing route in an app with them.
30
+ * `dashboard` - the storefront, whose routes live in `defaults/routes/dashboard.ts`
31
+ * and not in a bundle of their own: `/cart` posts to `/api/cart/update`, the
32
+ * three checkout steps to `/api/checkout/{contact,shipping,place}`, and
33
+ * `/orders/{id}` is where `place` lands. `dashboard/index.stx` is the stub
34
+ * `/dashboard` renders on the views server, meaningless without the bundle.
27
35
  *
28
- * `defaultViews` is not consulted for packages. That setting decides whether
29
- * the app serves the FRAMEWORK's demo views; an application that installed a
30
- * package asked for that package's pages either way.
36
+ * Served with every bundle mounted, withheld without it: an app answering 200
37
+ * on `/login` whose form posts into a 404 is worse than an app answering 404.
38
+ */
39
+ export declare const DEFAULT_VIEW_ROUTE_BUNDLES: Readonly<Record<string, readonly string[]>>;
40
+ /*` are rendered BY PATH - `renderCmsPage`
41
+ * resolves them with its own lookup and hands them the page it found - and a
42
+ * published CMS page is served at its own URL by the CMS fallback. Routed
43
+ * directly, `/cms/page` renders the shell around no page at all, with or
44
+ * without CMS enabled, so there is no bundle to wait for.
45
+ */
46
+ export declare const DEFAULT_VIEW_TEMPLATES: readonly string[];
47
+ /**
48
+ * Default views served whatever is mounted: the home fallback, the
49
+ * coming-soon page the maintenance gate renders, the error pages (the 404
50
+ * lookup, and `errors/tester`, which gates itself to local deployments) and
51
+ * the mail previews. Named so a test can hold every file in the defaults
52
+ * tree to exactly one of these three lists.
31
53
  */
32
- export declare function resolveViewPatterns(userViewsPath: string, defaultViewsPath: string, setting: DefaultViewsSetting | undefined, exists?: (path: string) => boolean, packageViews?: PackageResourceRoot[]): ViewPatternResolution;
54
+ export declare const DEFAULT_VIEWS_ALWAYS: readonly string[];
33
55
  export declare interface ViewPatternResolution {
34
56
  patterns: string[]
35
57
  missing: string[]
58
+ exclude: string[]
59
+ withheld: string[]
36
60
  }
37
61
  /**
38
62
  * Whether an app serves the framework's default views, and which of them.
39
63
  *
40
- * `true` (the default) keeps every default view registered, which is the
41
- * behaviour every existing app already has. `false` registers the app's own
42
- * views only. An array registers just the named subtrees of the defaults
43
- * directory — `['errors', 'emails']` for an app that wants the error pages and
44
- * the mail previews but not the demo storefront.
64
+ * Unset (the default) serves the default views that have routes behind them:
65
+ * each page that posts to a framework route bundle is served only while that
66
+ * bundle is mounted, see {@link DEFAULT_VIEW_ROUTE_BUNDLES}. `true` serves
67
+ * every default view whatever is mounted, which is what unset used to mean.
68
+ * `false` registers the app's own views only. An array registers just the
69
+ * named subtrees of the defaults directory: `['errors', 'emails']` for an app
70
+ * that wants the error pages and the mail previews but not the demo storefront.
45
71
  */
46
72
  export type DefaultViewsSetting = boolean | string[];
package/dist/views.js CHANGED
@@ -1 +1 @@
1
- import{existsSync}from"node:fs";import{join}from"node:path";import{packageViewRoots}from"./discovered-resources";export function resolveViewPatterns(userViewsPath,defaultViewsPath,setting,exists=existsSync,packageViews=packageViewRoots({exists})){const fromPackages=packageViews.map((root)=>root.dir);if(setting===void 0||setting===!0)return{patterns:[userViewsPath,defaultViewsPath,...fromPackages],missing:[]};if(setting===!1)return{patterns:[userViewsPath,...fromPackages],missing:[]};if(!Array.isArray(setting))return{patterns:[userViewsPath,defaultViewsPath,...fromPackages],missing:[]};const patterns=[userViewsPath],missing=[];for(const name of setting){const cleaned=String(name).replace(/^[/\\]+/,"");if(!cleaned||cleaned.split(/[/\\]/).includes(".."))continue;const candidate=join(defaultViewsPath,cleaned);if(exists(candidate))patterns.push(candidate);else missing.push(cleaned)}patterns.push(...fromPackages);return{patterns,missing}}
1
+ import{existsSync}from"node:fs";import{join}from"node:path";import{packageViewRoots}from"./discovered-resources";export const DEFAULT_VIEW_ROUTE_BUNDLES={auth:["login.stx","register.stx","forgot-password.stx","password","auth"],dashboard:["cart.stx","checkout","orders","dashboard"]},DEFAULT_VIEW_TEMPLATES=["cms"],DEFAULT_VIEWS_ALWAYS=["index.stx","coming-soon.stx","errors","emails"];export function withheldDefaultViews(mountedBundles){const withheld=[];for(const[bundle,views]of Object.entries(DEFAULT_VIEW_ROUTE_BUNDLES))if(!mountedBundles.has(bundle))withheld.push(...views);withheld.push(...DEFAULT_VIEW_TEMPLATES);return withheld}export function resolveViewPatterns(userViewsPath,defaultViewsPath,setting,exists=existsSync,packageViews=packageViewRoots({exists}),mountedBundles=new Set){const fromPackages=packageViews.map((root)=>root.dir);if(setting===void 0){const withheld=withheldDefaultViews(mountedBundles);return{patterns:[userViewsPath,defaultViewsPath,...fromPackages],missing:[],exclude:withheld.map((name)=>join(defaultViewsPath,name)),withheld}}if(setting===!0)return{patterns:[userViewsPath,defaultViewsPath,...fromPackages],missing:[],exclude:[],withheld:[]};if(setting===!1)return{patterns:[userViewsPath,...fromPackages],missing:[],exclude:[],withheld:[]};if(!Array.isArray(setting))return{patterns:[userViewsPath,defaultViewsPath,...fromPackages],missing:[],exclude:[],withheld:[]};const patterns=[userViewsPath],missing=[];for(const name of setting){const cleaned=String(name).replace(/^[/\\]+/,"");if(!cleaned||cleaned.split(/[/\\]/).includes(".."))continue;const candidate=join(defaultViewsPath,cleaned);if(exists(candidate))patterns.push(candidate);else missing.push(cleaned)}patterns.push(...fromPackages);return{patterns,missing,exclude:[],withheld:[]}}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/config",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.9",
5
+ "version": "0.75.10",
6
6
  "description": "The Stacks config helper methods.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -55,14 +55,14 @@
55
55
  "prepublishOnly": "bun run build"
56
56
  },
57
57
  "dependencies": {
58
- "@stacksjs/events": "0.75.9",
59
- "@stacksjs/path": "0.75.9",
60
- "@stacksjs/tunnel": "0.75.9",
58
+ "@stacksjs/events": "0.75.10",
59
+ "@stacksjs/path": "0.75.10",
60
+ "@stacksjs/tunnel": "0.75.10",
61
61
  "ts-pantry": "^0.11.35"
62
62
  },
63
63
  "devDependencies": {
64
- "@stacksjs/alias": "0.75.9",
65
- "@stacksjs/types": "0.75.9",
64
+ "@stacksjs/alias": "0.75.10",
65
+ "@stacksjs/types": "0.75.10",
66
66
  "better-dx": "^0.2.24"
67
67
  }
68
68
  }