@stacksjs/defaults 0.75.685 → 0.75.690
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/ai/skills/stacks-config/SKILL.md +10 -0
- package/ai/skills/stacks-desktop/SKILL.md +14 -1
- package/ai/skills/stacks-migrations/SKILL.md +6 -0
- package/ai/skills/stacks-native/CATALOG.md +11 -11
- package/ai/skills/stacks-socials/SKILL.md +24 -0
- package/app/Actions/Dashboard/Models/ModelActionRunAction.ts +6 -5
- package/app/Actions/Dashboard/Models/ModelDestroyAction.ts +4 -3
- package/app/Actions/Dashboard/Models/ModelOptionsAction.ts +16 -9
- package/app/Actions/Dashboard/Models/ModelRelatedAction.ts +5 -5
- package/app/Actions/Dashboard/Models/ModelSaveAction.ts +37 -18
- package/app/Actions/Dashboard/Models/ModelShowAction.ts +3 -4
- package/app/Actions/Dashboard/Models/ModelUpdateAction.ts +4 -3
- package/app/Actions/Dashboard/Models/model-destroy.ts +4 -2
- package/app/Actions/Dashboard/Models/model-options.ts +11 -6
- package/app/Actions/Dashboard/Models/model-related.ts +9 -6
- package/app/Actions/Dashboard/Models/model-row-writes.ts +13 -9
- package/app/Actions/Dashboard/Models/model-write.ts +61 -3
- package/ide/vscode/package.json +1 -1
- package/package.json +5 -5
- package/resources/components/Dashboard/Models/ModelRecordDetail.stx +1 -4
- package/routes/dashboard.ts +2 -14
- package/routes/email.ts +28 -0
- package/views/dashboard/layouts/default.stx +3 -1
|
@@ -27,6 +27,16 @@ The readiness promise and override storage are shared across installed copies.
|
|
|
27
27
|
Compiled server builds have a separate minimal env config and may deliberately
|
|
28
28
|
set `SKIP_CONFIG_LOADING=true`; see `stacks-server`.
|
|
29
29
|
|
|
30
|
+
A compiled app has no `config/` beside it, and the loader's `import()` of a
|
|
31
|
+
computed path is one the bundler cannot follow. Its entry hands the loader
|
|
32
|
+
static loaders instead, before anything imports config:
|
|
33
|
+
`registerBundledConfig({ app: () => import('/abs/config/app.ts') })` from the
|
|
34
|
+
dependency-free `@stacksjs/config/sources` (it throws once config has loaded).
|
|
35
|
+
`USER_CONFIG_FILES` / `userConfigFileNames()` list the files the loader reads.
|
|
36
|
+
`settledConfigSource()` says what was loaded: `bundled`, `files` under a root,
|
|
37
|
+
or `skipped`, the files that loaded and those that threw.
|
|
38
|
+
`describeConfigSource()` turns that into one log line.
|
|
39
|
+
|
|
30
40
|
Individual exports (app, auth, database, queue, filesystems and others) are also
|
|
31
41
|
available. Use the matching `satisfies ...Config` type or define helper.
|
|
32
42
|
`defineModel` belongs to `@stacksjs/orm`. App registries are owned by their
|
|
@@ -565,10 +565,23 @@ applied with `migrateCompiledDatabase` and `DB_CONNECTION`/`DB_DATABASE_PATH` po
|
|
|
565
565
|
newer version changed, or a migration that fails (the backup is put back), stops the launch with the reason in the
|
|
566
566
|
app's log.
|
|
567
567
|
|
|
568
|
+
A launch that fails once the instance lock is held (the database, config, the agent module or its `start`) says why in
|
|
569
|
+
a small window of its own as well as the log, since nobody reads the log of an app opened from Finder or a desktop
|
|
570
|
+
entry. The agent is stopped first. The page is static and escaped, served from loopback only while the window is open,
|
|
571
|
+
and names the log file when the log goes to one. The window keeps its titlebar whatever `window.titlebarHidden` says.
|
|
572
|
+
Closing it quits with exit code 1 and releases the lock (`showFailureWindow`, `renderFailurePage`).
|
|
573
|
+
|
|
568
574
|
`buddy build:desktop` also bundles the project's own scripts that pages load as `src="/assets/....ts"` (every `.stx`
|
|
569
575
|
under `resources/` is read for them): each is built for the browser with what it imports (`appClientScripts`) and
|
|
570
576
|
embedded at the URL the page asks for, served as JavaScript. A page naming a script that is not in `resources/assets`
|
|
571
|
-
fails the build.
|
|
577
|
+
fails the build.
|
|
578
|
+
|
|
579
|
+
`agent.config: true` compiles the project's `config/*.ts` into the app: every file the config loader reads that the
|
|
580
|
+
project has (`appConfigFiles`), each named in a static `import()`. At launch, after the database and before the agent
|
|
581
|
+
module, they are registered with `registerBundledConfig` and loaded, so a built app runs on its own config rather
|
|
582
|
+
than the framework defaults. A file that throws stops the launch with the reason in the log. Either way the app logs
|
|
583
|
+
which config it booted with (`[App] config: app.ts, database.ts compiled into the app; framework defaults for the
|
|
584
|
+
rest`, or `no config/*.ts under <root>` when a built app has none). Off by default.
|
|
572
585
|
|
|
573
586
|
**Views.** `buddy dev:desktop` serves `agent.views` live through stx (`bun-plugin-stx/serve`, with the gate and the
|
|
574
587
|
agent module in its `onRequest`). `buddy build:desktop` builds them to static pages with stx's `buildStaticSite`
|
|
@@ -38,6 +38,12 @@ buddy migrate:align --relax-constraints # also plan lossless removal of obsolete
|
|
|
38
38
|
buddy migrate:align --apply # rename legacy indexes, add missing indexes/FKs/columns, widen losslessly
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
`generate:db-types` types each table from its model and replays the corpus for
|
|
42
|
+
the rest: a table no model owns is typed from the migrations alone, and a
|
|
43
|
+
column a hand-written migration adds to a model's table (`ALTER TABLE ... ADD
|
|
44
|
+
COLUMN`) is typed as SQLite stores it. Where both declare a column, the model's
|
|
45
|
+
type wins, so an enum stays a union.
|
|
46
|
+
|
|
41
47
|
An app that develops on one dialect and deploys on another keeps a corpus per
|
|
42
48
|
dialect (`database/migrations/<dialect>/`, each with its own snapshot). A plain
|
|
43
49
|
`generate:migrations` moves only the connected dialect and then warns, naming
|
|
@@ -21,7 +21,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
21
21
|
| `@stacksjs/auth` | [`stacks-auth`](../stacks-auth/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/auth/src/index.ts) | 136 |
|
|
22
22
|
| `@stacksjs/browser` | [`stacks-browser`](../stacks-browser/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/browser/src/index.ts) | 11 |
|
|
23
23
|
| `@stacksjs/browser-extension` | [`stacks-browser-extension`](../stacks-browser-extension/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/browser-extension/src/index.ts) | 9 |
|
|
24
|
-
| `@stacksjs/buddy` | [`stacks-buddy`](../stacks-buddy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/index.ts) |
|
|
24
|
+
| `@stacksjs/buddy` | [`stacks-buddy`](../stacks-buddy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/index.ts) | 225 |
|
|
25
25
|
| `@stacksjs/build` | [`stacks-build`](../stacks-build/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/build/src/index.ts) | 7 |
|
|
26
26
|
| `@stacksjs/cache` | [`stacks-cache`](../stacks-cache/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cache/src/index.ts) | 24 |
|
|
27
27
|
| `@stacksjs/calendar-api` | [`stacks-calendar`](../stacks-calendar/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/calendar-api/src/index.ts) | 5 |
|
|
@@ -33,13 +33,13 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
33
33
|
| `@stacksjs/collections` | [`stacks-collections`](../stacks-collections/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/collections/src/index.ts) | 2 |
|
|
34
34
|
| `@stacksjs/commerce` | [`stacks-commerce`](../stacks-commerce/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/commerce/src/index.ts) | 16 |
|
|
35
35
|
| `@stacksjs/composables` | [`stacks-composables`](../stacks-composables/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/composables/src/index.ts) | 18 |
|
|
36
|
-
| `@stacksjs/config` | [`stacks-config`](../stacks-config/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/index.ts) |
|
|
36
|
+
| `@stacksjs/config` | [`stacks-config`](../stacks-config/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/index.ts) | 19 |
|
|
37
37
|
| `@stacksjs/cron` | [`stacks-cron`](../stacks-cron/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/cron/src/index.ts) | 6 |
|
|
38
38
|
| `@stacksjs/database` | [`stacks-database`](../stacks-database/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/database/src/index.ts) | 152 |
|
|
39
39
|
| `@stacksjs/datetime` | [`stacks-datetime`](../stacks-datetime/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/datetime/src/index.ts) | 22 |
|
|
40
40
|
| `@stacksjs/defaults` | [`stacks-build`](../stacks-build/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/defaults/package.json) | 3 |
|
|
41
41
|
| `@stacksjs/deploy` | [`stacks-deploy`](../stacks-deploy/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/deploy/package.json) | 1 |
|
|
42
|
-
| `@stacksjs/desktop-build` | [`stacks-desktop`](../stacks-desktop/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/index.ts) |
|
|
42
|
+
| `@stacksjs/desktop-build` | [`stacks-desktop`](../stacks-desktop/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/index.ts) | 25 |
|
|
43
43
|
| `@stacksjs/development` | [`stacks-development`](../stacks-development/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/development/package.json) | 1 |
|
|
44
44
|
| `@stacksjs/dns` | [`stacks-dns`](../stacks-dns/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/dns/src/index.ts) | 4 |
|
|
45
45
|
| `@stacksjs/docs` | [`stacks-docs`](../stacks-docs/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/docs/src/index.ts) | 8 |
|
|
@@ -86,7 +86,7 @@ Browser runtime bindings are documented separately in `stacks-auto-imports`.
|
|
|
86
86
|
| `@stacksjs/skills` | [`stacks-skills`](../stacks-skills/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/skills/src/index.ts) | 1 |
|
|
87
87
|
| `@stacksjs/slug` | [`stacks-slug`](../stacks-slug/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/slug/src/index.ts) | 5 |
|
|
88
88
|
| `@stacksjs/sms` | [`stacks-sms`](../stacks-sms/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/sms/src/index.ts) | 7 |
|
|
89
|
-
| `@stacksjs/socials` | [`stacks-socials`](../stacks-socials/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/index.ts) |
|
|
89
|
+
| `@stacksjs/socials` | [`stacks-socials`](../stacks-socials/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/index.ts) | 23 |
|
|
90
90
|
| `@stacksjs/storage` | [`stacks-storage`](../stacks-storage/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/storage/src/index.ts) | 54 |
|
|
91
91
|
| `@stacksjs/strings` | [`stacks-strings`](../stacks-strings/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/strings/src/index.ts) | 12 |
|
|
92
92
|
| `@stacksjs/support` | [`stacks-support`](../stacks-support/SKILL.md) | [entrypoint](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/support/src/index.ts) | 6 |
|
|
@@ -223,7 +223,7 @@ Read the entrypoint and package export map for re-exported or type-only surfaces
|
|
|
223
223
|
|
|
224
224
|
Local source modules: [src/commands/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/src/commands/index.ts).
|
|
225
225
|
|
|
226
|
-
Evidence directory: [
|
|
226
|
+
Evidence directory: [225 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/buddy/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
227
227
|
|
|
228
228
|
### @stacksjs/build
|
|
229
229
|
|
|
@@ -337,11 +337,11 @@ Evidence directory: [18 retained tests](https://github.com/stacksjs/stacks/blob/
|
|
|
337
337
|
|
|
338
338
|
Guidance: [`stacks-config`](../stacks-config/SKILL.md). Source: [storage/framework/core/config/src/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/index.ts).
|
|
339
339
|
|
|
340
|
-
Declared runtime exports: `DEFAULT_VIEWS_ALWAYS`, `DEFAULT_VIEW_ROUTE_BUNDLES`, `DEFAULT_VIEW_TEMPLATES`, `FORM_FLASH_COOKIE`, `FORM_FLASH_MAX_BYTES`, `FORM_FLASH_SECONDS`, `FRAMEWORK_DEFAULTS`, `clearShownFormFlash`, `createRequestContext`, `disableFeature`, `enableFeature`, `enterRequestScope`, `expiredFormFlashCookie`, `feature`, `flashableField`, `flashableInput`, `formFlashCookie`, `installRequestContext`, `installRequestScope`, `listFeatures`, `openFormFlash`, `packageComponentRoots`, `packageJobRoots`, `packageMigrationRoots`, `packageModelRoots`, `packageViewRoots`, `parseCookieHeader`, `reportConfigIssues`, `resetFeature`, `resolveViewPatterns`, `scopeStxServeContext`, `scopedRequestSnapshot`, `sealFormFlash`, `useRequestEvent`, `validateConfig`, `withheldDefaultViews`.
|
|
340
|
+
Declared runtime exports: `DEFAULT_VIEWS_ALWAYS`, `DEFAULT_VIEW_ROUTE_BUNDLES`, `DEFAULT_VIEW_TEMPLATES`, `FORM_FLASH_COOKIE`, `FORM_FLASH_MAX_BYTES`, `FORM_FLASH_SECONDS`, `FRAMEWORK_DEFAULTS`, `clearShownFormFlash`, `configSource`, `createRequestContext`, `describeConfigSource`, `disableFeature`, `enableFeature`, `enterRequestScope`, `expiredFormFlashCookie`, `feature`, `flashableField`, `flashableInput`, `formFlashCookie`, `installRequestContext`, `installRequestScope`, `listFeatures`, `openFormFlash`, `packageComponentRoots`, `packageJobRoots`, `packageMigrationRoots`, `packageModelRoots`, `packageViewRoots`, `parseCookieHeader`, `registerBundledConfig`, `reportConfigIssues`, `resetFeature`, `resolveViewPatterns`, `scopeStxServeContext`, `scopedRequestSnapshot`, `sealFormFlash`, `settledConfigSource`, `useRequestEvent`, `userConfigFileNames`, `validateConfig`, `withheldDefaultViews`.
|
|
341
341
|
|
|
342
|
-
Local source modules: [src/capabilities.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/capabilities.ts), [src/config.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/config.ts), [src/defaults.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/defaults.ts), [src/discovered-resources.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/discovered-resources.ts), [src/features.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/features.ts), [src/form-flash.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/form-flash.ts), [src/request-context.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/request-context.ts), [src/validators.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/validators.ts), [src/views.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/views.ts).
|
|
342
|
+
Local source modules: [src/capabilities.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/capabilities.ts), [src/config.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/config.ts), [src/defaults.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/defaults.ts), [src/discovered-resources.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/discovered-resources.ts), [src/features.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/features.ts), [src/form-flash.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/form-flash.ts), [src/request-context.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/request-context.ts), [src/sources.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/sources.ts), [src/validators.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/validators.ts), [src/views.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/src/views.ts).
|
|
343
343
|
|
|
344
|
-
Evidence directory: [
|
|
344
|
+
Evidence directory: [19 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/config/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
345
345
|
|
|
346
346
|
### @stacksjs/cron
|
|
347
347
|
|
|
@@ -397,7 +397,7 @@ Declared runtime exports: `BUN_EXECUTABLE_MARKER`, `RESERVED_PLIST_KEYS`, `USERL
|
|
|
397
397
|
|
|
398
398
|
Local source modules: [src/agent-launcher.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/agent-launcher.ts), [src/agent.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/agent.ts), [src/craft-runtime.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/craft-runtime.ts), [src/invites.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/invites.ts), [src/macos-app.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/macos-app.ts), [src/macos-bundle.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/macos-bundle.ts), [src/macos-release.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/macos-release.ts), [src/support.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/support.ts), [src/update-feed.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/update-feed.ts), [src/update-install.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/update-install.ts), [src/update-signing.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/update-signing.ts), [src/updater.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/updater.ts), [src/webview-agent.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/webview-agent.ts), [src/webview-app.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/webview-app.ts), [src/webview-build-record.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/webview-build-record.ts), [src/webview-launcher.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/src/webview-launcher.ts).
|
|
399
399
|
|
|
400
|
-
Evidence directory: [
|
|
400
|
+
Evidence directory: [25 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/desktop/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
401
401
|
|
|
402
402
|
### @stacksjs/development
|
|
403
403
|
|
|
@@ -847,9 +847,9 @@ Guidance: [`stacks-socials`](../stacks-socials/SKILL.md). Source: [storage/frame
|
|
|
847
847
|
|
|
848
848
|
Read the entrypoint and package export map for re-exported or type-only surfaces.
|
|
849
849
|
|
|
850
|
-
Local source modules: [src/abstract.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/abstract.ts), [src/authorize.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/authorize.ts), [src/drivers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/drivers/index.ts), [src/exceptions.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/exceptions.ts), [src/flows.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/flows.ts), [src/handoff.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/handoff.ts), [src/identities.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/identities.ts), [src/media.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/media.ts), [src/meta-graph.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/meta-graph.ts), [src/publish-errors.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/publish-errors.ts), [src/publish.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/publish.ts), [src/registry.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/registry.ts), [src/text.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/text.ts), [src/token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/token.ts), [src/types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/types.ts).
|
|
850
|
+
Local source modules: [src/abstract.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/abstract.ts), [src/authorize.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/authorize.ts), [src/drivers/index.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/drivers/index.ts), [src/errors.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/errors.ts), [src/exceptions.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/exceptions.ts), [src/flows.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/flows.ts), [src/handoff.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/handoff.ts), [src/identities.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/identities.ts), [src/media.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/media.ts), [src/meta-graph.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/meta-graph.ts), [src/publish-errors.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/publish-errors.ts), [src/publish.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/publish.ts), [src/registry.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/registry.ts), [src/text.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/text.ts), [src/token.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/token.ts), [src/types.ts](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/src/types.ts).
|
|
851
851
|
|
|
852
|
-
Evidence directory: [
|
|
852
|
+
Evidence directory: [23 retained tests](https://github.com/stacksjs/stacks/blob/main/storage/framework/core/socials/tests). These files are evidence pointers, not a claim that all tests were run for this catalog.
|
|
853
853
|
|
|
854
854
|
### @stacksjs/storage
|
|
855
855
|
|
|
@@ -149,6 +149,30 @@ A driver error's isAuthError is narrow; classifySocialError in
|
|
|
149
149
|
publish-errors.ts sorts any failure by status and body, and only `expired`
|
|
150
150
|
means the account must sign in again (a duplicate post on X is a 403).
|
|
151
151
|
|
|
152
|
+
Every driver error (BlueskyApiError, TwitterApiError, ...) is a SocialApiError
|
|
153
|
+
from errors.ts: `network`, `status`, the raw `body`, `kind` (the
|
|
154
|
+
classification), `reason` (the network's own sentence) and `retryAfterMs`. Its
|
|
155
|
+
message is the network's reason or the status text, never the raw body.
|
|
156
|
+
`retryAfterMs` reads Retry-After on any answer and, on a rate limit, X's
|
|
157
|
+
`x-rate-limit-reset`, Bluesky's `ratelimit-reset`, Mastodon's
|
|
158
|
+
`x-ratelimit-reset` and Meta's `estimated_time_to_regain_access`. Meta answers
|
|
159
|
+
a rate limit with a 400 ("(#4) Application request limit reached"), which still
|
|
160
|
+
classifies as `rate-limited`.
|
|
161
|
+
|
|
162
|
+
Engagement is a separate capability, like deletion: `supportsMetrics(driver)`,
|
|
163
|
+
then `driver.metrics(identity, uris)` with any number of `PublishedPost.uri`s,
|
|
164
|
+
answering `PostMetrics` (`likes`, `reposts`, `replies`, `quotes`, `views`,
|
|
165
|
+
`shares`). A count the network does not report is absent, not zero, and a post
|
|
166
|
+
that is gone is left out. Bluesky batches 25 a request (no views). Mastodon
|
|
167
|
+
batches 40 with `GET /api/v1/statuses?id[]=` and falls back to one status at a
|
|
168
|
+
time before 4.3 (no views; quotes from 4.5). Threads asks one post at a time
|
|
169
|
+
(`/{id}/insights`, the threads_manage_insights permission). Instagram asks one
|
|
170
|
+
post at a time too (`/{id}/insights`, instagram_manage_insights) and adds
|
|
171
|
+
`reach` and `saves`. LinkedIn batches 20 through Social Metadata: `likes` is
|
|
172
|
+
every reaction together, and it needs r_organization_social_feed for a Page
|
|
173
|
+
(r_member_social_feed for a member, granted to select developers only). X has
|
|
174
|
+
no metrics driver; its counts come with the session driver (#3372).
|
|
175
|
+
|
|
152
176
|
## Authorization and operational limits
|
|
153
177
|
|
|
154
178
|
The native terminal consent helper in authorize.ts currently supports X only.
|
|
@@ -6,7 +6,7 @@ import { safeGet } from '../../../../resources/functions/dashboard/data'
|
|
|
6
6
|
import { resolveDashboardModel } from '../../../../resources/functions/dashboard/model-access'
|
|
7
7
|
import { dashboardOperationalError } from '../dashboard-response'
|
|
8
8
|
import { modelActionApplies, modelActionOutcome, modelActions } from './model-actions'
|
|
9
|
-
import { humanizeIdentifier, isErasureSubject, isValidModelSlug, modelSchemaColumns,
|
|
9
|
+
import { humanizeIdentifier, isErasureSubject, isValidModelSlug, modelSchemaColumns, parseRowKey, slugToPascal } from './model-write'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* `POST /api/dashboard/models/{dashboardModel}/{id}/actions/{dashboardAction}`.
|
|
@@ -34,18 +34,19 @@ export default new Action({
|
|
|
34
34
|
const slug = String(request.getParam('dashboardModel') ?? '')
|
|
35
35
|
if (!isValidModelSlug(slug))
|
|
36
36
|
return response.json({ message: 'Model slug must be lowercase kebab-case.' }, 400)
|
|
37
|
-
const id = parseRowId(request.getParam('id'))
|
|
38
|
-
if (id === null)
|
|
39
|
-
return response.json({ message: 'A numeric row id is required.' }, 400)
|
|
40
|
-
|
|
41
37
|
const modelName = slugToPascal(slug)
|
|
42
38
|
const name = String(request.getParam('dashboardAction') ?? '')
|
|
43
39
|
let Model: any
|
|
44
40
|
let row: unknown
|
|
41
|
+
let id: string | number | null = null
|
|
45
42
|
try {
|
|
46
43
|
Model = await resolveDashboardModel(modelName)
|
|
47
44
|
if (!Model || typeof Model.find !== 'function')
|
|
48
45
|
return response.json({ message: `No ORM model named ${modelName}.` }, 404)
|
|
46
|
+
// The model's own key: a number, or the value of one it declares (stacksjs/stacks#3350).
|
|
47
|
+
id = parseRowKey(Model, request.getParam('id'))
|
|
48
|
+
if (id === null)
|
|
49
|
+
return response.json({ message: Model.autoIncrement === false ? 'A row key is required.' : 'A numeric row id is required.' }, 400)
|
|
49
50
|
row = await Model.find(id)
|
|
50
51
|
}
|
|
51
52
|
catch (error) {
|
|
@@ -2,7 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
|
|
|
2
2
|
import { Action } from '@stacksjs/actions/runtime'
|
|
3
3
|
import { response } from '@stacksjs/router'
|
|
4
4
|
import { destroyModelRow, requestAccountId, rowRefusalResponse } from './model-row-writes'
|
|
5
|
-
import {
|
|
5
|
+
import { parseRowKey, resolveWritableModel } from './model-write'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* `DELETE /api/dashboard/models/{slug}/{id}`.
|
|
@@ -22,9 +22,10 @@ export default new Action({
|
|
|
22
22
|
if ('error' in resolved)
|
|
23
23
|
return response.json({ message: resolved.error }, resolved.status)
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
// The model's own key: a number, or the value of one it declares (stacksjs/stacks#3350).
|
|
26
|
+
const id = parseRowKey(resolved.Model, request.getParam('id'))
|
|
26
27
|
if (id === null)
|
|
27
|
-
return response.json({ message: 'A numeric row id is required.' }, 400)
|
|
28
|
+
return response.json({ message: resolved.Model?.autoIncrement === false ? 'A row key is required.' : 'A numeric row id is required.' }, 400)
|
|
28
29
|
|
|
29
30
|
const result = await destroyModelRow(resolved, id, await requestAccountId(request))
|
|
30
31
|
return result.ok ? { ok: true, id, anonymized: result.anonymized } : rowRefusalResponse(result)
|
|
@@ -6,7 +6,7 @@ import { resolveDashboardModel } from '../../../../resources/functions/dashboard
|
|
|
6
6
|
import { dashboardOperationalError } from '../dashboard-response'
|
|
7
7
|
import { optionsFromRows } from './model-options'
|
|
8
8
|
import { modelHintColumn, modelLabelColumn } from './model-relations'
|
|
9
|
-
import { humanizeIdentifier, isValidModelSlug, slugToPascal } from './model-write'
|
|
9
|
+
import { humanizeIdentifier, isValidModelSlug, modelRowKey, slugToPascal } from './model-write'
|
|
10
10
|
|
|
11
11
|
/** How many records a search offers. A picker is for finding one, not browsing. */
|
|
12
12
|
const OPTION_LIMIT = 20
|
|
@@ -18,10 +18,12 @@ interface OptionsInput {
|
|
|
18
18
|
ids?: unknown
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
/** The ids asked about: numbers, or for a model keyed by a string it declares, those strings. */
|
|
22
|
+
function parseIds(raw: unknown, keyedByString = false): Array<number | string> {
|
|
22
23
|
const parts = Array.isArray(raw) ? raw : String(raw ?? '').split(',')
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
if (keyedByString)
|
|
25
|
+
return [...new Set(parts.map(part => String(part).trim()).filter(id => id.length > 0 && id.length <= 512))].slice(0, ID_LIMIT)
|
|
26
|
+
return [...new Set(parts.map(part => Number.parseInt(String(part).trim(), 10)).filter(id => Number.isSafeInteger(id) && id > 0))].slice(0, ID_LIMIT)
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
/**
|
|
@@ -58,7 +60,9 @@ export default new Action({
|
|
|
58
60
|
|
|
59
61
|
const input = request.all()
|
|
60
62
|
const q = String(input.q ?? '').trim().slice(0, 100)
|
|
61
|
-
const
|
|
63
|
+
const keyedByString = Model.autoIncrement === false
|
|
64
|
+
const key = modelRowKey(Model)
|
|
65
|
+
const ids = parseIds(input.ids, keyedByString)
|
|
62
66
|
const labelColumn = modelLabelColumn(Model)
|
|
63
67
|
const hintColumn = modelHintColumn(Model)
|
|
64
68
|
const modelLabel = humanizeIdentifier(modelName)
|
|
@@ -68,7 +72,7 @@ export default new Action({
|
|
|
68
72
|
// own query, with raw conditions inside the group.
|
|
69
73
|
let query = Model.query() as any
|
|
70
74
|
if (ids.length > 0) {
|
|
71
|
-
query = query.whereIn(
|
|
75
|
+
query = query.whereIn(key, ids)
|
|
72
76
|
}
|
|
73
77
|
else if (q) {
|
|
74
78
|
const numeric = /^\d+$/.test(q) ? Number(q) : null
|
|
@@ -77,8 +81,11 @@ export default new Action({
|
|
|
77
81
|
// Lowercased on both sides: a model query's LIKE is case-sensitive
|
|
78
82
|
// on PostgreSQL (stacksjs/stacks#3202).
|
|
79
83
|
.map(column => [`LOWER(${column}) LIKE LOWER(?)`, `%${q}%`])
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
// The record's own key, typed in: an id, or a declared key's value.
|
|
85
|
+
if (keyedByString)
|
|
86
|
+
conditions.push([`${key} = ?`, q])
|
|
87
|
+
else if (numeric !== null)
|
|
88
|
+
conditions.push([`${key} = ?`, numeric])
|
|
82
89
|
// Nothing to search by name and the term is not an id: no match, not everything.
|
|
83
90
|
if (conditions.length === 0)
|
|
84
91
|
return { options: [], modelLabel, labelColumn }
|
|
@@ -89,7 +96,7 @@ export default new Action({
|
|
|
89
96
|
})
|
|
90
97
|
}
|
|
91
98
|
|
|
92
|
-
const rows = await query.orderBy(labelColumn ??
|
|
99
|
+
const rows = await query.orderBy(labelColumn ?? key, 'asc').take(ids.length > 0 ? ID_LIMIT : OPTION_LIMIT).get() as any[]
|
|
93
100
|
const list = Array.isArray(rows) ? rows : []
|
|
94
101
|
|
|
95
102
|
const options: ModelOption[] = await optionsFromRows(Model, modelName, list)
|
|
@@ -4,7 +4,7 @@ import { response } from '@stacksjs/router'
|
|
|
4
4
|
import { resolveDashboardModel } from '../../../../resources/functions/dashboard/model-access'
|
|
5
5
|
import { dashboardOperationalError } from '../dashboard-response'
|
|
6
6
|
import { relatedPanels } from './model-related'
|
|
7
|
-
import { isValidModelSlug,
|
|
7
|
+
import { isValidModelSlug, parseRowKey, slugToPascal } from './model-write'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* `GET /api/dashboard/models/{slug}/{id}/related`.
|
|
@@ -22,15 +22,15 @@ export default new Action({
|
|
|
22
22
|
const slug = String(request.getParam('slug') ?? '')
|
|
23
23
|
if (!isValidModelSlug(slug))
|
|
24
24
|
return response.json({ message: 'Model slug must be lowercase kebab-case.' }, 400)
|
|
25
|
-
const id = parseRowId(request.getParam('id'))
|
|
26
|
-
if (id === null)
|
|
27
|
-
return response.json({ message: 'A numeric row id is required.' }, 400)
|
|
28
|
-
|
|
29
25
|
const modelName = slugToPascal(slug)
|
|
30
26
|
try {
|
|
31
27
|
const Model = await resolveDashboardModel(modelName)
|
|
32
28
|
if (!Model || typeof Model.find !== 'function')
|
|
33
29
|
return response.json({ message: `No ORM model named ${modelName}.` }, 404)
|
|
30
|
+
// The model's own key: a number, or the value of one it declares (stacksjs/stacks#3350).
|
|
31
|
+
const id = parseRowKey(Model, request.getParam('id'))
|
|
32
|
+
if (id === null)
|
|
33
|
+
return response.json({ message: Model.autoIncrement === false ? 'A row key is required.' : 'A numeric row id is required.' }, 400)
|
|
34
34
|
if (!(await Model.find(id)))
|
|
35
35
|
return response.json({ message: `${modelName} ${id} not found.` }, 404)
|
|
36
36
|
return { panels: await relatedPanels(Model, modelName, id) }
|
|
@@ -10,7 +10,8 @@ import { hasRelations } from './model-relations'
|
|
|
10
10
|
import type { RowRefusal } from './model-row-writes'
|
|
11
11
|
import { destroyModelRow, formFields, requestAccountId, storeModelRow, updateModelRow } from './model-row-writes'
|
|
12
12
|
import type { ResolvedModel } from './model-write'
|
|
13
|
-
import {
|
|
13
|
+
import type { RowKey } from './model-write'
|
|
14
|
+
import { isValidModelSlug, parseRowKey, resolveWritableModel, rowKeyShape } from './model-write'
|
|
14
15
|
|
|
15
16
|
/** What one related panel is asked to change. */
|
|
16
17
|
interface PanelChanges {
|
|
@@ -18,8 +19,9 @@ interface PanelChanges {
|
|
|
18
19
|
slug: string
|
|
19
20
|
/** New rows. `key` is the form's own name for each, so a refusal can say which. */
|
|
20
21
|
create: Array<{ key: string, fields: Record<string, unknown> }>
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
/** Rows by key: a number, or the value of a key the related model declares. */
|
|
23
|
+
update: Array<{ id: RowKey, fields: Record<string, unknown> }>
|
|
24
|
+
destroy: RowKey[]
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
/** Where a save was refused: the record's own fields, or one row of one panel. */
|
|
@@ -40,10 +42,10 @@ interface PanelPlan {
|
|
|
40
42
|
interface SavedPanel {
|
|
41
43
|
slug: string
|
|
42
44
|
created: Array<{ key: string, id: unknown }>
|
|
43
|
-
updated:
|
|
44
|
-
destroyed:
|
|
45
|
+
updated: RowKey[]
|
|
46
|
+
destroyed: RowKey[]
|
|
45
47
|
/** Of the destroyed: kept, with their personal details removed. */
|
|
46
|
-
anonymized:
|
|
48
|
+
anonymized: RowKey[]
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/** Thrown inside the transaction to roll it back at the first refusal, carrying where it was. */
|
|
@@ -80,23 +82,25 @@ function readRelatedChanges(raw: unknown): PanelChanges[] | string {
|
|
|
80
82
|
return `Two new ${entry.slug} rows were sent as ${row.key}.`
|
|
81
83
|
create.push({ key: row.key, fields: row.fields })
|
|
82
84
|
}
|
|
85
|
+
// Checked for shape here; read against the related model's own key once
|
|
86
|
+
// its panel is planned (stacksjs/stacks#3350).
|
|
83
87
|
const update: PanelChanges['update'] = []
|
|
84
88
|
for (const row of Array.isArray(entry.update) ? entry.update : []) {
|
|
85
|
-
const id = isRecord(row) ?
|
|
89
|
+
const id = isRecord(row) ? rowKeyShape(row.id) : null
|
|
86
90
|
if (id === null || !isRecord(row.fields))
|
|
87
91
|
return `Each edited ${entry.slug} row needs its id and its fields.`
|
|
88
|
-
if (update.some(other => other.id === id))
|
|
92
|
+
if (update.some(other => String(other.id) === String(id)))
|
|
89
93
|
return `${entry.slug} ${id} was edited twice.`
|
|
90
94
|
update.push({ id, fields: row.fields })
|
|
91
95
|
}
|
|
92
|
-
const destroy:
|
|
96
|
+
const destroy: RowKey[] = []
|
|
93
97
|
for (const raw of Array.isArray(entry.destroy) ? entry.destroy : []) {
|
|
94
|
-
const id =
|
|
98
|
+
const id = rowKeyShape(raw)
|
|
95
99
|
if (id === null)
|
|
96
100
|
return `Each deleted ${entry.slug} row needs its id.`
|
|
97
|
-
if (update.some(row => row.id === id))
|
|
101
|
+
if (update.some(row => String(row.id) === String(id)))
|
|
98
102
|
return `${entry.slug} ${id} cannot be both edited and deleted.`
|
|
99
|
-
if (!destroy.
|
|
103
|
+
if (!destroy.some(other => String(other) === String(id)))
|
|
100
104
|
destroy.push(id)
|
|
101
105
|
}
|
|
102
106
|
panels.push({ slug: entry.slug, create, update, destroy })
|
|
@@ -158,10 +162,6 @@ export default new Action({
|
|
|
158
162
|
method: 'PATCH',
|
|
159
163
|
apiResponse: true,
|
|
160
164
|
async handle(request: RequestInstance) {
|
|
161
|
-
const id = parseRowId(request.getParam('id'))
|
|
162
|
-
if (id === null)
|
|
163
|
-
return response.json({ message: 'A numeric row id is required.' }, 400)
|
|
164
|
-
|
|
165
165
|
const input = request.all()
|
|
166
166
|
const fields = formFields(input.fields)
|
|
167
167
|
const related = readRelatedChanges(input.related)
|
|
@@ -176,6 +176,10 @@ export default new Action({
|
|
|
176
176
|
const resolved = await resolveWritableModel(request.getParam('slug'), editsRecord ? 'update' : undefined)
|
|
177
177
|
if ('error' in resolved)
|
|
178
178
|
return response.json({ message: resolved.error }, resolved.status)
|
|
179
|
+
// The record's own key: a number, or the value of one its model declares (stacksjs/stacks#3350).
|
|
180
|
+
const id = parseRowKey(resolved.Model, request.getParam('id'))
|
|
181
|
+
if (id === null)
|
|
182
|
+
return response.json({ message: resolved.Model?.autoIncrement === false ? 'A row key is required.' : 'A numeric row id is required.' }, 400)
|
|
179
183
|
|
|
180
184
|
try {
|
|
181
185
|
if (!(await resolved.Model.find(id)))
|
|
@@ -197,11 +201,26 @@ export default new Action({
|
|
|
197
201
|
const target = await resolveWritableModel(changes.slug)
|
|
198
202
|
if ('error' in target)
|
|
199
203
|
return response.json({ message: target.error, at: { operation: 'update', panel: changes.slug } }, target.status)
|
|
200
|
-
|
|
204
|
+
// Each row's key read the way its own model is keyed.
|
|
205
|
+
const update: PanelChanges['update'] = []
|
|
206
|
+
for (const row of changes.update) {
|
|
207
|
+
const key = parseRowKey(target.Model, row.id)
|
|
208
|
+
if (key === null)
|
|
209
|
+
return refusedBefore(422, `${panel.label} ${row.id} is not a ${panel.label.toLowerCase()} key.`, { operation: 'update', panel: changes.slug, row: String(row.id) })
|
|
210
|
+
update.push({ id: key, fields: row.fields })
|
|
211
|
+
}
|
|
212
|
+
const destroy: RowKey[] = []
|
|
213
|
+
for (const raw of changes.destroy) {
|
|
214
|
+
const key = parseRowKey(target.Model, raw)
|
|
215
|
+
if (key === null)
|
|
216
|
+
return refusedBefore(422, `${panel.label} ${raw} is not a ${panel.label.toLowerCase()} key.`, { operation: 'destroy', panel: changes.slug, row: String(raw) })
|
|
217
|
+
destroy.push(key)
|
|
218
|
+
}
|
|
219
|
+
plans.push({ changes: { ...changes, update, destroy }, panel, target })
|
|
201
220
|
}
|
|
202
221
|
|
|
203
222
|
const viewer = await requestAccountId(request)
|
|
204
|
-
const own = async (plan: PanelPlan, rowId:
|
|
223
|
+
const own = async (plan: PanelPlan, rowId: RowKey, operation: SaveLocation['operation']): Promise<void> => {
|
|
205
224
|
const row = await plan.target.Model.find(rowId)
|
|
206
225
|
if (!row || String(safeGet(row, plan.panel.foreignKey, '')) !== String(id))
|
|
207
226
|
throw new SaveStopped(refusal(404, `${plan.panel.label} ${rowId} is not one of this ${resolved.modelName.toLowerCase()}'s.`), { operation, panel: plan.changes.slug, row: String(rowId) })
|
|
@@ -362,9 +362,8 @@ export default new Action({
|
|
|
362
362
|
return dashboardOperationalError(error, `${modelName} records could not be loaded.`, 'ModelShowAction.query')
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
-
//
|
|
366
|
-
|
|
367
|
-
response.writeCapabilities = modelWriteCapabilities(Model)
|
|
365
|
+
// Every dashboard route takes the model's own key (stacksjs/stacks#3350).
|
|
366
|
+
response.writeCapabilities = modelWriteCapabilities(Model)
|
|
368
367
|
response.writable = Object.values(response.writeCapabilities).some(Boolean)
|
|
369
368
|
// A relation is only worth a picker when the dashboard can list the model
|
|
370
369
|
// it points at. One whose feature is off, or that is kept out of the
|
|
@@ -426,7 +425,7 @@ export default new Action({
|
|
|
426
425
|
// The model's own actions, and the rows each is for. Decided here, where
|
|
427
426
|
// the whole row is, so the page never has to be sent the rule. An erased
|
|
428
427
|
// account is offered none: there is nobody left to act on.
|
|
429
|
-
const actions =
|
|
428
|
+
const actions = await modelActions(Model, modelName)
|
|
430
429
|
response.actions = actions.map(publicModelAction)
|
|
431
430
|
const erased = new Set((response.anonymizedIds ?? []).map(String))
|
|
432
431
|
for (const [index, row] of stored.entries()) {
|
|
@@ -2,7 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
|
|
|
2
2
|
import { Action } from '@stacksjs/actions/runtime'
|
|
3
3
|
import { response } from '@stacksjs/router'
|
|
4
4
|
import { formFields, rowRefusalResponse, updateModelRow } from './model-row-writes'
|
|
5
|
-
import {
|
|
5
|
+
import { parseRowKey, resolveWritableModel } from './model-write'
|
|
6
6
|
|
|
7
7
|
interface ModelWriteInput {
|
|
8
8
|
fields?: unknown
|
|
@@ -26,9 +26,10 @@ export default new Action({
|
|
|
26
26
|
if ('error' in resolved)
|
|
27
27
|
return response.json({ message: resolved.error }, resolved.status)
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
// The model's own key: a number, or the value of one it declares (stacksjs/stacks#3350).
|
|
30
|
+
const id = parseRowKey(resolved.Model, request.getParam('id'))
|
|
30
31
|
if (id === null)
|
|
31
|
-
return response.json({ message: 'A numeric row id is required.' }, 400)
|
|
32
|
+
return response.json({ message: resolved.Model?.autoIncrement === false ? 'A row key is required.' : 'A numeric row id is required.' }, 400)
|
|
32
33
|
|
|
33
34
|
// Nested under `fields`, apart from the URL's params (see `formFields`).
|
|
34
35
|
const result = await updateModelRow(resolved, id, formFields(request.all().fields))
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* sign-ins revoked, and keeps the records that still refer to it.
|
|
18
18
|
*/
|
|
19
19
|
import { isForeignKeyViolation } from '@stacksjs/error-handling'
|
|
20
|
+
import type { RowKey } from './model-write'
|
|
20
21
|
import { isErasureSubject } from './model-write'
|
|
21
22
|
|
|
22
23
|
export interface ErasureOutcome {
|
|
@@ -41,7 +42,7 @@ export type DestroyModelRecordResult
|
|
|
41
42
|
| { ok: false, reason: 'failed', cause: unknown }
|
|
42
43
|
| { ok: false, reason: 'erasure-failed', cause: unknown }
|
|
43
44
|
|
|
44
|
-
export async function destroyModelRecord(id:
|
|
45
|
+
export async function destroyModelRecord(id: RowKey, dependencies: DestroyModelRecordDependencies): Promise<DestroyModelRecordResult> {
|
|
45
46
|
const { Model } = dependencies
|
|
46
47
|
try {
|
|
47
48
|
const row = await Model.find(id)
|
|
@@ -53,7 +54,8 @@ export async function destroyModelRecord(id: number, dependencies: DestroyModelR
|
|
|
53
54
|
catch (error) {
|
|
54
55
|
if (!isForeignKeyViolation(error))
|
|
55
56
|
return { ok: false, reason: 'failed', cause: error }
|
|
56
|
-
|
|
57
|
+
// Erasure is about the account model, which is keyed by number.
|
|
58
|
+
if (!isErasureSubject(Model) || typeof id !== 'number')
|
|
57
59
|
return { ok: false, reason: 'referenced' }
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -8,7 +8,7 @@ import { anonymizedRows } from '@stacksjs/orm'
|
|
|
8
8
|
import { safeGet } from '../../../../resources/functions/dashboard/data'
|
|
9
9
|
import { resolveDashboardModel } from '../../../../resources/functions/dashboard/model-access'
|
|
10
10
|
import { modelHintColumn, modelLabelColumn } from './model-relations'
|
|
11
|
-
import { humanizeIdentifier, isErasureSubject } from './model-write'
|
|
11
|
+
import { humanizeIdentifier, isErasureSubject, modelRowKey } from './model-write'
|
|
12
12
|
|
|
13
13
|
/** A model's rows as the options a picker lists: an id, a name, and a line that tells two apart. */
|
|
14
14
|
export async function optionsFromRows(Model: any, modelName: string, rows: unknown[]): Promise<ModelOption[]> {
|
|
@@ -21,8 +21,10 @@ export async function optionsFromRows(Model: any, modelName: string, rows: unkno
|
|
|
21
21
|
? await anonymizedRows(modelName, rows.map(row => ({ id: safeGet(row, 'id', 0), name: safeGet(row, 'name', null), email: safeGet(row, 'email', null), avatar: safeGet(row, 'avatar', null) }))).catch(() => [] as boolean[])
|
|
22
22
|
: []
|
|
23
23
|
|
|
24
|
+
// A record is offered by its own key: `id`, or the one its model declares.
|
|
25
|
+
const key = modelRowKey(Model)
|
|
24
26
|
return rows.map((row, index) => {
|
|
25
|
-
const id = safeGet(row,
|
|
27
|
+
const id = safeGet(row, key, 0) as number | string
|
|
26
28
|
if (erased[index] === true)
|
|
27
29
|
return { id, label: `Anonymized ${modelLabel.toLowerCase()}`, hint: `#${id}` }
|
|
28
30
|
const named = labelColumn ? String(safeGet(row, labelColumn, '') ?? '').trim() : ''
|
|
@@ -38,14 +40,17 @@ export async function optionsFromRows(Model: any, modelName: string, rows: unkno
|
|
|
38
40
|
*/
|
|
39
41
|
export async function recordNames(modelName: string, ids: Array<number | string>): Promise<Map<string, string>> {
|
|
40
42
|
const names = new Map<string, string>()
|
|
41
|
-
const wanted = [...new Set(ids.map(id => Number(id)).filter(id => Number.isSafeInteger(id) && id > 0))]
|
|
42
|
-
if (wanted.length === 0)
|
|
43
|
-
return names
|
|
44
43
|
try {
|
|
45
44
|
const Model = await resolveDashboardModel(modelName)
|
|
46
45
|
if (!Model || typeof Model.query !== 'function')
|
|
47
46
|
return names
|
|
48
|
-
|
|
47
|
+
// Keys as the model has them: numbers, or the strings it declares.
|
|
48
|
+
const wanted = Model.autoIncrement === false
|
|
49
|
+
? [...new Set(ids.map(id => String(id)).filter(id => id.length > 0 && id.length <= 512))]
|
|
50
|
+
: [...new Set(ids.map(id => Number(id)).filter(id => Number.isSafeInteger(id) && id > 0))]
|
|
51
|
+
if (wanted.length === 0)
|
|
52
|
+
return names
|
|
53
|
+
const rows = await Model.query().whereIn(modelRowKey(Model), wanted).get() as unknown[]
|
|
49
54
|
for (const option of await optionsFromRows(Model, modelName, Array.isArray(rows) ? rows : []))
|
|
50
55
|
names.set(String(option.id), option.label)
|
|
51
56
|
}
|
|
@@ -22,7 +22,7 @@ import { recordNames } from './model-options'
|
|
|
22
22
|
import { belongsToRelations, hasRelations, modelLabelColumn, pluralizeLabel, relatedForeignKey } from './model-relations'
|
|
23
23
|
import type { ModelFieldDisplay } from './model-fields'
|
|
24
24
|
import { modelFormFields } from './model-forms'
|
|
25
|
-
import { humanizeIdentifier, type ModelCreateField, modelColumnDisplay, modelColumnLabel, modelListColumns, modelSchemaColumns, modelWriteCapabilities } from './model-write'
|
|
25
|
+
import { humanizeIdentifier, type ModelCreateField, modelColumnDisplay, modelColumnLabel, modelListColumns, modelRowKey, modelSchemaColumns, modelWriteCapabilities, type RowKey } from './model-write'
|
|
26
26
|
|
|
27
27
|
/** How many of a panel's records the page shows before "View all". */
|
|
28
28
|
export const RELATED_PREVIEW = 5
|
|
@@ -150,7 +150,7 @@ export function relatedSummaryColumns(Related: any, foreignKey: string, reachabl
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
/** One panel's worth, or null when the related model cannot be listed for this record. */
|
|
153
|
-
export async function relatedPanel(parentName: string, parentId:
|
|
153
|
+
export async function relatedPanel(parentName: string, parentId: RowKey, relation: ModelHasRelation): Promise<RelatedPanel | null> {
|
|
154
154
|
const Related = await resolveDashboardModel(relation.model).catch(() => null)
|
|
155
155
|
if (!Related || typeof Related.query !== 'function')
|
|
156
156
|
return null
|
|
@@ -168,10 +168,13 @@ export async function relatedPanel(parentName: string, parentId: number, relatio
|
|
|
168
168
|
const columns = relatedSummaryColumns(Related, foreignKey, reachable)
|
|
169
169
|
const hidden = hiddenModelColumns(Related)
|
|
170
170
|
|
|
171
|
+
// A related model keyed by something other than `id` is keyed by that here
|
|
172
|
+
// too: a panel row's `id` is the key its edit and delete are sent with.
|
|
173
|
+
const rowKey = modelRowKey(Related)
|
|
171
174
|
const total = Number(await Related.query().where(foreignKey, parentId).count()) || 0
|
|
172
175
|
const found = total === 0
|
|
173
176
|
? []
|
|
174
|
-
: await Related.query().where(foreignKey, parentId).orderBy(
|
|
177
|
+
: await Related.query().where(foreignKey, parentId).orderBy(rowKey, 'desc').take(relation.kind === 'one' ? 1 : RELATED_PREVIEW).get() as unknown[]
|
|
175
178
|
const list = Array.isArray(found) ? found : []
|
|
176
179
|
|
|
177
180
|
// The records these rows point at, named in one lookup per model.
|
|
@@ -182,7 +185,7 @@ export async function relatedPanel(parentName: string, parentId: number, relatio
|
|
|
182
185
|
}
|
|
183
186
|
|
|
184
187
|
const rows = list.map((row) => {
|
|
185
|
-
const shown: Record<string, unknown> = { id: safeGet(row,
|
|
188
|
+
const shown: Record<string, unknown> = { id: safeGet(row, rowKey, 0) }
|
|
186
189
|
for (const column of columns) {
|
|
187
190
|
const stored = safeGet(row, column.key, null)
|
|
188
191
|
if (column.key === 'id')
|
|
@@ -211,7 +214,7 @@ export async function relatedPanel(parentName: string, parentId: number, relatio
|
|
|
211
214
|
const values: Record<string, Record<string, unknown>> = {}
|
|
212
215
|
if (capabilities.update) {
|
|
213
216
|
for (const row of list)
|
|
214
|
-
values[String(safeGet(row,
|
|
217
|
+
values[String(safeGet(row, rowKey, ''))] = Object.fromEntries(fields.map(entry => [snakeCase(entry.name), safeGet(row, snakeCase(entry.name), null)]))
|
|
215
218
|
}
|
|
216
219
|
return {
|
|
217
220
|
kind: relation.kind,
|
|
@@ -234,7 +237,7 @@ export async function relatedPanel(parentName: string, parentId: number, relatio
|
|
|
234
237
|
}
|
|
235
238
|
|
|
236
239
|
/** Every panel a record's page shows, in the order the model declares them. */
|
|
237
|
-
export async function relatedPanels(Model: any, parentName: string, parentId:
|
|
240
|
+
export async function relatedPanels(Model: any, parentName: string, parentId: RowKey): Promise<RelatedPanel[]> {
|
|
238
241
|
const panels: RelatedPanel[] = []
|
|
239
242
|
for (const relation of hasRelations(Model)) {
|
|
240
243
|
try {
|
|
@@ -17,8 +17,8 @@ import { dashboardOperationalError } from '../dashboard-response'
|
|
|
17
17
|
import { destroyModelRecord } from './model-destroy'
|
|
18
18
|
import { missingRelationErrors } from './model-relations'
|
|
19
19
|
import { planSwitches, requestedSwitches, storedSwitches } from './model-switches'
|
|
20
|
-
import type { ResolvedModel } from './model-write'
|
|
21
|
-
import { duplicateFieldErrors, humanizeIdentifier, isAccountModel, prepareModelFields } from './model-write'
|
|
20
|
+
import type { ResolvedModel, RowKey } from './model-write'
|
|
21
|
+
import { duplicateFieldErrors, humanizeIdentifier, isAccountModel, modelRowKey, prepareModelFields, stringKeyedRelations } from './model-write'
|
|
22
22
|
|
|
23
23
|
/** Why a row was not written: what the visitor is told, and for a failure, what went wrong. */
|
|
24
24
|
export interface RowRefusal {
|
|
@@ -78,7 +78,7 @@ export function formFields(raw: unknown): Record<string, unknown> {
|
|
|
78
78
|
|
|
79
79
|
/** Create one row. `fixed` are columns set by where it is created, not by the form: a related row's link back. */
|
|
80
80
|
export async function storeModelRow(resolved: ResolvedModel, body: Record<string, unknown>, fixed: Record<string, unknown> = {}): Promise<RowWrite<{ id: unknown }>> {
|
|
81
|
-
const { data, errors } = prepareModelFields(resolved.Model, body)
|
|
81
|
+
const { data, errors } = prepareModelFields(resolved.Model, body, false, await stringKeyedRelations(resolved.Model))
|
|
82
82
|
if (Object.keys(errors).length > 0)
|
|
83
83
|
return refused(422, 'Validation failed.', errors)
|
|
84
84
|
if (Object.keys(data).length === 0)
|
|
@@ -87,7 +87,8 @@ export async function storeModelRow(resolved: ResolvedModel, body: Record<string
|
|
|
87
87
|
const values = { ...toSnakeCaseKeys(data), ...fixed }
|
|
88
88
|
try {
|
|
89
89
|
const row = await resolved.Model.create(values)
|
|
90
|
-
|
|
90
|
+
const key = modelRowKey(resolved.Model)
|
|
91
|
+
return { ok: true, id: row?.[key] ?? row?.attributes?.[key] ?? null }
|
|
91
92
|
}
|
|
92
93
|
catch (error) {
|
|
93
94
|
return fieldRefusal(resolved, error, Object.keys(values))
|
|
@@ -96,8 +97,8 @@ export async function storeModelRow(resolved: ResolvedModel, body: Record<string
|
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
/** Edit one row with the fields that changed, and the switches a trait keeps for itself. */
|
|
99
|
-
export async function updateModelRow(resolved: ResolvedModel, id:
|
|
100
|
-
const prepared = prepareModelFields(resolved.Model, body, true)
|
|
100
|
+
export async function updateModelRow(resolved: ResolvedModel, id: RowKey, body: Record<string, unknown>): Promise<RowWrite<{ id: RowKey, changed: string[] }>> {
|
|
101
|
+
const prepared = prepareModelFields(resolved.Model, body, true, await stringKeyedRelations(resolved.Model))
|
|
101
102
|
if (Object.keys(prepared.errors).length > 0)
|
|
102
103
|
return refused(422, 'Validation failed.', prepared.errors)
|
|
103
104
|
const changes = toSnakeCaseKeys(prepared.data)
|
|
@@ -108,6 +109,9 @@ export async function updateModelRow(resolved: ResolvedModel, id: number, body:
|
|
|
108
109
|
return refused(422, 'Validation failed.', unreadable)
|
|
109
110
|
if (Object.keys(changes).length === 0 && asked.length === 0)
|
|
110
111
|
return refused(422, 'No writable fields in the request body.')
|
|
112
|
+
// A switch belongs to a trait of the account models, which are keyed by number.
|
|
113
|
+
if (asked.length > 0 && typeof id !== 'number')
|
|
114
|
+
return refused(422, `${resolved.modelName} has no switches to turn.`)
|
|
111
115
|
|
|
112
116
|
try {
|
|
113
117
|
const row = await resolved.Model.find(id)
|
|
@@ -115,13 +119,13 @@ export async function updateModelRow(resolved: ResolvedModel, id: number, body:
|
|
|
115
119
|
return refused(404, `${resolved.modelName} ${id} not found.`)
|
|
116
120
|
// Refused before anything is written: a switch that cannot be turned
|
|
117
121
|
// that way refuses the whole save, like any other field's rule.
|
|
118
|
-
const { turning, errors } = planSwitches(resolved.Model, asked, asked.length > 0 ? await storedSwitches(resolved.Model, id) : {})
|
|
122
|
+
const { turning, errors } = planSwitches(resolved.Model, asked, asked.length > 0 && typeof id === 'number' ? await storedSwitches(resolved.Model, id) : {})
|
|
119
123
|
if (Object.keys(errors).length > 0)
|
|
120
124
|
return refused(422, 'Validation failed.', errors)
|
|
121
125
|
if (Object.keys(changes).length > 0)
|
|
122
126
|
await resolved.Model.update(id, changes)
|
|
123
127
|
for (const request of turning)
|
|
124
|
-
await request.switch.set(id, request.on)
|
|
128
|
+
await request.switch.set(id as number, request.on)
|
|
125
129
|
return { ok: true, id, changed: [...Object.keys(changes), ...turning.map(request => request.switch.column)] }
|
|
126
130
|
}
|
|
127
131
|
catch (error) {
|
|
@@ -149,7 +153,7 @@ export async function requestAccountId(request: RequestInstance): Promise<number
|
|
|
149
153
|
* `./model-destroy`. `viewer` is the account making the request, which is
|
|
150
154
|
* not deleted from here.
|
|
151
155
|
*/
|
|
152
|
-
export async function destroyModelRow(resolved: ResolvedModel, id:
|
|
156
|
+
export async function destroyModelRow(resolved: ResolvedModel, id: RowKey, viewer: number | null): Promise<RowWrite<{ id: RowKey, anonymized: boolean }>> {
|
|
153
157
|
// Deleting the account you are signed in with ends your own access in the
|
|
154
158
|
// middle of using it, and for the last admin there is no way back in.
|
|
155
159
|
if (isAccountModel(resolved.Model) && viewer === id)
|
|
@@ -593,6 +593,8 @@ export function prepareModelFields(
|
|
|
593
593
|
Model: any,
|
|
594
594
|
body: Record<string, unknown>,
|
|
595
595
|
partial = false,
|
|
596
|
+
/** Relation fields whose model is keyed by a string it declares ({@link stringKeyedRelations}). */
|
|
597
|
+
stringKeyed: ReadonlySet<string> = new Set(),
|
|
596
598
|
): PreparedModelFields {
|
|
597
599
|
const data: Record<string, unknown> = {}
|
|
598
600
|
const errors: Record<string, string[]> = {}
|
|
@@ -609,7 +611,11 @@ export function prepareModelFields(
|
|
|
609
611
|
}
|
|
610
612
|
|
|
611
613
|
const rawValue = hasAttribute ? body[field.name] : body[column]
|
|
612
|
-
|
|
614
|
+
// A link to a record keyed by a string it declares keeps that string.
|
|
615
|
+
const keyedByString = field.type === 'relation' && stringKeyed.has(field.name)
|
|
616
|
+
const value = keyedByString
|
|
617
|
+
? (rawValue === '' || rawValue === null || rawValue === undefined ? null : String(rawValue))
|
|
618
|
+
: normalizeModelValue(field.type, rawValue, attributes[field.name]?.validation?.rule)
|
|
613
619
|
if ((value === '' || value === null || value === undefined) && field.required) {
|
|
614
620
|
errors[field.name] = [`${field.label} is required.`]
|
|
615
621
|
continue
|
|
@@ -621,8 +627,12 @@ export function prepareModelFields(
|
|
|
621
627
|
}
|
|
622
628
|
|
|
623
629
|
// An id is a whole number above zero, whatever else the field's own rule
|
|
624
|
-
// allows
|
|
625
|
-
|
|
630
|
+
// allows, unless the record it points at is keyed by a string (stacksjs/stacks#3350).
|
|
631
|
+
// Whether that record exists is the database's to say.
|
|
632
|
+
const validLink = keyedByString
|
|
633
|
+
? rowKeyShape(value) !== null
|
|
634
|
+
: typeof value === 'number' && Number.isSafeInteger(value) && value > 0
|
|
635
|
+
if (field.type === 'relation' && !validLink) {
|
|
626
636
|
errors[field.name] = [`${field.label} must be chosen from the list.`]
|
|
627
637
|
continue
|
|
628
638
|
}
|
|
@@ -685,6 +695,54 @@ export async function resolveWritableModel(slug: string, operation?: ModelWriteO
|
|
|
685
695
|
return { Model, modelName }
|
|
686
696
|
}
|
|
687
697
|
|
|
698
|
+
/** A row's key as a route names it: an auto-increment number, or a declared key's own value. */
|
|
699
|
+
export type RowKey = number | string
|
|
700
|
+
|
|
701
|
+
/** The column a model's rows are keyed by: its declared `primaryKey`, else `id`. */
|
|
702
|
+
export function modelRowKey(Model: any): string {
|
|
703
|
+
return snakeCase(String(Model?.primaryKey || 'id'))
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* The row key a dashboard route names, for this model (stacksjs/stacks#3350).
|
|
708
|
+
*
|
|
709
|
+
* An auto-incrementing key, `id` or a declared one, is a positive integer:
|
|
710
|
+
* Postgres will not compare an integer column with a string. A key the model
|
|
711
|
+
* declares with `autoIncrement: false` (`worker_id`, a slug, a UUID) is its
|
|
712
|
+
* value as given, up to 512 characters.
|
|
713
|
+
*/
|
|
714
|
+
export function parseRowKey(Model: any, raw: unknown): RowKey | null {
|
|
715
|
+
if (Model?.autoIncrement !== false)
|
|
716
|
+
return parseRowId(raw)
|
|
717
|
+
const value = String(raw ?? '')
|
|
718
|
+
return value.length > 0 && value.length <= 512 ? value : null
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* The relation fields of a model whose related model is keyed by a string it
|
|
723
|
+
* declares (`autoIncrement: false`): those links are that string, not a number.
|
|
724
|
+
*/
|
|
725
|
+
export async function stringKeyedRelations(Model: any): Promise<Set<string>> {
|
|
726
|
+
const keyed = new Set<string>()
|
|
727
|
+
for (const relation of belongsToRelations(Model)) {
|
|
728
|
+
const Related = await resolveDashboardModel(relation.model).catch(() => null)
|
|
729
|
+
if (Related?.autoIncrement === false)
|
|
730
|
+
keyed.add(relation.field)
|
|
731
|
+
}
|
|
732
|
+
return keyed
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
/**
|
|
736
|
+
* A row key's shape, before the model it belongs to is known: a positive
|
|
737
|
+
* integer, or a non-empty string of at most 512 characters. Read against the
|
|
738
|
+
* model with {@link parseRowKey} once it is.
|
|
739
|
+
*/
|
|
740
|
+
export function rowKeyShape(raw: unknown): RowKey | null {
|
|
741
|
+
if (typeof raw === 'number')
|
|
742
|
+
return Number.isInteger(raw) && raw > 0 ? raw : null
|
|
743
|
+
return typeof raw === 'string' && raw.length > 0 && raw.length <= 512 ? raw : null
|
|
744
|
+
}
|
|
745
|
+
|
|
688
746
|
export function parseRowId(raw: unknown): number | null {
|
|
689
747
|
const id = Number.parseInt(String(raw ?? ''), 10)
|
|
690
748
|
return Number.isFinite(id) && id > 0 ? id : null
|
package/ide/vscode/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"publisher": "Stacks",
|
|
3
3
|
"name": "vscode-stacks",
|
|
4
4
|
"displayName": "Stacks",
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.690",
|
|
6
6
|
"description": "Stacks, built into VS Code: stx templates, pickier linting and formatting, encrypted env files, the dev server preview and every buddy command. No other extensions required.",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"funding": "https://github.com/sponsors/chrisbbreuer",
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@stacksjs/defaults",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"sideEffects": false,
|
|
5
|
-
"version": "0.75.
|
|
5
|
+
"version": "0.75.690",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"@iconify-json/f7": "^1.2.2",
|
|
47
47
|
"@iconify-json/hugeicons": "^1.2.35",
|
|
48
48
|
"@stacksjs/desktop": "^0.2.938",
|
|
49
|
-
"@stacksjs/mobile": "0.75.
|
|
49
|
+
"@stacksjs/mobile": "0.75.690",
|
|
50
50
|
"@stacksjs/sanitizer": "^0.2.938",
|
|
51
51
|
"@stacksjs/stx": "^0.2.938",
|
|
52
|
-
"@stacksjs/strings": "0.75.
|
|
52
|
+
"@stacksjs/strings": "0.75.690",
|
|
53
53
|
"@xterm/addon-fit": "^0.11.0",
|
|
54
54
|
"@xterm/xterm": "^6.0.0",
|
|
55
55
|
"ts-qr-codes": "^0.1.8",
|
|
56
|
-
"@stacksjs/support": "0.75.
|
|
57
|
-
"@stacksjs/browser": "0.75.
|
|
56
|
+
"@stacksjs/support": "0.75.690",
|
|
57
|
+
"@stacksjs/browser": "0.75.690"
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -76,10 +76,7 @@ async function loadRecord(): Promise<void> {
|
|
|
76
76
|
// For a component the app placed on this page: it follows the record.
|
|
77
77
|
modelPageStore.showRecord(slug(), recordId(), loaded)
|
|
78
78
|
// Not awaited, and a page whose panels cannot be read is still the record's page.
|
|
79
|
-
|
|
80
|
-
void fetchModelRelated(slug(), recordId()).then(panels => related.set(panels)).catch(() => related.set([]))
|
|
81
|
-
else
|
|
82
|
-
related.set([])
|
|
79
|
+
void fetchModelRelated(slug(), recordId()).then(panels => related.set(panels)).catch(() => related.set([]))
|
|
83
80
|
}
|
|
84
81
|
catch (error) {
|
|
85
82
|
record.set(null)
|
package/routes/dashboard.ts
CHANGED
|
@@ -63,20 +63,8 @@ function guarded(prefix: string, base?: Parameters<typeof dashboardGroupMiddlewa
|
|
|
63
63
|
// Email
|
|
64
64
|
// ============================================================================
|
|
65
65
|
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
// without a CSRF token round-trip, and the abuse case (bots inflating
|
|
69
|
-
// the subscriber list) is better handled with the rate limiter — at
|
|
70
|
-
// the action layer — than with a token check the form can't satisfy.
|
|
71
|
-
route.post('/api/email/subscribe', 'Actions/SubscriberEmailAction').name('email.subscribe').skipCsrf()
|
|
72
|
-
// The button in the double opt-in email (lists with `double_opt_in` on).
|
|
73
|
-
route.get('/api/email/confirm', 'Actions/ConfirmSubscriptionAction').name('email.confirm')
|
|
74
|
-
route.get('/api/email/unsubscribe', 'Actions/UnsubscribeAction').name('email.unsubscribe')
|
|
75
|
-
// RFC 8058 one-click endpoint. Mailbox providers (Gmail, Yahoo, Outlook)
|
|
76
|
-
// POST here with body `List-Unsubscribe=One-Click` when the user clicks
|
|
77
|
-
// the inbox-native unsubscribe affordance — the request never carries a
|
|
78
|
-
// CSRF token because the mailbox provider isn't in our session, so skip.
|
|
79
|
-
route.post('/api/email/unsubscribe', 'Actions/UnsubscribeAction').name('email.unsubscribe.oneclick').skipCsrf()
|
|
66
|
+
// The newsletter signup, its double opt-in confirmation and its unsubscribe
|
|
67
|
+
// links are in routes/email.ts: they ship in every app, dashboard or not.
|
|
80
68
|
|
|
81
69
|
// Public contact form. CSRF skipped for the same reason as the
|
|
82
70
|
// subscribe endpoint — the form renders without JS — and the outbound
|
package/routes/email.ts
CHANGED
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
* - POST /webhooks/email/postmark — bounce/complaint events
|
|
8
8
|
* - POST /webhooks/email/ses — SES via SNS
|
|
9
9
|
* - POST /webhooks/email/sendgrid — event webhook
|
|
10
|
+
* - POST /api/email/subscribe — the public newsletter signup
|
|
11
|
+
* - GET /api/email/confirm — the double opt-in link
|
|
12
|
+
* - GET/POST /api/email/unsubscribe — a list membership's opt-out
|
|
10
13
|
*
|
|
11
14
|
* All routes are CSRF-exempt (they're called by external providers
|
|
12
15
|
* or anonymous users clicking unsubscribe links). User routes
|
|
@@ -136,3 +139,28 @@ route.post('/webhooks/email/sendgrid', async (req) => {
|
|
|
136
139
|
const result = await handleSendgridWebhook(rawBody, sig, ts, { publicKeyPem })
|
|
137
140
|
return Response.json(result.body, { status: result.status })
|
|
138
141
|
}).skipCsrf()
|
|
142
|
+
|
|
143
|
+
// ============================================================================
|
|
144
|
+
// Newsletter signup
|
|
145
|
+
// ============================================================================
|
|
146
|
+
//
|
|
147
|
+
// These lived in routes/dashboard.ts, so an app without the dashboard mounted
|
|
148
|
+
// the signup action (directly, or under its own path) but not the link in the
|
|
149
|
+
// double opt-in email or the unsubscribe link in the welcome email: the
|
|
150
|
+
// confirmation failed to send ("Route 'email.confirm' is not defined") and
|
|
151
|
+
// nobody could leave the list. They belong with the rest of the email routes.
|
|
152
|
+
|
|
153
|
+
// CSRF is skipped for the same reason the storefront cart routes skip
|
|
154
|
+
// it: the storefront's email-subscribe form is rendered in static HTML
|
|
155
|
+
// without a CSRF token round-trip, and the abuse case (bots inflating
|
|
156
|
+
// the subscriber list) is better handled with the rate limiter — at
|
|
157
|
+
// the action layer — than with a token check the form can't satisfy.
|
|
158
|
+
route.post('/api/email/subscribe', 'Actions/SubscriberEmailAction').name('email.subscribe').skipCsrf()
|
|
159
|
+
// The button in the double opt-in email (lists with `double_opt_in` on).
|
|
160
|
+
route.get('/api/email/confirm', 'Actions/ConfirmSubscriptionAction').name('email.confirm')
|
|
161
|
+
route.get('/api/email/unsubscribe', 'Actions/UnsubscribeAction').name('email.unsubscribe')
|
|
162
|
+
// RFC 8058 one-click endpoint. Mailbox providers (Gmail, Yahoo, Outlook)
|
|
163
|
+
// POST here with body `List-Unsubscribe=One-Click` when the user clicks
|
|
164
|
+
// the inbox-native unsubscribe affordance — the request never carries a
|
|
165
|
+
// CSRF token because the mailbox provider isn't in our session, so skip.
|
|
166
|
+
route.post('/api/email/unsubscribe', 'Actions/UnsubscribeAction').name('email.unsubscribe.oneclick').skipCsrf()
|
|
@@ -796,7 +796,9 @@ onDestroy(() => {
|
|
|
796
796
|
<template #footer>
|
|
797
797
|
<div class="px-3 py-2 text-neutral-600 text-xs dark:text-neutral-300" data-sidebar-order-controls data-dashboard-muted :data-sidebar-order-editing="sidebarReordering() ? 'true' : 'false'">
|
|
798
798
|
<p role="status" aria-live="polite" :text="sidebarOrderStatus.message"></p>
|
|
799
|
-
<Button :if="sidebarOrderStatus.ready" class="dashboard-sidebar-order-mode" variant="ghost" size="xs" @click="sidebarReordering.set(!sidebarReordering())">
|
|
799
|
+
<Button :if="sidebarOrderStatus.ready" class="dashboard-sidebar-order-mode" variant="ghost" size="xs" @click="sidebarReordering.set(!sidebarReordering())">
|
|
800
|
+
<span :text="sidebarReordering() ? 'Done reordering' : 'Reorder sidebar'">Reorder sidebar</span>
|
|
801
|
+
</Button>
|
|
800
802
|
<Button :if="!sidebarOrderStatus.ready" variant="ghost" size="xs" @click="sidebarOrder.load()">Retry loading order</Button>
|
|
801
803
|
<Button :if="sidebarOrderStatus.ready" variant="ghost" size="xs" :disabled="sidebarOrderStatus.saving" @click="sidebarOrder.reset()">Reset order</Button>
|
|
802
804
|
</div>
|