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
3 changes: 2 additions & 1 deletion src/cli/generateSpec.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -19,7 +20,7 @@ const resolveCommandPath = (): string => {
return `${fileURLToPath(new URL(`./cli/generateSpec${ext}`, selfUrl))}#generateSpecCommand`
}

export const openapi = definePlugin<OpenApiPluginOptions>({
export const openapi: (options: OpenApiPluginOptions) => Plugin = definePlugin<OpenApiPluginOptions>({
slug: PLUGIN_NAME,
plugin: ({ config, options, plugins }) => {
const resolved = resolveOptions(options)
Expand Down
2 changes: 1 addition & 1 deletion src/server/spec/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> = new Set([
'salt',
'hash',
'password',
Expand Down
3 changes: 2 additions & 1 deletion src/server/ui/createUiPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Plugin } from 'payload'
import { definePlugin, Forbidden } from 'payload'

import { assertNoRemovedKeys } from '@/server/options/resolveOptions.js'
Expand All @@ -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<UiPluginOptions | undefined>({
slug: spec.slug,
plugin: ({ config, options = {} }) => {
Expand Down
5 changes: 4 additions & 1 deletion src/server/ui/scalar.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
5 changes: 4 additions & 1 deletion src/server/ui/swagger.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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'

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',
Expand Down
4 changes: 2 additions & 2 deletions src/shared/constants.ts
Original file line number Diff line number Diff line change
@@ -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`
5 changes: 4 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Loading