@nuxtseo/pro-indexing 0.0.0-stage → 0.1.4

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.
@@ -0,0 +1,231 @@
1
+ <script setup lang="ts" generic="T extends object">
2
+ import type { UiTableColumn, UiTableRowId, UiTableSize } from '@nuxtseo/design-system/app/shared/table'
3
+ import { useHumanFriendlyNumber } from '@nuxtseo/design-system/app/composables/formatting'
4
+ import { refDebounced } from '@vueuse/core'
5
+ import { computed, ref, watch } from 'vue'
6
+ import { UiAlert, UiButton, UiEmptyState, UiFilterMenu, UiInput, UiSkeleton, UiTable, UiTablePagination } from '#components'
7
+
8
+ // The default table shell of `IndexingUrlsTable`: search, the status filter,
9
+ // loading, error, empty, the table, and the pager. A site with its own shell
10
+ // passes it as the table's `shell` prop; that shell takes these props, emits
11
+ // these events, and fills the same slots (`toolbar`, `notices`,
12
+ // `expanded-component`).
13
+
14
+ export interface IndexingUrlsTableFilter {
15
+ key: string
16
+ label: string
17
+ icon?: string
18
+ tooltip?: string
19
+ }
20
+
21
+ const {
22
+ filters = [],
23
+ searchPlaceholder = 'Search…',
24
+ emptyIcon = 'file-search',
25
+ emptyTitle = 'No results',
26
+ emptyDefaultDescription = '',
27
+ itemLabel = 'rows',
28
+ pageSize = 25,
29
+ hasExternalFilter = false,
30
+ hasCachedData,
31
+ rowClickable = false,
32
+ tableSize = 'md',
33
+ q,
34
+ filter,
35
+ page,
36
+ error,
37
+ rows,
38
+ } = defineProps<{
39
+ filters?: IndexingUrlsTableFilter[]
40
+ searchPlaceholder?: string
41
+ emptyIcon?: string
42
+ emptyTitle?: string
43
+ emptyDefaultDescription?: string
44
+ itemLabel?: string
45
+ pageSize?: number
46
+ /** Another filter the table owns is active, such as an issue. */
47
+ hasExternalFilter?: boolean
48
+ /** Accepted for parity with a site shell. The default shell saves no filters. */
49
+ showSavedFilters?: boolean
50
+ /** A successful response is present, including a valid empty one. */
51
+ hasCachedData?: boolean
52
+ rowClickable?: boolean
53
+ rowId?: UiTableRowId<T>
54
+ initialExpandedRowId?: string
55
+ tableSize?: UiTableSize
56
+ tableLabel: string
57
+ q: string
58
+ filter: string | undefined
59
+ isLoading: boolean
60
+ error: Error | null | undefined
61
+ rows: T[]
62
+ total: number
63
+ page: number
64
+ columns: UiTableColumn<T>[]
65
+ tableData: T[]
66
+ }>()
67
+
68
+ const emit = defineEmits<{
69
+ 'update:q': [value: string]
70
+ 'update:page': [value: number]
71
+ 'toggleFilter': [key: string]
72
+ 'clearFilters': []
73
+ 'retry': []
74
+ }>()
75
+
76
+ const localQ = ref(q)
77
+ const debouncedQ = refDebounced(localQ, 300)
78
+ const localPage = computed({
79
+ get: () => page,
80
+ set: (value: number) => emit('update:page', value),
81
+ })
82
+
83
+ const cachedEvidence = computed(() => hasCachedData ?? rows.length > 0)
84
+ const blockingError = computed(() => error && !cachedEvidence.value ? error : null)
85
+ const refreshError = computed(() => error && cachedEvidence.value ? error : null)
86
+ const hasActiveFilter = computed(() => Boolean(q || (filter && filter !== 'default') || hasExternalFilter))
87
+ const emptyDescription = computed(() => {
88
+ if (q)
89
+ return `No ${itemLabel} match "${q}"`
90
+ if ((filter && filter !== 'default') || hasExternalFilter)
91
+ return `No ${itemLabel} match the selected filter`
92
+ return emptyDefaultDescription
93
+ })
94
+
95
+ watch(() => q, (value) => {
96
+ if (value !== localQ.value)
97
+ localQ.value = value
98
+ })
99
+ watch(debouncedQ, (value) => {
100
+ if (value === q)
101
+ return
102
+ emit('update:q', value)
103
+ emit('update:page', 1)
104
+ })
105
+
106
+ function commitQ(value = localQ.value) {
107
+ localQ.value = value
108
+ if (value !== q)
109
+ emit('update:q', value)
110
+ emit('update:page', 1)
111
+ }
112
+
113
+ const presetFilters = computed(() => filters.map(entry => ({ id: entry.key, label: entry.label, icon: entry.icon })))
114
+ const activeCount = computed(() => filter && filter !== 'default' ? 1 : 0)
115
+
116
+ function clearOwnedFilters() {
117
+ commitQ('')
118
+ if (filter && filter !== 'default')
119
+ emit('toggleFilter', filter)
120
+ }
121
+ function clearAllFilters() {
122
+ if (hasExternalFilter)
123
+ emit('clearFilters')
124
+ else
125
+ clearOwnedFilters()
126
+ }
127
+ </script>
128
+
129
+ <template>
130
+ <div class="space-y-4" :aria-busy="isLoading || undefined">
131
+ <div class="flex items-center justify-between gap-2">
132
+ <div class="flex-1 sm:flex-none sm:w-64">
133
+ <UiInput
134
+ v-model="localQ"
135
+ :placeholder="searchPlaceholder"
136
+ :aria-label="searchPlaceholder"
137
+ icon="search"
138
+ autocomplete="off"
139
+ size="sm"
140
+ :ui="{ base: 'min-h-11 sm:min-h-10' }"
141
+ @keydown.enter="commitQ()"
142
+ >
143
+ <template #trailing>
144
+ <UiButton
145
+ v-if="localQ !== ''"
146
+ purpose="quiet"
147
+ icon="close"
148
+ size="xs"
149
+ class="min-h-11 min-w-11 sm:min-h-0 sm:min-w-0"
150
+ aria-label="Clear search"
151
+ @click="commitQ('')"
152
+ />
153
+ </template>
154
+ </UiInput>
155
+ </div>
156
+ <div class="flex items-center gap-1">
157
+ <slot name="toolbar" />
158
+ <UiFilterMenu
159
+ v-if="filters.length"
160
+ :searchable="false"
161
+ :preset-filters="presetFilters"
162
+ :active-preset="filter"
163
+ :saved-filters="[]"
164
+ :active-count="activeCount"
165
+ :show-saved="false"
166
+ @apply-preset="emit('toggleFilter', $event)"
167
+ @clear="clearOwnedFilters"
168
+ />
169
+ </div>
170
+ </div>
171
+
172
+ <slot name="notices" />
173
+
174
+ <UiAlert v-if="refreshError" status="warning" title="Latest refresh failed" description="Showing the last successful report.">
175
+ <template #action>
176
+ <UiButton purpose="secondary" size="xs" class="min-h-11 sm:min-h-0" @click="emit('retry')">
177
+ Retry
178
+ </UiButton>
179
+ </template>
180
+ </UiAlert>
181
+
182
+ <div v-if="isLoading" class="rounded-xl border border-default overflow-hidden">
183
+ <div class="divide-y divide-default">
184
+ <div v-for="i in Math.min(pageSize, 10)" :key="i" class="px-5 py-4 flex items-center gap-6">
185
+ <div class="flex-1">
186
+ <UiSkeleton class="h-4" :index="i" :base="180" :range="80" />
187
+ </div>
188
+ <UiSkeleton class="h-4" :index="i + 10" :base="48" :range="16" />
189
+ <UiSkeleton class="h-4" :index="i + 20" :base="56" :range="18" />
190
+ </div>
191
+ </div>
192
+ </div>
193
+
194
+ <UiAlert v-else-if="blockingError" status="error" icon="caution" :title="blockingError.message || 'The URLs could not be loaded'">
195
+ <template #action>
196
+ <UiButton purpose="secondary" size="xs" class="min-h-11 sm:min-h-0" @click="emit('retry')">
197
+ Retry
198
+ </UiButton>
199
+ </template>
200
+ </UiAlert>
201
+
202
+ <UiEmptyState v-else-if="!rows.length" compact heading-tag="h3" :icon="emptyIcon" :title="emptyTitle" :description="emptyDescription">
203
+ <UiButton v-if="hasActiveFilter" size="sm" purpose="secondary" @click="clearAllFilters">
204
+ Clear filters
205
+ </UiButton>
206
+ </UiEmptyState>
207
+
208
+ <UiTable
209
+ v-else
210
+ :data="tableData"
211
+ :columns="columns"
212
+ :page-size="pageSize"
213
+ bordered
214
+ :row-clickable="rowClickable"
215
+ :row-id="rowId"
216
+ :initial-expanded-row-id="initialExpandedRowId"
217
+ :size="tableSize"
218
+ :label="tableLabel"
219
+ disable-pagination
220
+ row-hover
221
+ >
222
+ <template v-if="$slots['expanded-component']" #expanded-component="{ row }">
223
+ <slot name="expanded-component" :row="row" />
224
+ </template>
225
+ </UiTable>
226
+
227
+ <UiTablePagination v-if="total > pageSize" v-model:page="localPage" :page-size="pageSize" :total="total">
228
+ <span class="font-medium text-default">{{ useHumanFriendlyNumber(total) }}</span> {{ itemLabel }} total
229
+ </UiTablePagination>
230
+ </div>
231
+ </template>
@@ -0,0 +1,27 @@
1
+ import type { InjectionKey } from 'vue'
2
+ import type { IndexingCapability, IndexingSource } from '../../shared/source'
3
+ import { inject, provide } from 'vue'
4
+ import { hasIndexingCapability } from '../../shared/source'
5
+
6
+ export const PRO_INDEXING_SOURCE_KEY: InjectionKey<IndexingSource> = Symbol('pro-indexing-source')
7
+
8
+ /**
9
+ * Provides the site's IndexingSource to every indexing section below. Call it
10
+ * in the setup of a component above the sections, such as the site's
11
+ * dashboard layout. To provide it app-wide, call
12
+ * `nuxtApp.vueApp.provide(PRO_INDEXING_SOURCE_KEY, source)` in a plugin.
13
+ */
14
+ export function provideIndexingSource(source: IndexingSource): IndexingSource {
15
+ provide(PRO_INDEXING_SOURCE_KEY, source)
16
+ return source
17
+ }
18
+
19
+ /** The IndexingSource a site provided, or null. A section draws nothing that needs a source when it is null. */
20
+ export function useIndexingSource(): IndexingSource | null {
21
+ return inject(PRO_INDEXING_SOURCE_KEY, null)
22
+ }
23
+
24
+ /** True when the provided source has the capability. Call it in setup. */
25
+ export function useIndexingCapability(capability: IndexingCapability): boolean {
26
+ return hasIndexingCapability(useIndexingSource(), capability)
27
+ }
@@ -0,0 +1,10 @@
1
+ import type { ProIndexingAppConfig } from '../../shared/config'
2
+ import type { ProIndexingCopy } from '../../shared/copy'
3
+ import { tryUseNuxtApp, useAppConfig } from 'nuxt/app'
4
+ import { resolveProIndexingCopy } from '../../shared/copy'
5
+
6
+ /** The indexing copy with the site's `proIndexing.copy` overrides applied. Call it in setup. */
7
+ export function useProIndexingCopy(): ProIndexingCopy {
8
+ const appConfig = tryUseNuxtApp() ? useAppConfig() : null
9
+ return resolveProIndexingCopy((appConfig?.proIndexing as ProIndexingAppConfig | undefined)?.copy)
10
+ }
@@ -0,0 +1,23 @@
1
+ import type { ProIndexingAppConfig } from '../../shared/config'
2
+ import type { ProIndexingAppRoute, ProIndexingQuery, ProIndexingSiteRoute } from '../../shared/routes'
3
+ import { tryUseNuxtApp, useAppConfig } from 'nuxt/app'
4
+ import { resolveIndexingAppRoute, resolveIndexingSiteRoute } from '../../shared/routes'
5
+
6
+ export interface ProIndexingRouteResolver {
7
+ readonly app: (name: ProIndexingAppRoute, query?: ProIndexingQuery) => string | null
8
+ readonly site: (name: ProIndexingSiteRoute, site: string, query?: ProIndexingQuery) => string | null
9
+ }
10
+
11
+ /**
12
+ * Resolves the sections' logical routes against app.config
13
+ * `proIndexing.routes`. Null means the site maps no such route: hide the link.
14
+ * Call it in setup; each call reads the map again.
15
+ */
16
+ export function useProIndexingRoute(): ProIndexingRouteResolver {
17
+ const appConfig = tryUseNuxtApp() ? useAppConfig() : null
18
+ const routes = () => (appConfig?.proIndexing as ProIndexingAppConfig | undefined)?.routes ?? {}
19
+ return {
20
+ app: (name, query) => resolveIndexingAppRoute(routes(), name, query),
21
+ site: (name, site, query) => resolveIndexingSiteRoute(routes(), name, site, query),
22
+ }
23
+ }
package/nuxt.config.ts ADDED
@@ -0,0 +1,33 @@
1
+ import { join } from 'node:path'
2
+ import { defineNuxtConfig } from 'nuxt/config'
3
+
4
+ const currentDir = import.meta.dirname
5
+
6
+ // Pro indexing layer: the dashboard indexing sections that nuxtseo.com,
7
+ // gscdump.com and Request Indexing share. It extends the shell and adds no
8
+ // module of its own.
9
+ //
10
+ // Per ADR-0042, ADR-0166 and ADR-0167: it MUST NOT import runtime services (no
11
+ // useFetch, $fetch, Drizzle, Caller, billing, auth, useRuntimeConfig). Every
12
+ // read and action goes through the IndexingSource the site provides
13
+ // (`provideIndexingSource`). An optional capability the source leaves out
14
+ // hides the section that needs it. Links come from the route map in
15
+ // app.config `proIndexing.routes`. The maths is `@gscdump/sdk/indexing`.
16
+ export default defineNuxtConfig({
17
+ extends: ['@nuxtseo/pro-shell'],
18
+
19
+ imports: { autoImport: false },
20
+
21
+ components: {
22
+ dirs: [
23
+ {
24
+ path: join(currentDir, './app/components'),
25
+ pathPrefix: false,
26
+ // The same priority as the shell and the design system, so a site
27
+ // component with a layer name loses. Sites change the layer through
28
+ // props, slots, the source and app.config instead.
29
+ priority: 10,
30
+ },
31
+ ],
32
+ },
33
+ })
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@nuxtseo/pro-indexing",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "type": "module",
4
+ "version": "0.1.4",
5
+ "description": "Nuxt SEO Pro indexing layer: the dashboard indexing sections (Portfolio overview, issues and changes, the per-Site diagnosis panel, coverage trend, Index cohorts, and the indexing URLs table) over one IndexingSource adapter and a route map. Extends @nuxtseo/pro-shell.",
6
+ "license": "MIT",
7
+ "homepage": "https://nuxtseo.com",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/harlan-zw/nuxtseo.com.git",
11
+ "directory": "layers/pro-indexing"
12
+ },
13
+ "keywords": [
14
+ "nuxt",
15
+ "nuxt-layer",
16
+ "dashboard",
17
+ "search-console",
18
+ "indexing"
19
+ ],
20
+ "exports": {
21
+ ".": "./nuxt.config.ts",
22
+ "./*": "./*",
23
+ "./app/*": "./app/*.ts",
24
+ "./app/*.vue": "./app/*.vue",
25
+ "./components/*.vue": "./app/components/*.vue",
26
+ "./composables/*": "./app/composables/*.ts",
27
+ "./package.json": "./package.json",
28
+ "./shared/*": "./shared/*.ts"
29
+ },
30
+ "main": "./nuxt.config.ts",
31
+ "files": [
32
+ "app",
33
+ "nuxt.config.ts",
34
+ "shared"
35
+ ],
36
+ "peerDependencies": {
37
+ "@gscdump/contracts": "^7.13.0",
38
+ "@gscdump/sdk": "^7.13.0",
39
+ "@nuxt/ui": "^4.11.1",
40
+ "@nuxtseo/design-system": "^0.1.4",
41
+ "@nuxtseo/pro-shell": "^0.1.4",
42
+ "@vueuse/core": "^14.0.0 || ^15.0.0",
43
+ "nuxt": "^4.6.0",
44
+ "typescript": ">=5.8.0 <7",
45
+ "vue": "^3.5.0"
46
+ },
47
+ "dependencies": {
48
+ "@unovis/ts": "^1.6.7",
49
+ "@unovis/vue": "^1.6.7"
50
+ },
51
+ "devDependencies": {
52
+ "@gscdump/contracts": "7.13.0",
53
+ "@gscdump/sdk": "7.13.0",
54
+ "@nuxt/ui": "^4.11.1",
55
+ "@nuxtseo/design-system": "0.1.4",
56
+ "@nuxtseo/pro-shell": "0.1.4",
57
+ "@vueuse/core": "^14.4.0",
58
+ "nuxt": "4.6.1",
59
+ "site-typecheck": "0.0.0",
60
+ "vue": "^3.5.43"
61
+ },
62
+ "publishConfig": {
63
+ "access": "public"
64
+ },
65
+ "scripts": {
66
+ "nuxt:prepare": "nuxt prepare",
67
+ "typecheck": "nuxt prepare && site-typecheck -b --noEmit --force",
68
+ "typecheck:legacy": "nuxt typecheck"
69
+ }
6
70
  }
