@happyvertical/smrt-analytics 0.60.14 → 0.60.16

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.
@@ -2,7 +2,7 @@
2
2
  "version": "1.0.0",
3
3
  "timestamp": 0,
4
4
  "packageName": "@happyvertical/smrt-analytics",
5
- "packageVersion": "0.60.14",
5
+ "packageVersion": "0.60.16",
6
6
  "objects": {
7
7
  "@happyvertical/smrt-analytics:AnalyticsDataStreamCollection": {
8
8
  "name": "analyticsdatastreamcollection",
@@ -1 +1 @@
1
- {"version":3,"file":"AnalyticsReport.d.ts","sourceRoot":"","sources":["../../src/models/AnalyticsReport.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAGL,UAAU,EACV,KAAK,iBAAiB,EAEvB,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAElE;;;;;;GAMG;AACH,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,iBAAiB,EAAE,SAAS,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,SAAS,CAAC,EAAE,eAAe,CAAC;IAC5B,SAAS,CAAC,EAAE,IAAI,GAAG,IAA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KnB;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAQrC;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAO/B;;OAEG;IACH,gBAAgB,IAAI,IAAI;IAwBxB;;OAEG;IACH,KAAK,IAAI,OAAO;IAQhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,cAAc,CAAC,QAAQ,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,OAAO,CAAC;QACpE,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IA+CF;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;CAgF5C;AAED,eAAe,eAAe,CAAC"}
package/dist/prompts.d.ts CHANGED
@@ -42,7 +42,6 @@
42
42
  * computed aggregates (row counts, totals), and high-level dimension/metric
43
43
  * labels (which are public GA4/Plausible/Matomo schema names).
44
44
  */
45
- import { type ResolvedPromptAI } from '@happyvertical/smrt-prompts';
46
45
  /**
47
46
  * `AnalyticsProperty.analyzePerformance()` prompt. Only the human-readable
48
47
  * display name, provider label, and the requested period reach the model;
@@ -89,13 +88,9 @@ export declare const smrtAnalyticsAnalyzeResultsPrompt: import("@happyvertical/s
89
88
  */
90
89
  export declare const smrtAnalyticsHasPositiveTrendsPrompt: import("@happyvertical/smrt-prompts").PromptDefinition;
91
90
  /**
92
- * Build the message-options object passed to `aiClient.message()` from a
93
- * `ResolvedPromptAI` shape. Mirrors the helper in `smrt-properties` and
94
- * `smrt-content` so behavior across packages is identical.
91
+ * Canonical helper lives in `@happyvertical/smrt-prompts` (#4751): it also
92
+ * forwards the resolution's `usageTags` (`promptKey`, `promptLayer`,
93
+ * `templateHash`). Re-exported here for existing importers.
95
94
  */
96
- export declare function promptMessageOptions(ai: ResolvedPromptAI): {
97
- maxTokens?: number | undefined;
98
- temperature?: number | undefined;
99
- model?: string | undefined;
100
- };
95
+ export { promptMessageOptions } from '@happyvertical/smrt-prompts';
101
96
  //# sourceMappingURL=prompts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAEL,KAAK,gBAAgB,EACtB,MAAM,6BAA6B,CAAC;AAErC;;;;GAIG;AACH,eAAO,MAAM,qCAAqC,wDAWhD,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,iCAAiC,wDAsB5C,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oCAAoC,wDAkB/C,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,gBAAgB;;;;EASxD"}
1
+ {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAIH;;;;GAIG;AACH,eAAO,MAAM,qCAAqC,wDAYhD,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,iCAAiC,wDAuB5C,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,oCAAoC,wDAmB/C,CAAC;AAEH;;;;GAIG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC"}
@@ -3,13 +3,13 @@
3
3
  "sensitiveFieldsExcluded": true,
4
4
  "generatedAt": "1970-01-01T00:00:00.000Z",
5
5
  "packageName": "@happyvertical/smrt-analytics",
6
- "packageVersion": "0.60.14",
6
+ "packageVersion": "0.60.16",
7
7
  "sourceManifestPath": "dist/manifest.json",
8
8
  "agentDocPath": "AGENTS.md",
9
9
  "sourceHashes": {
10
- "manifest": "9d8a57f6751e0635127417ff641d314413d2a225a65cd05e385046f46e0021ed",
11
- "packageJson": "0f501e0a78c78a61d689d4fb6cd8f049d3f6d7c37d6c59e05038a1f661a27aac",
12
- "agents": "0738e00081ba0afec63eead2120be90659465f3daf4fbd15948594d062448677",
10
+ "manifest": "7ba8428f44eef071644123286a775c04d3a81aed2d9c243f53460aea6b81e277",
11
+ "packageJson": "77d7985b012d75b03e5a0a6ec5b5d9f4bc8a06a7a6c61412d033452ae833d441",
12
+ "agents": "2ea3b0b6a66a546e17c63f8131208ad48870c289dfa39e5f3fda7be17395e3e4",
13
13
  "moduleDoc:agents/browser.md": "af729304f8ffe8106261665b23f7bbeedcf64fdb08a46f22df1f0bea100ab21b"
14
14
  },
15
15
  "exports": [
@@ -3637,7 +3637,7 @@
3637
3637
  "polymorphicAssociations": 0,
3638
3638
  "uuidColumns": 22
3639
3639
  },
3640
- "agentDoc": "# @happyvertical/smrt-analytics\n\nGA4/Plausible/Matomo analytics integration with server-side event tracking and AI-powered reporting.\n\n## Models\n\n- **AnalyticsProperty**: GA4 property, Plausible site, or Matomo site. Provider metadata, status, sync timestamps.\n- **AnalyticsDataStream**: web/iOS/Android data streams. Measurement IDs (G-XXXXXX for GA4, Firebase app ID for mobile).\n- **AnalyticsEvent**: tracked events with params (JSON), retry queue, conversion classification.\n- **AnalyticsReport**: saved report configs with dimensions/metrics (JSON), scheduling (daily/weekly/monthly), result caching.\n\nAll models use STI (`tableStrategy: 'sti'`).\n\nAll four persisted models are `@TenantScoped({ mode: 'optional' })` with a nullable `tenantId` (#1410), matching the framework convention used by sibling domain packages (ads/jobs/commerce). **When a tenant context is active**, the interceptor auto-filters `list`/`get`/raw reads and binds `create`/`save` writes to that tenant, keeping one tenant's properties, data streams, events (end-user PII), and cached report rows from reaching another. Because the mode is `optional`, the interceptor intentionally passes **through unfiltered when no tenant context is established** — so a surface is only safe insofar as it establishes tenant context first. Generated SvelteKit routes do this (#1540); the CLI/MCP code paths do not yet, which is a known framework-level residual (fail-closed tenant context for CLI/MCP) tracked outside this package, not an analytics-specific gap.\n\n## Key Collection Methods\n\n`findByExternalId()`, `findByProvider()`, `findNeedingSync()`, `findGA4Properties()`, `findPlausibleSites()`, `findMatomoSites()`\n\n## AI Operations\n\n`analyzePerformance()`, `analyzeResults()`, `hasPositiveTrends()` route through registered prompts (see Prompt Registry below) so tenant overrides apply via `resolvePrompt()`. `isPerformingWell()` still uses the inline `is()` shortcut.\n\n## Prompt Registry\n\nThree prompts are registered at module-load time via `definePrompt()` from `@happyvertical/smrt-prompts`. Re-exported from the package root for tenant override targeting.\n\n| Key | Method | Variables (PII-conscious) |\n|-----|--------|---------------------------|\n| `smrtAnalytics.property.analyzePerformance` | `AnalyticsProperty.analyzePerformance()` | `period`, `propertyDisplayName`, `propertyProvider` |\n| `smrtAnalytics.report.analyzeResults` | `AnalyticsReport.analyzeResults()` | `reportName`, `reportDimensions`, `reportMetrics`, `dateRangeStart`, `dateRangeEnd`, `rowCount`, `reportData` |\n| `smrtAnalytics.report.hasPositiveTrends` | `AnalyticsReport.hasPositiveTrends()` | `reportMetrics`, `reportData` |\n\n**Excluded from variables (never reach the AI provider):**\n- `id`, `propertyId`, `tenantId`, `externalId` — internal foreign keys / UUIDs that link to identifying records.\n- `apiSecret`, `measurementId`, `siteDomain` — provider credentials and platform-specific identifiers (GA4 API secrets, Matomo `idSite`, custom `G-XXXX` measurement IDs).\n- `providerMetadata` — extensible JSON blob that may contain credentials, account IDs, or other configuration secrets.\n- `lastError`, raw `dimensionFilter` / `metricFilter` JSON — internal error strings (may contain auth tokens) and filter expressions that may reference cookie IDs, user-pseudo-IDs, or IP-derived geos.\n\n**`resultData` is forwarded verbatim.** This package does not — and cannot — strip PII from result rows, because the row schema is determined by the dimensions/metrics the caller asked the analytics provider to return. If the caller persists rows containing a `userPseudoId`, `clientId`, IP-derived geolocation, or any other identifier, those fields WILL reach the AI provider. Callers must:\n\n- exclude PII-bearing dimensions before persisting `resultData` (e.g. don't request `userPseudoId` as a GA4 dimension), or\n- apply a column allowlist at the call site before invoking `analyzeResults()`, or\n- override the prompt template via `PromptOverride` to redact rows.\n\nThe forwarding contract is pinned by a regression test in `src/__tests__/analytics-report-prompt.test.ts`.\n\nSee `src/prompts.ts` for the full rationale block.\n\n## UI Registry\n\nSvelte components live in `src/svelte/` and auto-register with `ModuleUIRegistry` from `@happyvertical/smrt-ui/registry` when `@happyvertical/smrt-analytics/svelte` is imported.\n\nSlot declarations live in `src/ui.ts`, exported via the `./ui` package subpath. The slots are: `analytics-summary`, `events-table`, `property-info`, `property-status-badge`, `stat-card`, `trend-badge` (see `ANALYTICS_UI_SLOTS` for icons / categories / display order).\n\n```typescript\nimport '@happyvertical/smrt-analytics/svelte'; // side-effect: registers slots\nimport { ModuleUIRegistry } from '@happyvertical/smrt-ui/registry';\nconst StatCard = ModuleUIRegistry.get('@happyvertical/smrt-analytics', 'stat-card');\n```\n\n## Recipes (#3719)\n\n`src/recipes.ts` declares `analytics.reports` (`AnalyticsReportsRecipe`:\n`AnalyticsProperty` and `AnalyticsReport`), emitted into the built\n`manifest.json` and `smrt-knowledge.json` `recipes`. `AnalyticsEvent` and\n`AnalyticsDataStream` are left out: event tracking and stream setup are separate\nconcerns. User-facing help is `src/reports.recipe.md` (#3591); keep it and the\n`@field({ description })` text on the two models in plain language, and never\nreference a `sensitive` field (`apiSecret`, `providerMetadata`) in help.\n\n- **Runtime is `server`.** Reports and their rows live in the app database, the\n AI summary needs a server-held key, and provider credentials sit on the\n property row (so no `providers` are declared: there are no env secrets to name).\n- **One route, deliberately.** `/analytics/summary` mounts\n `@happyvertical/smrt-analytics/svelte#AnalyticsSummary`, which renders an empty\n state without data. `PropertyInfo` and `EventsTable` take required row props\n and throw with none, so they are not routes; a host places them in its own\n pages. Add a route only for a component that survives being mounted bare.\n- **No demo seed.** The playground sample data is module-local, not an export.\n- **What the assistant can do.** Generated MCP exposes `list` and `get` on\n `AnalyticsReport` only; `analyzeResults()` is a model method the app calls,\n not a tool. The help says so and points at `reports.query` (declared reports,\n `@happyvertical/smrt-reports`) and `reports.runtime.*` (runtime reports,\n `@happyvertical/smrt-chat`) for aggregates over the app's own data.\n\n`src/__tests__/recipes.test.ts` runs the real scan, manifest and generation\npasses in memory and renders the help. See\n[core recipes](../core/agents/recipes.md).\n\n## Gotchas\n\n- **`apiSecret` / `providerMetadata` stripped from API/MCP**: marked `@field({ sensitive: true })` (#1540) so they never appear in generated responses or `where` filters. They are still stored at rest **unencrypted** — envelope encryption via `@happyvertical/smrt-secrets` is a separate, breaking follow-up (tracked, not done here).\n- **Event retry at model level**: no background job integration\n- **JSON fields**: params, dimensions, metrics use string storage with getter/setter helpers\n- **Measurement IDs differ per platform**: G-XXXXXX (GA4 web) vs Firebase app ID (mobile)\n- **`analyzeResults` is now a single AI call**: previously issued a second freeform `do()` to summarize \"top 3 insights\"; folded into the registered template, and `insights` mirrors `analysis` in the response shape.\n\n## Browser tracking (#4251)\n\nThe isolated `./browser` subpath owns the optional browser tracker and Matomo\nHTTP adapter; it must never import model registration or the server SDK.\nThe optional `smrt-ui/analytics` context connects shared component standard\nevents to the configured provider. See [browser contract](agents/browser.md).\n",
3640
+ "agentDoc": "# @happyvertical/smrt-analytics\n\nGA4/Plausible/Matomo analytics integration with server-side event tracking and AI-powered reporting.\n\n## Models\n\n- **AnalyticsProperty**: GA4 property, Plausible site, or Matomo site. Provider metadata, status, sync timestamps.\n- **AnalyticsDataStream**: web/iOS/Android data streams. Measurement IDs (G-XXXXXX for GA4, Firebase app ID for mobile).\n- **AnalyticsEvent**: tracked events with params (JSON), retry queue, conversion classification.\n- **AnalyticsReport**: saved report configs with dimensions/metrics (JSON), scheduling (daily/weekly/monthly), result caching.\n\nAll models use STI (`tableStrategy: 'sti'`).\n\nAll four persisted models are `@TenantScoped({ mode: 'optional' })` with a nullable `tenantId` (#1410), matching the framework convention used by sibling domain packages (ads/jobs/commerce). **When a tenant context is active**, the interceptor auto-filters `list`/`get`/raw reads and binds `create`/`save` writes to that tenant, keeping one tenant's properties, data streams, events (end-user PII), and cached report rows from reaching another. Because the mode is `optional`, the interceptor intentionally passes **through unfiltered when no tenant context is established** — so a surface is only safe insofar as it establishes tenant context first. Generated SvelteKit routes do this (#1540); the CLI/MCP code paths do not yet, which is a known framework-level residual (fail-closed tenant context for CLI/MCP) tracked outside this package, not an analytics-specific gap.\n\n## Key Collection Methods\n\n`findByExternalId()`, `findByProvider()`, `findNeedingSync()`, `findGA4Properties()`, `findPlausibleSites()`, `findMatomoSites()`\n\n## AI Operations\n\n`analyzePerformance()`, `analyzeResults()`, `hasPositiveTrends()` route through registered prompts (see Prompt Registry below) so tenant overrides apply via `resolvePrompt()`. `isPerformingWell()` still uses the inline `is()` shortcut.\n\n## Prompt Registry\n\nThree prompts are registered at module-load time via `definePrompt()` from `@happyvertical/smrt-prompts`. Re-exported from the package root for tenant override targeting. Tiers follow the #4755 rule (`../prompts/AGENTS.md`); calls bind them through `prepareAiOperation()`.\n\n| Key | Method | Tier | Variables (PII-conscious) |\n|-----|--------|------|---------------------------|\n| `smrtAnalytics.property.analyzePerformance` | `AnalyticsProperty.analyzePerformance()` | `good` | `period`, `propertyDisplayName`, `propertyProvider` |\n| `smrtAnalytics.report.analyzeResults` | `AnalyticsReport.analyzeResults()` | `good` | `reportName`, `reportDimensions`, `reportMetrics`, `dateRangeStart`, `dateRangeEnd`, `rowCount`, `reportData` |\n| `smrtAnalytics.report.hasPositiveTrends` | `AnalyticsReport.hasPositiveTrends()` | `cheap` | `reportMetrics`, `reportData` |\n\n**Excluded from variables (never reach the AI provider):**\n- `id`, `propertyId`, `tenantId`, `externalId` — internal foreign keys / UUIDs that link to identifying records.\n- `apiSecret`, `measurementId`, `siteDomain` — provider credentials and platform-specific identifiers (GA4 API secrets, Matomo `idSite`, custom `G-XXXX` measurement IDs).\n- `providerMetadata` — extensible JSON blob that may contain credentials, account IDs, or other configuration secrets.\n- `lastError`, raw `dimensionFilter` / `metricFilter` JSON — internal error strings (may contain auth tokens) and filter expressions that may reference cookie IDs, user-pseudo-IDs, or IP-derived geos.\n\n**`resultData` is forwarded verbatim.** This package does not — and cannot — strip PII from result rows, because the row schema is determined by the dimensions/metrics the caller asked the analytics provider to return. If the caller persists rows containing a `userPseudoId`, `clientId`, IP-derived geolocation, or any other identifier, those fields WILL reach the AI provider. Callers must:\n\n- exclude PII-bearing dimensions before persisting `resultData` (e.g. don't request `userPseudoId` as a GA4 dimension), or\n- apply a column allowlist at the call site before invoking `analyzeResults()`, or\n- override the prompt template via `PromptOverride` to redact rows.\n\nThe forwarding contract is pinned by a regression test in `src/__tests__/analytics-report-prompt.test.ts`.\n\nSee `src/prompts.ts` for the full rationale block.\n\n## UI Registry\n\nSvelte components live in `src/svelte/` and auto-register with `ModuleUIRegistry` from `@happyvertical/smrt-ui/registry` when `@happyvertical/smrt-analytics/svelte` is imported.\n\nSlot declarations live in `src/ui.ts`, exported via the `./ui` package subpath. The slots are: `analytics-summary`, `events-table`, `property-info`, `property-status-badge`, `stat-card`, `trend-badge` (see `ANALYTICS_UI_SLOTS` for icons / categories / display order).\n\n```typescript\nimport '@happyvertical/smrt-analytics/svelte'; // side-effect: registers slots\nimport { ModuleUIRegistry } from '@happyvertical/smrt-ui/registry';\nconst StatCard = ModuleUIRegistry.get('@happyvertical/smrt-analytics', 'stat-card');\n```\n\n## Recipes (#3719)\n\n`src/recipes.ts` declares `analytics.reports` (`AnalyticsReportsRecipe`:\n`AnalyticsProperty` and `AnalyticsReport`), emitted into the built\n`manifest.json` and `smrt-knowledge.json` `recipes`. `AnalyticsEvent` and\n`AnalyticsDataStream` are left out: event tracking and stream setup are separate\nconcerns. User-facing help is `src/reports.recipe.md` (#3591); keep it and the\n`@field({ description })` text on the two models in plain language, and never\nreference a `sensitive` field (`apiSecret`, `providerMetadata`) in help.\n\n- **Runtime is `server`.** Reports and their rows live in the app database, the\n AI summary needs a server-held key, and provider credentials sit on the\n property row (so no `providers` are declared: there are no env secrets to name).\n- **One route, deliberately.** `/analytics/summary` mounts\n `@happyvertical/smrt-analytics/svelte#AnalyticsSummary`, which renders an empty\n state without data. `PropertyInfo` and `EventsTable` take required row props\n and throw with none, so they are not routes; a host places them in its own\n pages. Add a route only for a component that survives being mounted bare.\n- **No demo seed.** The playground sample data is module-local, not an export.\n- **What the assistant can do.** Generated MCP exposes `list` and `get` on\n `AnalyticsReport` only; `analyzeResults()` is a model method the app calls,\n not a tool. The help says so and points at `reports.query` (declared reports,\n `@happyvertical/smrt-reports`) and `reports.runtime.*` (runtime reports,\n `@happyvertical/smrt-chat`) for aggregates over the app's own data.\n\n`src/__tests__/recipes.test.ts` runs the real scan, manifest and generation\npasses in memory and renders the help. See\n[core recipes](../core/agents/recipes.md).\n\n## Gotchas\n\n- **`apiSecret` / `providerMetadata` stripped from API/MCP**: marked `@field({ sensitive: true })` (#1540) so they never appear in generated responses or `where` filters. They are still stored at rest **unencrypted** — envelope encryption via `@happyvertical/smrt-secrets` is a separate, breaking follow-up (tracked, not done here).\n- **Event retry at model level**: no background job integration\n- **JSON fields**: params, dimensions, metrics use string storage with getter/setter helpers\n- **Measurement IDs differ per platform**: G-XXXXXX (GA4 web) vs Firebase app ID (mobile)\n- **`analyzeResults` is now a single AI call**: previously issued a second freeform `do()` to summarize \"top 3 insights\"; folded into the registered template, and `insights` mirrors `analysis` in the response shape.\n\n## Browser tracking (#4251)\n\nThe isolated `./browser` subpath owns the optional browser tracker and Matomo\nHTTP adapter; it must never import model registration or the server SDK.\nThe optional `smrt-ui/analytics` context connects shared component standard\nevents to the configured provider. See [browser contract](agents/browser.md).\n",
3641
3641
  "moduleDocs": [
3642
3642
  {
3643
3643
  "path": "agents/browser.md",
@@ -5,10 +5,10 @@ description: "Analytics integration models for SMRT framework"
5
5
  status: "stable"
6
6
  generated:
7
7
  by: "smrt/scripts/generate-knowledge-okf.ts"
8
- at: "2026-11-05T15:48:19Z"
8
+ at: "2026-11-08T08:40:59Z"
9
9
  audience: "internal"
10
10
  evidence_level: "source-inspected"
11
- source_revision: "sha256:0956cf7e880461b1b116bcd6d83f48e2a3a3c07a31c2ce7e7fb5b0ff3ca39a2f"
11
+ source_revision: "sha256:da9625dcc5cd080352c83d4a4df595e3fe351beae9958b165611bfccf341f60f"
12
12
  sources:
13
13
  - id: "manifest"
14
14
  resource: "https://github.com/happyvertical/smrt/blob/main/packages/analytics/package.json"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-analytics",
3
- "version": "0.60.14",
3
+ "version": "0.60.16",
4
4
  "smrtJsdoc": "strict",
5
5
  "description": "Analytics integration models for SMRT framework",
6
6
  "type": "module",
@@ -38,11 +38,11 @@
38
38
  }
39
39
  },
40
40
  "dependencies": {
41
- "@happyvertical/smrt-core": "0.60.14",
42
- "@happyvertical/smrt-prompts": "0.60.14",
43
- "@happyvertical/smrt-tenancy": "0.60.14",
44
- "@happyvertical/smrt-types": "0.60.14",
45
- "@happyvertical/smrt-ui": "0.60.14"
41
+ "@happyvertical/smrt-core": "0.60.16",
42
+ "@happyvertical/smrt-prompts": "0.60.16",
43
+ "@happyvertical/smrt-tenancy": "0.60.16",
44
+ "@happyvertical/smrt-types": "0.60.16",
45
+ "@happyvertical/smrt-ui": "0.60.16"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "svelte": "^5.57.0"
@@ -53,9 +53,9 @@
53
53
  }
54
54
  },
55
55
  "devDependencies": {
56
- "@happyvertical/smrt-scanner": "0.60.14",
57
- "@happyvertical/smrt-vitest": "0.60.14",
58
- "@happyvertical/sql": "^0.111.6",
56
+ "@happyvertical/smrt-scanner": "0.60.16",
57
+ "@happyvertical/smrt-vitest": "0.60.16",
58
+ "@happyvertical/sql": "^0.111.8",
59
59
  "@sveltejs/package": "^2.5.8",
60
60
  "@types/node": "24.13.6",
61
61
  "svelte-check": "^4.7.6",