pinia-plugin-subscription 1.0.0-beta.2 → 1.0.0-beta.20
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/CHANGELOG.md +73 -12
- package/CONTRIBUTING.md +10 -1
- package/README.md +48 -293
- package/SECURITY.md +6 -6
- package/dist/chunks/setup-context-3G3Hy1ep.js +909 -0
- package/dist/dictionaries/plugin-subscription-event.d.ts +20 -0
- package/dist/{core/Store.d.ts → enhanced-store/EnhancedStore.d.ts} +24 -29
- package/dist/enhanced-store/define-a-store.d.ts +64 -0
- package/dist/enhanced-store/setup-context.d.ts +27 -0
- package/dist/events/EventsEmitter.d.ts +9 -0
- package/dist/events/EventsSubscriber.d.ts +32 -0
- package/dist/events/EventsSubscription.d.ts +13 -0
- package/dist/events/StoreEvent.d.ts +6 -0
- package/dist/events/StoresEventsSubscriptionsRegistry.d.ts +31 -0
- package/dist/events/event.d.ts +8 -0
- package/dist/factories/events-registry.d.ts +9 -0
- package/dist/factories/events-subscriber.d.ts +11 -0
- package/dist/factories/messenger-registry.d.ts +16 -0
- package/dist/factories/plugin-subscriber.d.ts +17 -0
- package/dist/helpers.js +204 -312
- package/dist/lib/helpers.d.ts +9 -0
- package/dist/lib/main.d.ts +3 -12
- package/dist/orchestration/ExecutionPolicy.d.ts +15 -0
- package/dist/orchestration/PluginOrchestrator.d.ts +41 -0
- package/dist/orchestration/SubscriberScheduler.d.ts +31 -0
- package/dist/pinia-plugin-subscription.js +31 -426
- package/dist/plugins/createPlugin.d.ts +3 -13
- package/dist/services/messenger.d.ts +28 -0
- package/dist/services/messengerProvider.d.ts +45 -0
- package/dist/store-hooks/StoreHooksBinder.d.ts +20 -0
- package/dist/store-hooks/StoreHooksRegistry.d.ts +34 -0
- package/dist/{core/PluginSubscriber.d.ts → subscribers/StoreSubscriber.d.ts} +39 -28
- package/dist/tracing/TraceGroupHelper.d.ts +27 -0
- package/dist/tracing/TraceableEmitter.d.ts +60 -0
- package/dist/tracing/TraceableEventsSubscriber.d.ts +21 -0
- package/dist/tracing/TraceableStoreEventsSubscriber.d.ts +16 -0
- package/dist/tracing/trace-groups.d.ts +9 -0
- package/dist/types/core.d.ts +12 -0
- package/dist/types/events.d.ts +24 -0
- package/dist/types/index.d.ts +8 -34
- package/dist/types/messenger.d.ts +20 -0
- package/dist/types/plugin.d.ts +39 -20
- package/dist/types/store.d.ts +1 -9
- package/dist/types/trace.d.ts +35 -75
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/events.d.ts +3 -0
- package/dist/utils/id.d.ts +20 -0
- package/dist/utils/store.d.ts +9 -93
- package/docs/authoring-plugins.md +330 -78
- package/docs/using-plugins.md +89 -53
- package/package.json +14 -8
- package/dist/chunks/constantes-CaTNAbzX.js +0 -261
- package/dist/chunks/constantes-CaTNAbzX.js.map +0 -1
- package/dist/core/PluginSubscription.d.ts +0 -92
- package/dist/core/RollbackStateSnapshotsHandler.d.ts +0 -65
- package/dist/factories/console-trace-listener.d.ts +0 -7
- package/dist/factories/state-snapshot.d.ts +0 -3
- package/dist/factories/trace-listener.d.ts +0 -16
- package/dist/factories/trace-registry.d.ts +0 -17
- package/dist/helpers/index.d.ts +0 -9
- package/dist/helpers.js.map +0 -1
- package/dist/pinia-plugin-subscription.js.map +0 -1
- package/dist/plugins/createHydrationPlugin.d.ts +0 -10
- package/dist/system/Tracer.d.ts +0 -20
- package/dist/system/log.d.ts +0 -35
- package/dist/tests/defineAStore.test-d.d.ts +0 -1
- package/dist/tests/storeOptionsExtensions.test-d.d.ts +0 -12
- package/dist/types/comparison.d.ts +0 -3
- package/dist/types/list.d.ts +0 -13
- package/dist/types/log.d.ts +0 -8
- package/dist/types/resourceId.d.ts +0 -4
- package/dist/utils/Performance.d.ts +0 -9
- package/dist/utils/constantes.d.ts +0 -1
- package/dist/utils/deep-clone.d.ts +0 -7
- package/dist/utils/defineStoreId.d.ts +0 -1
- package/dist/utils/object.d.ts +0 -4
- package/dist/utils/validation/object.d.ts +0 -9
package/CHANGELOG.md
CHANGED
|
@@ -7,38 +7,99 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Changed
|
|
11
|
+
- Refactored the `PluginOrchestrator` into focused collaborators: `ExecutionPolicy` and `SubscriberScheduler` in `src/orchestration/`, `StoreHooksRegistry` and `StoreHooksBinder` in `src/store-hooks/`, and `TraceGroupHelper` in `src/tracing/`; this keeps orchestration, per-store hooks, and tracing responsibilities separate without changing subscriber delivery behavior.
|
|
12
|
+
- Updated the public API names to match the reorganized implementation: import `StoreSubscriber`, `EnhancedStore`, and `PluginOrchestrator` from `pinia-plugin-subscription/helpers`, and use `StoreSubscriberInterface` from `pinia-plugin-subscription/types`.
|
|
13
|
+
|
|
10
14
|
### Added
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- Added
|
|
14
|
-
-
|
|
15
|
-
- Added `
|
|
16
|
-
-
|
|
15
|
+
- SSR demo subscribers are now class-based (`StoreSubscriber` + an `EnhancedStore` subclass) and emit traces through the tracer `PluginOrchestrator` provides (`this.trace()` / `this.traceError()`): hydration start/done, errors, and the `onMutation` trace group, all scoped to the store; the per-request tracer registry also listens on the server, so server traces print in the Node terminal and browser traces in the devtools console
|
|
16
|
+
- SSR demo shows a concrete case of environment-aware hydration: one store filled by a server-only subscriber (request data) and a client-only deferred subscriber (browser data), with a server/browser panel layout and a hydration timeline; the `Accept-Language` header is validated before being serialized
|
|
17
|
+
- Added a Vite SSR demo server (`npm run dev:ssr`) with per-request app/plugin instances, async server-side subscriber hydration, and Pinia state serialization for client hydration
|
|
18
|
+
- Demo: `defineAStoreCtx` enhanced-store example; the demo app now resolves the package to `src/` through Vite aliases (no build needed)
|
|
19
|
+
- Added `pinia-plugin-subscription` to the package `keywords`
|
|
20
|
+
- `traceGroups` glossary, exported from `pinia-plugin-subscription/helpers`, building the `groupId` emitted by `PluginOrchestrator` (`onActionAfter`, `onActionError`, `onMutation`, `reset`); documented in `packages/devtools/docs/tracing.md`
|
|
21
|
+
- `createPluginSubscriber(name, invoke, optionalProps?)` factory, exported from `pinia-plugin-subscription/helpers`, to build plain-object subscribers; documented in `docs/authoring-plugins.md` and used by the demo plugin
|
|
22
|
+
- Added a dedicated tracing guide, `packages/devtools/docs/tracing.md`; the README now only presents tracing and links to it
|
|
23
|
+
- Moved the API reference, import subpaths, development, `EnhancedStore` summary and testing sections from `README.md` to `docs/authoring-plugins.md`
|
|
24
|
+
- Added `trace()` and `traceError()` to `EnhancedStore` and `PluginOrchestrator`
|
|
25
|
+
- Added trace types: `TraceEvent`, `TraceEventMetadata`, `TraceHandler`, `TraceLevel`, `TraceListener`, `TraceListenerRemover` and `TracePayload`
|
|
17
26
|
- Added `check:leaks` script and `scripts/check-dist-leaks.mjs`, guarding published artifacts against non-peer dependency imports in `dist/` (`.js` and `.d.ts`)
|
|
18
27
|
- Added the leak guard to `npm run build` and to the CI workflow
|
|
19
28
|
- Added unit tests covering the tracing system and the leak detection logic
|
|
20
29
|
|
|
21
30
|
### Changed
|
|
31
|
+
- `StoreSubscriber` passes the shared event registry to its `EnhancedStore` instance; both can register event subscriptions.
|
|
32
|
+
- Subscribers now execute in ascending `execution.order` order (default `9`), preserving declaration order for equal priorities; `StoreSubscriber.tracer` exposes the tracer created for that subscriber and passes the same instance to its `EnhancedStore` factory.
|
|
33
|
+
- Trace groups follow the lifecycles of a store: `groupId` is now a `/` separated path (`<storeId>/plugin`, `<storeId>/onAction:<name>#<n>`, with `/after` and `/onError` sub-groups, `<storeId>/onMutation#<n>`, `<storeId>/reset#<n>`, `<storeId>/plugin/deferred:<subscriber>#<n>`). Every trace emitted for a store while a group is open, including those of subscribers and `Store` subclasses, joins the innermost one. `traceGroups` builders take the call counter; `TraceGroupId` is removed, and `groupId` is lifted from the payload to the event like `actionId`
|
|
34
|
+
- `storeMutationSubscription` now supports several subscribers per store, like `storeOnActionSubscription`: a single `$subscribe` is registered per store and dispatches to every callback. A failing callback is reported through `traceError` without blocking the others, subscriber names are tracked, and the hook is unsubscribed when the store is disposed
|
|
35
|
+
- `storeOnActionSubscription` now receives the Pinia plugin context; action trace labels include the invoked action name
|
|
36
|
+
- Subscribers deferred with `hydration: 'defer'` now run inside their own trace group (label `subscriber:deferred`, keyed by store scope), which stays open until their asynchronous `hydrate()` / `afterHydration()` settle, so their traces are no longer emitted outside any group once `plugin()` has closed its `context` group. A hydration that never settles can no longer buffer the store's traces forever: the group is force-closed after `deferredTraceGroupTimeout` ms (new option, default 2500) and a `subscriber:deferred:timeout` error is traced
|
|
22
37
|
- Moved the demo application from `src/demo/` to the repository-level `demo/` directory, separating example code from the library source and tracking the demo files in version control.
|
|
23
38
|
- Clarified that SSR tracing registries and plugin instances must be created per request, and added coverage for listener isolation between registries
|
|
24
|
-
- Replaced the `Debug` abstract class with composition: `
|
|
25
|
-
- `createPlugin()` accepts `PluginSubscriptionOptions`, including a `createTracer` factory to connect a tracer registry to plugin and store trace events
|
|
39
|
+
- Replaced the `Debug` abstract class with composition: `EnhancedStore` and `PluginOrchestrator` no longer extend it and now own a `Tracer`
|
|
26
40
|
- Trace errors with no matching listener, and failures in listener filters or handlers, are now reported with `console.error` instead of rethrowing the original error
|
|
27
|
-
- Deprecated `createHydrationPlugin()` in favor of `createPlugin()` with hydration options
|
|
28
41
|
- Trace payloads are now lazily resolved, so unobserved tracing no longer builds log arguments
|
|
29
|
-
- Internal events now derive namespaces from trace labels, with `
|
|
42
|
+
- Internal events now derive namespaces from trace labels, with `PluginOrchestrator` prefixed by default; store events carry `store.$id` as `scope`
|
|
30
43
|
- `Tracer` now delegates all output decisions to listeners and no longer owns a console or an enabled state
|
|
31
44
|
- Error events are delivered to matching listeners and reported with `console.error` when none match
|
|
32
45
|
- Store trace labels can include the store class name by default, and callers can override the event namespace
|
|
33
46
|
- Excluded `scripts/**` from coverage thresholds, as build tooling is not shipped to consumers
|
|
47
|
+
- `EnhancedStore`, `StoreSubscriber` and `PluginOrchestrator` share store-event emission and tracing helpers; `EnhancedStore` receives the shared event handler from its subscriber.
|
|
48
|
+
- `Tracer` listener matching no longer allocates intermediate arrays beyond the matched set, and duplicated unhandled-error reporting was factored out
|
|
49
|
+
- Devtools now recognizes the `pluginorchestrator` namespace emitted by `PluginOrchestrator` when including context events in filtered traces.
|
|
50
|
+
|
|
51
|
+
### Changed (breaking)
|
|
52
|
+
- **Breaking:** renamed the helper exports `PluginSubscriber`, `Store`, and `PluginSubscription` to `StoreSubscriber`, `EnhancedStore`, and `PluginOrchestrator`; the subscriber interface is now `StoreSubscriberInterface`. Update imports from the `helpers` and `types` subpaths.
|
|
53
|
+
- Action event consumers receive an event whose lazy payload is an object with named fields rather than positional callback arguments. See the [event registration guide](docs/authoring-plugins.md#store-event-registration).
|
|
54
|
+
- Registering multiple callbacks for the same event now keeps all callbacks rather than replacing the previous one.
|
|
55
|
+
- The second argument to a subscriber's `invoke()` is now an options object containing `createTracer` and `eventsRegistry`, rather than the tracer factory itself.
|
|
56
|
+
- Replace `PluginSubscriber.storeInstance` with `getStoreInstance(store)` so asynchronous hooks can retrieve the wrapper for their own Pinia store.
|
|
57
|
+
- Class-based subscribers now define a unique `_name` instead of passing a name to `super()`; `StoreSubscriber` takes only its instance factory. `EnhancedStore` subclasses use `_name` instead of `_className`. `trace()` and `traceError()` are protected, and subclasses configure label prefixes through `traceOptions.prefixLabelWithName` instead of `classNameAddedToTraceNamespace`.
|
|
58
|
+
- Removed `PluginSubscriberWithoutInstance`; use a plain-object subscriber or `StoreSubscriber` with an `EnhancedStore` wrapper.
|
|
59
|
+
- Move automatic and manual rollback, including their types, to `pinia-plugin-state-snapshots`; register its subscriber explicitly.
|
|
60
|
+
- Move `$reset` ownership and reset callback execution to the state-snapshots package; replace subscriber `resetStoreCallback` with `$onResetStore()`. Callbacks run after state restoration; `PluginOrchestrator` only orchestrates subscribers.
|
|
61
|
+
- Store-event subscriber failures no longer propagate to the emitter, and `shouldPropagateError` has been removed. Synchronous failures and async rejections are logged; async subscribers are not awaited.
|
|
62
|
+
- removed the built-in console output of traces (`createConsoleGroupTraceListener`, `ConsoleTraceGroupListener`, `TraceGroupListener`, `TraceListenerGroupBy`, the `groupBy` option of `addListener()`, and the internal console printers). Listeners now only forward events to their own `handler` (a no-op when omitted); `startGroup` / `closeGroup` only maintain the open-group stack that sets `groupId`. Fixed `tracerHandler.journal` not being exposed by the registry
|
|
63
|
+
- The tracing solution moved to the new `pinia-plugin-subscription-devtools` package (`packages/devtools/`, same repository). `pinia-plugin-subscription` now only emits trace events through the `Tracer` / `TracerHandler` contract exported from `pinia-plugin-subscription/types`; without a `tracerHandler` it emits nothing. The compressed package drops from about 117 kB to about 50 kB, and the new package weighs about 19 kB.
|
|
64
|
+
- `createTracerRegistry`, `Tracer` (class), `defaultRedactedKeys`, `stringifyTraceSnapshot`, `getTraceGroupName` and `mountTraceDevtools` are now exported by `pinia-plugin-subscription-devtools` instead of `pinia-plugin-subscription/helpers` and `pinia-plugin-subscription/devtools`. `traceGroups` stays in `pinia-plugin-subscription/helpers`.
|
|
65
|
+
- The `Tracer` export of `pinia-plugin-subscription/helpers` is now the `Tracer` interface of `pinia-plugin-subscription/types`.
|
|
66
|
+
- `TracerHandler.createTracer(source)` no longer takes options, and `TracerHandler` no longer exposes `journal`; the registry's handler of the devtools package does.
|
|
67
|
+
- Source maps are no longer published.
|
|
68
|
+
|
|
69
|
+
### Documentation
|
|
70
|
+
- Added `demo/README.md` mapping each use case to its demo files and docs; documented the `pinia-plugin-subscription` topic in the Ecosystem section
|
|
71
|
+
- Reference implementation section lists the demo files and what each one illustrates; README links the demo and the `pinia-plugin-subscription` topic
|
|
72
|
+
|
|
73
|
+
### Fixed
|
|
74
|
+
- Track subscriber delivery, deferred subscriptions, action callbacks, and cleanup per store instance, including stores with the same `$id`; generate distinct IDs for prototype property names.
|
|
75
|
+
- Correlate state snapshots with individual action invocations, clean them up on store disposal, and emit action completion events when actions actually settle.
|
|
76
|
+
- Publish workflow: `scripts/publish-unpublished.mjs` publishes each package (root, then workspaces) only when its `name@version` is not already on npm, so a re-run after a partial failure no longer fails on versions already published
|
|
77
|
+
- `defineAStoreSetup` now creates a separate setup context for each Pinia store instance, preventing enhanced-store extensions from being shared across SSR requests
|
|
78
|
+
- Demo plugin-added state now uses `Store.addToState()` so `pluginIsActive` is exposed and reactive on the Pinia store
|
|
79
|
+
- `defineAStoreCtx()` now types the inferred setup context's enhanced-store extensions as `unknown` instead of `AnyObject`; explicit types remain available through generics or `getEnhancedStore<T>()`
|
|
80
|
+
- Demo no longer depends on git-ignored `experiment/` files nor on `src/` imports, so it runs from a fresh clone; `codeError` now fails explicitly
|
|
81
|
+
- `onAction`, `after` and `onError` subscription callbacks may now be asynchronous: rejections are traced instead of becoming unhandled, and their trace groups are closed once all async callbacks have settled
|
|
82
|
+
- Group listener filters receive only trace metadata, redaction safely copies own `__proto__` keys, and registry group payload factories are skipped when no listeners are registered
|
|
83
|
+
- Subscriber, subscription, action and rollback tracking keys now encode store IDs and names without delimiter collisions; disposing a store removes only its own tracking entries
|
|
84
|
+
- Trace groups opened by `onAction`, `$subscribe` and `$reset` are now always closed (also when the action fails or a callback throws), so grouped events no longer stay buffered forever
|
|
85
|
+
- Listener definitions passed to `addListener()` are no longer mutated when their `filter` is an array of criteria
|
|
86
|
+
- `CustomConsole.rebuildArgs()` no longer returns `undefined` for unsupported argument types
|
|
87
|
+
- `clearTraceListeners()` now empties the shared listener list in place, so tracers created before the call stop delivering to cleared listeners and see listeners registered afterwards
|
|
34
88
|
|
|
35
89
|
### Removed
|
|
36
|
-
-
|
|
90
|
+
- Removed the internal `PluginConsole` singleton and the dead commented code of `system/log.ts`; `CustomConsole` stays exported from `helpers` for plugins not yet migrated to the tracer
|
|
91
|
+
- **Breaking:** removed `createHydrationPlugin()`; use `createPlugin(subscribers, options)` with the hydration and runtime options directly
|
|
92
|
+
- **Breaking:** removed `getExtendingStore()`; use `getEnhancedStore()` and `ctx.extensions.enhancedStore` instead. `getEnhancedStore()` no longer falls back to the deprecated `ctx.extensions.extending` property
|
|
93
|
+
- Removed the `itemState` export from `src/utils/store`
|
|
94
|
+
- **Breaking:** removed `debugLog()` and `logError()` from the former `Store` and `PluginSubscription` helpers — use `trace()` and `traceError()` instead (see the migration snippet in `packages/devtools/docs/tracing.md`)
|
|
37
95
|
- **Breaking:** removed the obsolete `debug` and custom-console arguments from `createPlugin()`, `PluginSubscription`, `PluginSubscriber`, `Store`, and `Store.customizeStore()`
|
|
38
96
|
- **Breaking:** removed the `debug` argument from subscriber `invoke()`, `hydrate()`, and `afterHydration()` hooks; tracing is now configured exclusively through listeners
|
|
39
97
|
- **Breaking:** removed the legacy `debug` and `console` accessors from `Store` and `PluginSubscription`
|
|
40
98
|
- Removed the internal `src/system/Debug.ts` abstract class (was never publicly exported)
|
|
41
99
|
- **Breaking:** replaced module-global trace-listener functions with methods on a `createTracerRegistry()` instance
|
|
100
|
+
- Removed Performance monitoring utilities
|
|
101
|
+
- The `devtools` option of `createPlugin()` and the `pinia-plugin-subscription/devtools` entry point; install `pinia-plugin-subscription-devtools` and use `createTraceDevtools()` with `tracerHandler: registry.tracerHandler`
|
|
102
|
+
- Types `TraceFilter`, `TraceJournal`, `TraceRegistry`, `TracerOptions`, `TracerRegistryOptions` and the other registry types from `pinia-plugin-subscription/types`; they are exported by `pinia-plugin-subscription-devtools`
|
|
42
103
|
|
|
43
104
|
## [0.2.1]
|
|
44
105
|
|
|
@@ -104,7 +165,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
104
165
|
### Added
|
|
105
166
|
- Added `execution` and `hydrationScheduler` support on `PluginSubscriber` / `PluginSubscriberInterface`.
|
|
106
167
|
- Added `createHydrationPlugin()` as the dedicated Nuxt / SSR hydration helper.
|
|
107
|
-
- Added `
|
|
168
|
+
- Added `PluginOrchestratorOptions` for hydration-specific runtime overrides without changing the default `createPlugin()` API.
|
|
108
169
|
- Added optional `hydrate()` and `afterHydration()` lifecycle hooks to the subscriber and base `Store` contract for SSR-safe initialization logic.
|
|
109
170
|
|
|
110
171
|
### Changed
|
package/CONTRIBUTING.md
CHANGED
|
@@ -23,6 +23,15 @@ Please be respectful and constructive in all interactions with other contributor
|
|
|
23
23
|
git checkout -b feature/your-feature-name
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
## Repository Layout
|
|
27
|
+
|
|
28
|
+
This repository is an npm workspace with two published packages:
|
|
29
|
+
|
|
30
|
+
- `pinia-plugin-subscription` (repository root, `src/`): the plugin. It only *emits* trace events through the `TracerHandler` contract (`src/types/trace.ts`) and must never import the devtools package.
|
|
31
|
+
- `pinia-plugin-subscription-devtools` (`packages/devtools/`): consumes trace events (registry, journal, redaction, in-page panel). It depends on the plugin through types only.
|
|
32
|
+
|
|
33
|
+
Core tests use the in-memory tracer in `src/tests/support/testTracer.ts`; end-to-end tracing tests live in `packages/devtools/src/tests/`.
|
|
34
|
+
|
|
26
35
|
## Development Workflow
|
|
27
36
|
|
|
28
37
|
### Running Tests
|
|
@@ -36,7 +45,7 @@ npm run coverage # Generate coverage report
|
|
|
36
45
|
### Building
|
|
37
46
|
|
|
38
47
|
```bash
|
|
39
|
-
npm run build # Run tests, build
|
|
48
|
+
npm run build # Run tests, then build and check both packages
|
|
40
49
|
```
|
|
41
50
|
|
|
42
51
|
### Preview Changes
|
package/README.md
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# pinia-plugin-subscription
|
|
2
2
|
|
|
3
|
-
Pinia plugin for Vue.js that helps building Pinia plugins by centralizing subscriber registration and providing
|
|
3
|
+
Pinia plugin for Vue.js that helps building Pinia plugins by centralizing subscriber registration and providing an `EnhancedStore` base class for store helpers.
|
|
4
4
|
|
|
5
5
|
This project provides:
|
|
6
6
|
- a lightweight mechanism to declare "subscribers" that are invoked when stores are registered or updated by Pinia;
|
|
7
|
-
-
|
|
7
|
+
- an `EnhancedStore` base class (helper wrapper) to ease interacting with Pinia stores from subscribers or other plugin code;
|
|
8
8
|
- an API to create a Pinia plugin from a list of subscribers;
|
|
9
|
-
-
|
|
10
|
-
- automatic state rollback on action failure via the `rollbackAfterFailure` store option and the `$rollbackAfterFailure` method.
|
|
9
|
+
- optional `$reset` support and state rollback through the separate [`pinia-plugin-state-snapshots`](packages/state-snapshots/) package.
|
|
11
10
|
|
|
12
|
-
Deferred subscribers attach their action and reset callbacks to their own store after hydration; disposing a store removes its callbacks.
|
|
11
|
+
Deferred subscribers attach their action and reset callbacks to their own store after hydration; disposing a store removes its callbacks.
|
|
12
|
+
If a snapshot cannot be created, the state-snapshots subscriber logs the error
|
|
13
|
+
and lets the action run without that rollback snapshot.
|
|
13
14
|
|
|
14
15
|
## Tested & maintained
|
|
15
16
|
|
|
@@ -33,8 +34,11 @@ The package serves two audiences:
|
|
|
33
34
|
|
|
34
35
|
| You want to… | Guide |
|
|
35
36
|
| --- | --- |
|
|
36
|
-
| Use a compatible plugin (e.g. `pinia-plugin-extending-store`, `pinia-plugin-persist-state`) or
|
|
37
|
-
| Build your own pinia plugin on top of `pinia-plugin-subscription` | [Plugin authoring guide](docs/authoring-plugins.md) |
|
|
37
|
+
| Use a compatible plugin (e.g. `pinia-plugin-extending-store`, `pinia-plugin-persist-state`, `pinia-plugin-state-snapshots`) or built-in store features (`defineAStore`, `$reset`) | [Using compatible plugins](docs/using-plugins.md) |
|
|
38
|
+
| Build your own pinia plugin on top of `pinia-plugin-subscription` (API reference, `EnhancedStore` class, import subpaths, development and testing) | [Plugin authoring guide](docs/authoring-plugins.md) |
|
|
39
|
+
| Debug stores and plugins with structured trace events | [Tracing](packages/devtools/docs/tracing.md) |
|
|
40
|
+
|
|
41
|
+
A runnable example lives in [`demo/`](demo/) (`npm run dev` for SPA mode or `npm run dev:ssr` for Vite SSR). The SSR example hydrates **one store from two environments**: a server-only subscriber loads request data (awaited before rendering and serializing Pinia state) and a client-only, deferred subscriber fills browser data after hydration, with a visual timeline; see the [reference implementation](docs/authoring-plugins.md#reference-implementation). Plugins built on this package are discoverable through the [`pinia-plugin-subscription` GitHub topic](https://github.com/topics/pinia-plugin-subscription).
|
|
38
42
|
|
|
39
43
|
## Installation
|
|
40
44
|
|
|
@@ -60,311 +64,62 @@ app.use(pinia)
|
|
|
60
64
|
app.mount('#app')
|
|
61
65
|
```
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
## Usage — Examples
|
|
66
|
-
|
|
67
|
-
**1) Subscriber using a `Store` subclass:**
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
import PluginSubscriber from 'pinia-plugin-subscription'
|
|
71
|
-
import { Store } from 'pinia-plugin-subscription'
|
|
72
|
-
|
|
73
|
-
class MyPlugin extends Store {
|
|
74
|
-
protected override _className: string = 'MyPlugin'
|
|
75
|
-
protected static override _requiredKeys?: string[] | undefined = ['my-plugin-option']
|
|
76
|
-
|
|
77
|
-
constructor(store, options) {
|
|
78
|
-
super(store, options)
|
|
79
|
-
this.doSomething()
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
class MyPluginSubscriber extends PluginSubscriber<MyPlugin> {
|
|
84
|
-
constructor() {
|
|
85
|
-
super('my-plugin', MyPlugin.customizeStore.bind(MyPlugin))
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export const myStoreSubscriber = new MyPluginSubscriber()
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
**2) Simple subscriber implementing `PluginSubscriberInterface`:**
|
|
93
|
-
|
|
94
|
-
```typescript
|
|
95
|
-
import type { PluginSubscriberInterface } from 'pinia-plugin-subscription'
|
|
67
|
+
## Compatible Plugins
|
|
96
68
|
|
|
97
|
-
|
|
98
|
-
|
|
69
|
+
These plugins build on `pinia-plugin-subscription`; register their subscribers
|
|
70
|
+
with `createPlugin()` to use their features:
|
|
99
71
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
72
|
+
- **[pinia-plugin-subscription-devtools](packages/devtools/README.md):** structured tracing with filtered listeners, a per-store journal, payload redaction and an in-page panel.
|
|
73
|
+
- **[pinia-plugin-state-snapshots](packages/state-snapshots/README.md):** opt-in `$reset` wrapping and reset callbacks, plus state rollback when configured actions fail.
|
|
74
|
+
- **[pinia-plugin-extending-store](https://github.com/AlxBDo/extending-pinia-store):** compose state, getters and actions from parent stores into a child store.
|
|
75
|
+
- **[pinia-plugin-persist-state](https://github.com/AlxBDo/pinia-plugin-persist-state):** persist store state to browser storage or IndexedDB, with optional encryption.
|
|
76
|
+
- **[pinia-plugin-action-flow](https://github.com/AlxBDo/pinia-plugin-action-flow):** define before/after flows around store actions, including validation and side effects.
|
|
103
77
|
|
|
104
|
-
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
resetStoreCallback: (store) => {
|
|
108
|
-
console.log('store reset:', store.$id)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
```
|
|
78
|
+
Discover more compatible plugins on the [`pinia-plugin-subscription` GitHub topic](https://github.com/topics/pinia-plugin-subscription).
|
|
112
79
|
|
|
113
80
|
## Advanced Features
|
|
114
81
|
|
|
115
|
-
- **Structured tracing:**
|
|
116
|
-
- **Reset callbacks:** Define `resetStoreCallback` to run custom logic when a store is reset.
|
|
82
|
+
- **Structured tracing:** the plugin and `EnhancedStore` emit typed trace events through an optional `tracerHandler`; without one, no trace events are emitted. See [Tracing](#tracing).
|
|
117
83
|
- **SSR and hydration control:** Configure whether each subscribed plugin runs on the server, the client, or only after client hydration.
|
|
118
84
|
- **Lifecycle safety:** Internal hydration ordering is now guarded so `hydrate()` completes before `afterHydration()` and disposed stores do not retain stale subscriber metadata.
|
|
119
85
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
}))
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### SSR / Nuxt hydration control
|
|
143
|
-
|
|
144
|
-
The source of truth for hydration policy stays on the subscriber itself. For example, a client-only plugin should declare its execution directly:
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
export const persistedStateSubscriber: PluginSubscriberInterface = {
|
|
148
|
-
name: 'persisted-state',
|
|
149
|
-
execution: {
|
|
150
|
-
environment: 'client',
|
|
151
|
-
hydration: 'defer',
|
|
152
|
-
},
|
|
153
|
-
hydrationScheduler: (run) => {
|
|
154
|
-
nextTick(() => run())
|
|
155
|
-
},
|
|
156
|
-
invoke: (context) => {
|
|
157
|
-
// ...
|
|
158
|
-
return true
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
Available execution options:
|
|
164
|
-
|
|
165
|
-
- `environment: 'both' | 'client' | 'server'` — controls where the subscriber is allowed to run.
|
|
166
|
-
- `hydration: 'immediate' | 'defer'` — on the client, `defer` schedules execution after hydration.
|
|
167
|
-
- `hydrationScheduler` can be provided on a subscriber or through `createPlugin()` options to override execution timing when needed.
|
|
168
|
-
|
|
169
|
-
### SSR / Nuxt best practices
|
|
170
|
-
|
|
171
|
-
`pinia-plugin-subscription` is SSR-safe by design, but the runtime policy still needs to match the actual app lifecycle.
|
|
172
|
-
|
|
173
|
-
For helper-only imports, the package exposes an additive subpath kept separate from the default library API:
|
|
174
|
-
|
|
175
|
-
```ts
|
|
176
|
-
import { PluginSubscriber, Store } from 'pinia-plugin-subscription/helpers'
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
For type-only imports, prefer the dedicated public types entry:
|
|
180
|
-
|
|
181
|
-
```ts
|
|
182
|
-
import type { PluginSubscriptionOptions } from 'pinia-plugin-subscription/types'
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
## Development
|
|
186
|
-
|
|
187
|
-
This example shows the recommended pattern for SSR / Nuxt-safe plugins:
|
|
188
|
-
|
|
189
|
-
- `execution.environment` restricts the subscriber to `'both'`, `'client'`, or `'server'`
|
|
190
|
-
- `execution.hydration` is `'immediate'` by default and can be set to `'defer'` when the plugin must wait for client hydration
|
|
191
|
-
- `hydrationScheduler` lets you override the runtime scheduling behavior, for example with Nuxt/Vue `nextTick()`
|
|
192
|
-
- `hydrate()` / `afterHydration()` are optional lifecycle hooks for browser-only initialization and post-hydration work; they help keep SSR-sensitive logic out of constructors
|
|
193
|
-
|
|
194
|
-
## The `Store` Class — Summary
|
|
195
|
-
|
|
196
|
-
The `Store` class (see [src/core/Store.ts](src/core/Store.ts)) is a wrapper around a `PiniaStore` providing:
|
|
197
|
-
|
|
198
|
-
- **Properties:** `options`, `state`, `store`.
|
|
199
|
-
- **Useful methods:**
|
|
200
|
-
- `addToState(name, value?)` — adds a property to store state and exposes it as a `Ref` when appropriate.
|
|
201
|
-
- `addSubscription(pluginName, subscription)` — registers a plugin-specific subscription function.
|
|
202
|
-
- `getSubscriptions()` — returns registered subscriptions.
|
|
203
|
-
- `storeSubscribe` (getter/setter) — factory for `store.$subscribe` ({ store, callback }).
|
|
204
|
-
- `onAction` (getter/setter) — factory for `onAction` ({ store, callback }).
|
|
205
|
-
- `static customizeStore(store, options)` — recommended factory for class instantiation.
|
|
206
|
-
- `trace(label, payload?, scope?, namespace?)` — emits a structured trace event, scoped to the store by default.
|
|
207
|
-
- `traceError(label, error, payload?, scope?, namespace?)` — emits an error event, or reports it with `console.error` when no listener matches.
|
|
208
|
-
- Helpers: `stateHas()`, `storeHas()`, `getValue()`.
|
|
86
|
+
Subscriber delivery and cleanup tracking are scoped per Pinia store instance,
|
|
87
|
+
even when stores from different Pinia instances share the same `$id`.
|
|
88
|
+
Class-based subscribers can use `getStoreInstance(context.store)` in lifecycle
|
|
89
|
+
hooks to access the wrapper associated with that specific store.
|
|
90
|
+
|
|
91
|
+
For subscriber authors, store action events are emitted even without a `storeOnActionSubscription`.
|
|
92
|
+
The consumer receives an event; its `payload()` returns an object:
|
|
93
|
+
`ACTION_BEFORE` has `{ action, args, invocationKey }`, `ACTION_AFTER` has
|
|
94
|
+
`{ action, result, invocationKey }`, and `ACTION_ON_ERROR` has
|
|
95
|
+
`{ action, error, invocationKey }`. When present, the symbol identifies one
|
|
96
|
+
invocation; it may be `undefined` if the store has no event subscriber.
|
|
97
|
+
Event subscribers cannot interrupt the emitter: synchronous failures and async
|
|
98
|
+
rejections are reported with `console.error`, and other subscribers still run.
|
|
99
|
+
Async subscribers are not awaited.
|
|
100
|
+
Class-based subscribers define a unique `_name`; their `EnhancedStore` wrappers can
|
|
101
|
+
register event callbacks through protected helpers using the shared handler.
|
|
102
|
+
The orchestrator clears those subscriptions when the store is disposed. See
|
|
103
|
+
the [plugin authoring guide](docs/authoring-plugins.md#store-event-registration).
|
|
209
104
|
|
|
210
105
|
## Tracing
|
|
211
106
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
### Production safety
|
|
215
|
-
|
|
216
|
-
Tracing is **not automatically blocked in production**. Leave normal tracing disabled by default using your application's environment configuration; enable production diagnostics only deliberately and with limited scope and duration.
|
|
217
|
-
|
|
218
|
-
Events are **not automatically redacted** and may include sensitive action arguments, store state, plugin options, or error details. Filters select events by metadata; they do not sanitize payloads. Before writing to a console or forwarding to a logging service, select an allowlist of fields and redact sensitive values rather than sending complete events.
|
|
219
|
-
|
|
220
|
-
**Disabling normal tracing does not disable error reporting.** Errors can still be sent to `console.error` without a tracer or when no listener matches. See [Error reporting](#error-reporting) and the [security guidance](./SECURITY.md#tracing-and-production-logging) for precautions, including log access and retention.
|
|
107
|
+
The plugin only *emits* structured trace events; without a `tracerHandler` it emits nothing and costs nothing. Install [`pinia-plugin-subscription-devtools`](packages/devtools/) (usually as a development dependency) to consume them with filtered listeners, a per-store journal, payload redaction and an in-page panel:
|
|
221
108
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
```ts
|
|
225
|
-
import { createPlugin } from 'pinia-plugin-subscription'
|
|
226
|
-
import { createTracerRegistry } from 'pinia-plugin-subscription/helpers'
|
|
227
|
-
|
|
228
|
-
const traceRegistry = createTracerRegistry()
|
|
229
|
-
const remove = traceRegistry.addTraceListener({
|
|
230
|
-
filter: (event) => event.scope === 'cart'
|
|
231
|
-
&& event.namespace.startsWith('pluginsubscription:subscription:'),
|
|
232
|
-
handler: (event) => console.log(event.namespace, event.scope, event.payload)
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
pinia.use(createPlugin(subscribers, {
|
|
236
|
-
createTracer: traceRegistry.createTracer
|
|
237
|
-
}))
|
|
238
|
-
|
|
239
|
-
remove() // unsubscribe
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
`filter` is evaluated against event metadata before the payload is resolved,
|
|
243
|
-
so you can narrow tracing to a single store without building discarded
|
|
244
|
-
payloads. Registries do not share listeners with one another.
|
|
245
|
-
|
|
246
|
-
For simple metadata filters, provide comparison criteria instead of a
|
|
247
|
-
callback. Supported comparators are `equals` (the default), `contains`,
|
|
248
|
-
`startsWith` and `endsWith`; multiple criteria use `every` by default or
|
|
249
|
-
`some` when requested:
|
|
250
|
-
|
|
251
|
-
```ts
|
|
252
|
-
traceRegistry.addTraceListener({
|
|
253
|
-
filter: [
|
|
254
|
-
{ target: 'scope', value: 'cart' },
|
|
255
|
-
{ target: 'namespace', comparator: 'startsWith', value: 'pluginsubscription:subscription:' }
|
|
256
|
-
]
|
|
257
|
-
}, 'every')
|
|
258
|
-
```
|
|
259
|
-
|
|
260
|
-
When no `handler` is provided for criteria-based registration, the registry
|
|
261
|
-
uses its styled console listener.
|
|
262
|
-
|
|
263
|
-
### Event shape
|
|
264
|
-
|
|
265
|
-
| Field | Description |
|
|
266
|
-
| --- | --- |
|
|
267
|
-
| `namespace` | Structured identifier, derived from the label by default |
|
|
268
|
-
| `label` | Human-readable event label |
|
|
269
|
-
| `source` | Source passed to `createTracer`, usually `pinia-plugin-subscription` |
|
|
270
|
-
| `scope` | Instance identifier, usually `store.$id` |
|
|
271
|
-
| `payload` | Event data, resolved only when consumed |
|
|
272
|
-
| `level` | `debug` or `error` |
|
|
273
|
-
| `timestamp` | `Date.now()` at emission |
|
|
274
|
-
| `error` | Present on `error` events |
|
|
275
|
-
|
|
276
|
-
By default, `Store` prefixes its class name to labels and derived namespaces.
|
|
277
|
-
Library events use `PluginSubscription` as their prefix (for example,
|
|
278
|
-
`pluginsubscription:store:mutation` and
|
|
279
|
-
`pluginsubscription:subscription:delivery`). Set
|
|
280
|
-
`classNameAddedToTraceNamespace = false` on a `Store` subclass to omit its
|
|
281
|
-
class prefix, or provide an explicit namespace as the fourth argument to
|
|
282
|
-
`trace()` / `traceError()`.
|
|
283
|
-
|
|
284
|
-
### Emitting your own events
|
|
285
|
-
|
|
286
|
-
```ts
|
|
287
|
-
class CartStore extends Store {
|
|
288
|
-
hydrate() {
|
|
289
|
-
this.trace('cart:hydrate', () => ({ items: this.state.items }))
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
`Store.trace(label, payload?, scope?, namespace?)` and
|
|
295
|
-
`Store.traceError(label, error, payload?, scope?, namespace?)` emit the events.
|
|
296
|
-
The store class name is included in the label by default; set
|
|
297
|
-
`classNameAddedToTraceNamespace = false` to omit it. Unless an explicit
|
|
298
|
-
namespace is provided, the normalized label is used as the namespace.
|
|
299
|
-
|
|
300
|
-
Always prefer the **function form** for `payload`: it is only invoked once a
|
|
301
|
-
listener matches, so unobserved tracing costs nothing.
|
|
302
|
-
|
|
303
|
-
### Console listener
|
|
304
|
-
|
|
305
|
-
Normal trace events do not write to a console. Console output for those events is an opt-in listener:
|
|
306
|
-
|
|
307
|
-
```ts
|
|
308
|
-
import {
|
|
309
|
-
createConsoleTraceListener,
|
|
310
|
-
createTracerRegistry
|
|
311
|
-
} from 'pinia-plugin-subscription/helpers'
|
|
312
|
-
|
|
313
|
-
const traceRegistry = createTracerRegistry()
|
|
314
|
-
const remove = traceRegistry.addTraceListener({
|
|
315
|
-
...createConsoleTraceListener(),
|
|
316
|
-
filter: () => true
|
|
317
|
-
})
|
|
318
|
-
```
|
|
319
|
-
|
|
320
|
-
By default, this listener uses the styled plugin console. Pass any object exposing `log` and `error` to use another target:
|
|
321
|
-
|
|
322
|
-
Any object exposing `log` and `error` satisfies the `Console` interface, so external logging libraries can be connected without this plugin depending on them:
|
|
323
|
-
|
|
324
|
-
```ts
|
|
325
|
-
const remove = traceRegistry.addTraceListener({
|
|
326
|
-
...createConsoleTraceListener(myLogger),
|
|
327
|
-
filter: () => true
|
|
328
|
-
})
|
|
109
|
+
```bash
|
|
110
|
+
npm install -D pinia-plugin-subscription-devtools
|
|
329
111
|
```
|
|
330
112
|
|
|
331
|
-
### Error reporting
|
|
332
|
-
|
|
333
|
-
An error is delivered to every matching listener. If no listener matches — including when listeners exist but all filters reject the event — it is reported with `console.error`; it is not rethrown. Errors thrown by filters or handlers are also reported and isolated so they do not interrupt the traced process or remaining listeners.
|
|
334
|
-
|
|
335
|
-
### Migrating from `debugLog()` / `logError()`
|
|
336
|
-
|
|
337
|
-
These methods were removed in favour of structured events:
|
|
338
|
-
|
|
339
113
|
```ts
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
this.logError('subscriptionDelivery()', error, store, options)
|
|
343
|
-
|
|
344
|
-
// after
|
|
345
|
-
this.trace('store:mutation', () => ({ mutation, store }))
|
|
346
|
-
this.traceError('subscription:delivery', error, () => ({ store, options }))
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
The `namespace` replaces the formatted message, store trace events are scoped to `store.$id`, and the payload becomes a factory so it is only built when a listener consumes the event.
|
|
350
|
-
|
|
351
|
-
## Testing
|
|
352
|
-
|
|
353
|
-
- `npm run dev` — runs the dedicated demo app in [`demo/`](demo/). The library build remains `npm run build` and is intentionally kept separate from the demo entry.
|
|
354
|
-
- `npm test` — runs the Vitest suite, including typecheck tests (`*.test-d.ts`) validating type-level contracts such as `StoreOptionsExtensions` merging. Coverage reports are available in `coverage/`.
|
|
355
|
-
- `npm run bundle:check` — measures the emitted bundle size.
|
|
356
|
-
|
|
357
|
-
### Dependency leak guard
|
|
358
|
-
|
|
359
|
-
Published artifacts must only reference **peer dependencies** (`pinia`, `vue`) and Node builtins. A `devDependency` referenced from `src/` does not fail the local build, but it breaks consumers: Vite inlines runtime imports, while `tsc` keeps bare `import type` specifiers in the emitted `.d.ts`, which consumers cannot resolve.
|
|
114
|
+
import { createPlugin } from 'pinia-plugin-subscription'
|
|
115
|
+
import { createTraceDevtools } from 'pinia-plugin-subscription-devtools'
|
|
360
116
|
|
|
361
|
-
|
|
117
|
+
const { registry } = createTraceDevtools() // mounts the in-page panel in development browsers
|
|
362
118
|
|
|
363
|
-
|
|
364
|
-
npm run check:leaks
|
|
119
|
+
pinia.use(createPlugin(subscribers, { tracerHandler: registry.tracerHandler }))
|
|
365
120
|
```
|
|
366
121
|
|
|
367
|
-
|
|
122
|
+
See the [Tracing documentation](packages/devtools/docs/tracing.md) for filtering, redaction, production safety, event shape and error reporting. Plugin authors only need the `Tracer` and `TracerHandler` types from `pinia-plugin-subscription/types`, and `createTracer` / `this.trace()` to emit events.
|
|
368
123
|
|
|
369
124
|
## License
|
|
370
125
|
|
|
@@ -372,4 +127,4 @@ MIT
|
|
|
372
127
|
|
|
373
128
|
## Publishing
|
|
374
129
|
|
|
375
|
-
|
|
130
|
+
Both packages (`pinia-plugin-subscription` and `pinia-plugin-subscription-devtools`) are published to npm via GitHub Actions on the same release. GitHub releases marked as pre-releases are published with the `beta` dist-tag; stable releases use the default `latest` tag. The workflow runs `scripts/publish-unpublished.mjs`, which skips any package whose version is already on npm, so it can be safely re-run after a partial failure. It uses npm provenance for better supply-chain security and requires a `NPM_TOKEN` secret in the repository settings.
|
package/SECURITY.md
CHANGED
|
@@ -38,22 +38,22 @@ When using pinia-plugin-subscription:
|
|
|
38
38
|
|
|
39
39
|
### Tracing and Production Logging
|
|
40
40
|
|
|
41
|
-
Normal trace events are opt-in: the plugin requires an explicitly configured `
|
|
41
|
+
Tracing is provided by the separate `pinia-plugin-subscription-devtools` package. Normal trace events are opt-in: the plugin requires an explicitly configured `tracerHandler` and matching listeners to deliver them. `createTracerRegistry()` ignores `addListener()` in production builds (`process.env.NODE_ENV === 'production'`) unless `createTracerRegistry({ enabled: true })` is passed. This guard relies on the consuming bundler replacing `process.env.NODE_ENV`; without it, tracing is considered enabled. Production tracing can be useful for incident diagnosis, but should only be enabled deliberately and with controlled access to its output.
|
|
42
42
|
|
|
43
|
-
Trace events are not
|
|
43
|
+
Trace events are not redacted by default. Depending on the event, they may contain action arguments, store state, mutations, plugin options, subscriptions, or error details. These values can include application secrets or personal data. `createTracerRegistry({ redact: true })` masks values stored under sensitive keys (passwords, tokens, secrets, authorization, API keys, cookies...) before any listener receives them, but it inspects keys only: it does not detect secrets under innocuous keys, and it does not redact `event.error`. A listener can expose them through the browser console, server logs, or an external logging service. The absence of a production block is not, by itself, a vulnerability; the disclosure risk depends on the data emitted, the logging destination, and who can access it.
|
|
44
44
|
|
|
45
45
|
When configuring tracing:
|
|
46
46
|
|
|
47
|
-
1. **
|
|
48
|
-
2. **Minimize Logged Data:**
|
|
49
|
-
3. **Do Not Treat Filters as Redaction:** Filters only select events using metadata; a matching handler receives the full event, including its resolved payload and error.
|
|
47
|
+
1. **Keep Normal Tracing Disabled in Production:** This is the default of `createTracerRegistry()`. Only pass `enabled: true` when diagnostics are needed, and limit their duration and scope.
|
|
48
|
+
2. **Minimize Logged Data:** Enable `createTracerRegistry({ redact: true })` (extend it with your own `keys`) and select an explicit allowlist of fields before writing or forwarding events. Avoid logging complete stores, action arguments, plugin options, or raw error objects.
|
|
49
|
+
3. **Do Not Treat Filters as Redaction:** Filters only select events using metadata; a matching handler receives the full event, including its resolved payload and error. Use the `redact` option, and sanitize `event.error` and any remaining data in the handler before passing it to a logging destination.
|
|
50
50
|
4. **Protect Logging Destinations:** Review external logging services, restrict access to logs, and define appropriate retention periods. Do not assume browser console output or server logs are private.
|
|
51
51
|
|
|
52
52
|
**Error reporting is separate from normal tracing.** Without a tracer, plugin and store error reporting falls back to `console.error`. With a tracer, error events also fall back to `console.error` when no listener matches, including when all filters reject the event. Exceptions thrown by listener filters or handlers are reported to `console.error` as well. Removing listeners, clearing a registry, or omitting `createTracer` therefore does not guarantee that no errors will be logged.
|
|
53
53
|
|
|
54
54
|
For production, handle error events with a matching listener that reports only sanitized details, and ensure listener filters and handlers do not throw sensitive errors. Review the application's console and error logging policy as well; do not silently discard operational errors to prevent disclosure.
|
|
55
55
|
|
|
56
|
-
See [Tracing](./
|
|
56
|
+
See [Tracing](./packages/devtools/docs/tracing.md) for configuration and event details.
|
|
57
57
|
|
|
58
58
|
## Dependencies Security
|
|
59
59
|
|