@@ -0,0 +1,124 @@
1
+ // Portfolio indexing Changes. Pure: the roll-up carries every Site the source
2
+ // covers, and the group scope narrows it here.
3
+ //
4
+ // Moved from nuxtseo.com `layers/pro/gsc/app/utils/indexing-changes.ts`.
5
+ //
6
+ // Two sources with different strengths. A Site's trend counts every URL, so it
7
+ // owns the not-indexed change. The roll-up reads a page issue index, which can
8
+ // hold a sample of URLs per reason on a large Site: its counts are floors, and
9
+ // a URL can enter that sample long after Google reported it. So first recorded
10
+ // minus cleared is never presented as a change in level.
11
+
12
+ import type { IndexingTrendReading } from '@gscdump/sdk/indexing'
13
+ import { notIndexedCount } from '@gscdump/sdk/indexing'
14
+
15
+ /** One Site on one UTC day of the roll-up. */
16
+ export interface IndexingChangesRow {
17
+ readonly siteId: string
18
+ /** UTC day, `YYYY-MM-DD`. */
19
+ readonly day: string
20
+ /** Issues the source first reported on this day. */
21
+ readonly opened: number
22
+ /** Issues the source stopped reporting on this day. This says nothing about a repair. */
23
+ readonly cleared: number
24
+ }
25
+
26
+ /** What the `changesRollup` capability returns. */
27
+ export interface IndexingChangesRollup {
28
+ readonly windowDays: number
29
+ /** The source's last UTC day of the window, so the axis cannot follow a browser clock. */
30
+ readonly through: string
31
+ /** Only days with a change. */
32
+ readonly rows: readonly IndexingChangesRow[]
33
+ }
34
+
35
+ export interface IndexingChangesSite {
36
+ id: string
37
+ label: string
38
+ /** Absent until the Site has a coverage observation. Missing is not zero. */
39
+ trend?: readonly IndexingTrendReading[]
40
+ }
41
+ export interface IndexingLevelChange {
42
+ notIndexed: number
43
+ /** Positive means more URLs are not indexed. */
44
+ change: number
45
+ /** The first day of the trend inside the window. */
46
+ since: string
47
+ }
48
+
49
+ export interface IndexingChangesDay {
50
+ day: string
51
+ opened: number
52
+ cleared: number
53
+ }
54
+
55
+ export interface IndexingChangesSiteRow {
56
+ siteId: string
57
+ label: string
58
+ opened: number
59
+ cleared: number
60
+ level: IndexingLevelChange | null
61
+ }
62
+
63
+ export interface IndexingChanges {
64
+ /** One entry per UTC day of the window, oldest first, zero filled. */
65
+ days: IndexingChangesDay[]
66
+ /** Sites with a change, largest not-indexed rise first. Unknown levels sort last. */
67
+ sites: IndexingChangesSiteRow[]
68
+ }
69
+
70
+ const DAY_MS = 86_400_000
71
+
72
+ function windowAxis(through: string, windowDays: number): string[] {
73
+ const last = Date.parse(`${through}T00:00:00Z`)
74
+ return Array.from({ length: windowDays }, (_, index) =>
75
+ new Date(last - (windowDays - 1 - index) * DAY_MS).toISOString().slice(0, 10))
76
+ }
77
+
78
+ /** The not-indexed change across the window, or null without two days to compare. */
79
+ export function indexingLevelChange(trend: readonly IndexingTrendReading[], from: string): IndexingLevelChange | null {
80
+ const points = trend.filter(point => point.totalUrls > 0 && point.date >= from).toSorted((a, b) => a.date.localeCompare(b.date))
81
+ const first = points[0]
82
+ const last = points.at(-1)
83
+ if (!first || !last || first === last)
84
+ return null
85
+ const notIndexed = notIndexedCount(last)
86
+ return { notIndexed, change: notIndexed - notIndexedCount(first), since: first.date }
87
+ }
88
+
89
+ /**
90
+ * The chart and the list read one set of rows, so their totals agree. A row
91
+ * outside the scoped Sites or outside the window reaches neither.
92
+ */
93
+ export function summarizeIndexingChanges(rollup: IndexingChangesRollup, sites: readonly IndexingChangesSite[]): IndexingChanges {
94
+ const axis = windowAxis(rollup.through, rollup.windowDays)
95
+ const days = new Map(axis.map(day => [day, { day, opened: 0, cleared: 0 }]))
96
+ const bySite = new Map<string, IndexingChangesSiteRow>(sites.map(site => [site.id, {
97
+ siteId: site.id,
98
+ label: site.label,
99
+ opened: 0,
100
+ cleared: 0,
101
+ level: site.trend ? indexingLevelChange(site.trend, axis[0]!) : null,
102
+ }]))
103
+
104
+ const withTrend = new Set(sites.filter(site => site.trend?.length).map(site => site.id))
105
+ for (const row of rollup.rows) {
106
+ const day = days.get(row.day)
107
+ const site = bySite.get(row.siteId)
108
+ if (!day || !site)
109
+ continue
110
+ day.opened += row.opened
111
+ day.cleared += row.cleared
112
+ site.opened += row.opened
113
+ site.cleared += row.cleared
114
+ }
115
+
116
+ return {
117
+ days: [...days.values()],
118
+ sites: [...bySite.values()]
119
+ // A Site with a trend but nothing to compare stays, as unknown. Dropping it
120
+ // would read as no change.
121
+ .filter(site => site.opened > 0 || site.cleared > 0 || !!site.level?.change || (!site.level && withTrend.has(site.siteId)))
122
+ .sort((a, b) => (b.level?.change ?? Number.NEGATIVE_INFINITY) - (a.level?.change ?? Number.NEGATIVE_INFINITY) || b.opened - a.opened || a.label.localeCompare(b.label)),
123
+ }
124
+ }
@@ -0,0 +1,16 @@
1
+ // `proIndexing` in app.config: the route map and copy overrides. Write
2
+ // app.config as a plain object and wrap this key in `defineProIndexingConfig`
3
+ // to type-check it.
4
+
5
+ import type { ProIndexingCopyOverrides } from './copy'
6
+ import type { ProIndexingRouteMap } from './routes'
7
+
8
+ export interface ProIndexingAppConfig {
9
+ readonly routes?: ProIndexingRouteMap
10
+ readonly copy?: ProIndexingCopyOverrides
11
+ }
12
+
13
+ /** Identity function that type-checks `proIndexing` in a plain-object app.config. */
14
+ export function defineProIndexingConfig(config: ProIndexingAppConfig): ProIndexingAppConfig {
15
+ return config
16
+ }