Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default defineNuxtConfig({
documentIdParam: 'document_id',
backLink: '/',
backLinkText: 'Back to dashboard',
showBackLink: true,
buttonColor: '#4f46e5',
buttonHoverColor: '#4338ca',
showDocument: true,
Expand Down Expand Up @@ -112,6 +113,7 @@ All response fields are treated as strings except the validity flag. If a status
| `logo` | Logo URL displayed at the top of the page | `/logo.png` |
| `verificationEndpoint` | API endpoint that validates a document | **required** |
| `backLink` / `backLinkText` | Destination + label for the back button | `'/'` / `'Back to Home'` |
| `showBackLink` | Toggle visibility of the back button | `true` |
| `buttonColor` / `buttonHoverColor` | Primary button colours | `#4f46e5` / `#4338ca` |
| `fields` | Array describing the detail rows (label, key, type, optional resolver) | Built-in defaults |
| `showDocument` | Toggle document image section (hides it entirely when `false`) | `true` |
Expand Down Expand Up @@ -153,6 +155,8 @@ Only fields that resolve to a non-empty value are rendered. `type: 'status'` als

When `showDocument` is `false`, the asset block is skipped altogether even if the API responds with a URL. Use `showDocumentTitle` to hide the heading while keeping the preview itself, or override `displayTitle` to customise the heading copy. Set `displayType` to `'image'` or `'pdf'` when you know the asset format; otherwise the component falls back to inferring it from the URL (still supporting PDF detection). The `displayField` can point to an image or a PDF; PDFs render inside the viewer with a fallback link.

Turn off the footer back button entirely by setting `showBackLink: false`.

```ts
documentVerification: {
// ...
Expand Down
3 changes: 3 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// https://nuxt.com/docs/api/configuration/nuxt-config
import { defineNuxtConfig } from 'nuxt/config'

export default defineNuxtConfig({
modules: ['../nuxt'],
documentVerification: {
logo: '/document-icon.png',
verificationEndpoint: '/api/verify-document',
backLink: '/',
backLinkText: 'Back to Home',
showBackLink: false,
buttonColor: '#4f46e5',
buttonHoverColor: '#4338ca',
fields: [
Expand Down
7 changes: 7 additions & 0 deletions playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["nuxt"]
},
"include": ["../src/types/**/*.d.ts", "./**/*"]
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import type { DocumentVerificationConfig } from '../runtime/composables/types'
import type { DocumentVerificationConfig } from '../../src/runtime/composables/types'

declare module '@nuxt/schema' {
declare module 'nuxt/schema' {
interface NuxtConfig {
documentVerification?: DocumentVerificationConfig
}

interface PublicRuntimeConfig {
documentVerification: DocumentVerificationConfig
}
Expand Down
3 changes: 1 addition & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import './types/runtime-config'

import { defineNuxtModule, createResolver, addComponent, addImportsDir, addPlugin } from '@nuxt/kit'
import type { DocumentVerificationConfig } from './runtime/composables/types'
import { BASE_FIELD_DEFINITIONS } from './runtime/composables/constants'
Expand All @@ -17,6 +15,7 @@ export default defineNuxtModule<DocumentVerificationConfig>({
verificationEndpoint: '/api/verify-document',
backLink: '/',
backLinkText: 'Back to Home',
showBackLink: true,
buttonColor: '#4f46e5',
buttonHoverColor: '#4338ca',
fields: BASE_FIELD_DEFINITIONS,
Expand Down
6 changes: 5 additions & 1 deletion src/runtime/components/DocumentFooter.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="dv-footer">
<div v-if="showBackLink" class="dv-footer">
<a :href="backLink" class="dv-footer__link">{{ backLinkText }}</a>
</div>
</template>
Expand All @@ -15,5 +15,9 @@ defineProps({
type: String,
required: true,
},
showBackLink: {
type: Boolean,
default: true,
},
})
</script>
7 changes: 6 additions & 1 deletion src/runtime/components/DocumentVerification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
/>
</div>

<DocumentFooter :back-link="config.backLink" :back-link-text="config.backLinkText" />
<DocumentFooter
v-if="config.showBackLink !== false"
:back-link="config.backLink"
:back-link-text="config.backLinkText"
:show-back-link="config.showBackLink"
/>
</div>
</template>

Expand Down
1 change: 1 addition & 0 deletions src/runtime/composables/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface DocumentVerificationConfig {
verificationEndpoint: string
backLink: string
backLinkText: string
showBackLink?: boolean
buttonColor: string
buttonHoverColor: string
fields?: FieldDefinition[]
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/composables/useDocumentVerification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const useDocumentVerification = () => {
const cfg = $documentVerification as DocumentVerificationConfig
const route = useRoute()
const documentIdParam = cfg.documentIdParam || DEFAULT_DOCUMENT_ID_PARAM
const showBackLink = cfg.showBackLink ?? true
const showDocument = cfg.showDocument ?? true
const displayTitle = cfg.displayTitle ?? 'Document Preview'
const showDocumentTitle = cfg.showDocumentTitle ?? true
Expand All @@ -40,6 +41,7 @@ export const useDocumentVerification = () => {
const resolvedConfig: DocumentVerificationConfig = {
...cfg,
documentIdParam,
showBackLink,
showDocument,
showDocumentTitle,
displayTitle,
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/plugins/document-verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default defineNuxtPlugin<{ documentVerification: DocumentVerificationConf
}

const documentIdParam = moduleConfig.documentIdParam ?? DEFAULT_DOCUMENT_ID_PARAM
const showBackLink = moduleConfig.showBackLink ?? true
const showDocument = moduleConfig.showDocument ?? true
const displayTitle = moduleConfig.displayTitle ?? 'Document Preview'
const showDocumentTitle = moduleConfig.showDocumentTitle ?? true
Expand All @@ -26,6 +27,7 @@ export default defineNuxtPlugin<{ documentVerification: DocumentVerificationConf
const normalizedConfig: DocumentVerificationConfig = {
...moduleConfig,
documentIdParam,
showBackLink,
showDocument,
displayTitle,
showDocumentTitle,
Expand Down
33 changes: 33 additions & 0 deletions src/types/runtime-config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { DocumentVerificationConfig } from '../runtime/composables/types'

// Augment both 'nuxt/schema' and '@nuxt/schema' to ensure TS picks it up in different setups

declare module 'nuxt/schema' {
interface NuxtConfig {
documentVerification?: DocumentVerificationConfig
}

interface NuxtOptions {
documentVerification?: DocumentVerificationConfig
}

interface PublicRuntimeConfig {
documentVerification: DocumentVerificationConfig
}
}

declare module '@nuxt/schema' {
interface NuxtConfig {
documentVerification?: DocumentVerificationConfig
}

interface NuxtOptions {
documentVerification?: DocumentVerificationConfig
}

interface PublicRuntimeConfig {
documentVerification: DocumentVerificationConfig
}
}

export {}
11 changes: 10 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@
"esModuleInterop": true,
"skipLibCheck": true,
"resolveJsonModule": true,

"declaration": true,
"emitDeclarationOnly": true,
"outDir": "./dist",
"declarationMap": false,

"sourceMap": true,

"paths": {
"#app": ["./src/types/nuxt-app.d.ts"],
"@nuxt/schema": ["./node_modules/nuxt/schema"],
"nuxt/app": ["./node_modules/nuxt/app"],
"nuxt/dist/app/*": ["./node_modules/nuxt/dist/app/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts"]
"include": ["src/**/*.ts", "src/**/*.d.ts", "types/**/*.d.ts"],
"exclude": ["node_modules", "dist", "playground"]
}