diff --git a/src/cli/generateSpec.ts b/src/cli/generateSpec.ts index 3701b5b..0f2a08a 100644 --- a/src/cli/generateSpec.ts +++ b/src/cli/generateSpec.ts @@ -1,6 +1,7 @@ import { writeFile } from 'node:fs/promises' import path from 'node:path' +import type { CLICommand } from 'payload' import { strictObject, z } from 'payload' import { defineCLICommand } from 'payload/cli' @@ -10,7 +11,7 @@ import type { ResolvedOptions } from '@/shared/types/index.js' const optionalString = (description: string) => z.optional(z.string()).check(z.describe(description)) -export const generateSpecCommand = defineCLICommand({ +export const generateSpecCommand: CLICommand = defineCLICommand({ description: 'Write the OpenAPI document to a file.', input: strictObject({ lang: optionalString( diff --git a/src/index.ts b/src/index.ts index f95f9ca..7984425 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,6 @@ import { fileURLToPath } from 'node:url' +import type { Plugin } from 'payload' import { definePlugin } from 'payload' import { interactiveAuthHandler } from '@/server/endpoints/interactiveAuth.js' @@ -19,7 +20,7 @@ const resolveCommandPath = (): string => { return `${fileURLToPath(new URL(`./cli/generateSpec${ext}`, selfUrl))}#generateSpecCommand` } -export const openapi = definePlugin({ +export const openapi: (options: OpenApiPluginOptions) => Plugin = definePlugin({ slug: PLUGIN_NAME, plugin: ({ config, options, plugins }) => { const resolved = resolveOptions(options) diff --git a/src/server/spec/fields.ts b/src/server/spec/fields.ts index 218eef9..553ca35 100644 --- a/src/server/spec/fields.ts +++ b/src/server/spec/fields.ts @@ -2,7 +2,7 @@ import type { Field, NamedTab } from 'payload' export const isHiddenField = (field: Field): boolean => 'hidden' in field && field.hidden === true -export const AUTH_FIELDS = new Set([ +export const AUTH_FIELDS: Set = new Set([ 'salt', 'hash', 'password', diff --git a/src/server/ui/createUiPlugin.ts b/src/server/ui/createUiPlugin.ts index 3aec3e2..8c1a29f 100644 --- a/src/server/ui/createUiPlugin.ts +++ b/src/server/ui/createUiPlugin.ts @@ -1,3 +1,4 @@ +import type { Plugin } from 'payload' import { definePlugin, Forbidden } from 'payload' import { assertNoRemovedKeys } from '@/server/options/resolveOptions.js' @@ -19,7 +20,7 @@ export interface UiPluginSpec { render: (args: UiRenderArgs) => string } -export const createUiPlugin = (spec: UiPluginSpec) => +export const createUiPlugin = (spec: UiPluginSpec): ((options?: UiPluginOptions) => Plugin) => definePlugin({ slug: spec.slug, plugin: ({ config, options = {} }) => { diff --git a/src/server/ui/scalar.ts b/src/server/ui/scalar.ts index 52ed1a9..31cd279 100644 --- a/src/server/ui/scalar.ts +++ b/src/server/ui/scalar.ts @@ -1,11 +1,14 @@ +import type { Plugin } from 'payload' + import { SCALAR_PLUGIN_NAME } from '@/shared/constants.js' +import type { UiPluginOptions } from '@/shared/types/index.js' import { createUiPlugin } from './createUiPlugin.js' import { escapeHtml, htmlPage, integrityAttrs, jsonForScript, specUrlExpr } from './html.js' const SCRIPT_INTEGRITY = 'sha384-omTRdD9MbjA1vm12DqRUVvqJlr3VzSixvAdF1Jruu9AJOiJKyTKraIB6DyX+m10M' -export const scalar = createUiPlugin({ +export const scalar: (options?: UiPluginOptions) => Plugin = createUiPlugin({ slug: SCALAR_PLUGIN_NAME, defaultDocsUrl: '/docs', defaultCdnBase: 'https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.72.4/dist/browser/standalone.js', diff --git a/src/server/ui/swagger.ts b/src/server/ui/swagger.ts index 2189d9d..ae41ec2 100644 --- a/src/server/ui/swagger.ts +++ b/src/server/ui/swagger.ts @@ -1,4 +1,7 @@ +import type { Plugin } from 'payload' + import { SWAGGER_UI_PLUGIN_NAME } from '@/shared/constants.js' +import type { UiPluginOptions } from '@/shared/types/index.js' import { createUiPlugin } from './createUiPlugin.js' import { escapeHtml, htmlPage, integrityAttrs, jsonForScript, specUrlExpr } from './html.js' @@ -6,7 +9,7 @@ import { escapeHtml, htmlPage, integrityAttrs, jsonForScript, specUrlExpr } from const STYLE_INTEGRITY = 'sha384-Ov4/wv3j2bmct8cDc5X4ngJZohVPzEmc6uDPH8WeljUxO5vtoykvMEfbu9Vh6RaW' const SCRIPT_INTEGRITY = 'sha384-ZPehFMQommnnuaZ4rpxgkgTT2DKFVp4hZC/7pLit+9Lek9T1YGSo23eHFbvNkXkw' -export const swaggerUi = createUiPlugin({ +export const swaggerUi: (options?: UiPluginOptions) => Plugin = createUiPlugin({ slug: SWAGGER_UI_PLUGIN_NAME, defaultDocsUrl: '/docs', defaultCdnBase: 'https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.33.1', diff --git a/src/shared/constants.ts b/src/shared/constants.ts index 021aeb2..188081d 100644 --- a/src/shared/constants.ts +++ b/src/shared/constants.ts @@ -1,3 +1,3 @@ export const PLUGIN_NAME = '@seshuk/payload-plugin-openapi' -export const SCALAR_PLUGIN_NAME = `${PLUGIN_NAME}/scalar` -export const SWAGGER_UI_PLUGIN_NAME = `${PLUGIN_NAME}/swagger-ui` +export const SCALAR_PLUGIN_NAME: `${typeof PLUGIN_NAME}/scalar` = `${PLUGIN_NAME}/scalar` +export const SWAGGER_UI_PLUGIN_NAME: `${typeof PLUGIN_NAME}/swagger-ui` = `${PLUGIN_NAME}/swagger-ui` diff --git a/tsconfig.build.json b/tsconfig.build.json index a89dd00..69d4592 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -4,7 +4,10 @@ "jsx": "react-jsx", "rootDir": "./src", "outDir": "./dist", - "noEmit": false + "noEmit": false, + "declaration": true, + "isolatedDeclarations": true, + "allowJs": false }, "include": ["./src/**/*.ts", "./src/**/*.tsx"], "exclude": ["./tests"]