diff --git a/package.json b/package.json index 328c80a..7c26b92 100644 --- a/package.json +++ b/package.json @@ -3,17 +3,14 @@ "version": "8.2.0", "description": "Fastify CORS", "main": "index.js", - "types": "index.d.ts", + "types": "types/index.d.ts", "scripts": { "coverage": "tap --cov --coverage-report=html test", - "lint": "npm run lint:standard && npm run lint:typescript", + "lint": "standard", "lint:fix": "standard --fix", - "lint:standard": "standard", - "lint:typescript": "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin test/*.ts", - "test": "npm run unit && npm run typescript", - "test:ci": "npm run lint && tap test/*.test.js --coverage-report=lcovonly && npm run typescript", - "typescript": "tsd", - "unit": "tap test/*.test.js" + "test": "npm run test:unit && npm run test:typescript", + "test:typescript": "tsd", + "test:unit": "tap test/*.test.js" }, "keywords": [ "fastify", diff --git a/test/named-import.test-d.ts b/test/named-import.test-d.ts deleted file mode 100644 index b327a5e..0000000 --- a/test/named-import.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import fastify from 'fastify' -import { fastifyCors } from '..' - -const app = fastify() - -app.register(fastifyCors) diff --git a/index.d.ts b/types/index.d.ts similarity index 97% rename from index.d.ts rename to types/index.d.ts index 03cceb1..ab4b577 100644 --- a/index.d.ts +++ b/types/index.d.ts @@ -22,7 +22,7 @@ type FastifyCorsHook = | 'onSend' declare namespace fastifyCors { - export type OriginFunction = (origin: string, callback: OriginCallback) => void; + export type OriginFunction = (origin: string | undefined, callback: OriginCallback) => void; export interface FastifyCorsOptions { /** diff --git a/test/index.test-d.ts b/types/index.test-d.ts similarity index 98% rename from test/index.test-d.ts rename to types/index.test-d.ts index 38e69cb..97ff24d 100644 --- a/test/index.test-d.ts +++ b/types/index.test-d.ts @@ -1,4 +1,5 @@ import fastify from 'fastify' +import { expectType } from 'tsd' import fastifyCors, { FastifyCorsOptionsDelegate, FastifyCorsOptionsDelegatePromise, @@ -310,3 +311,10 @@ appHttp2.register(fastifyCors, { }) appHttp2.register(fastifyCors, delegate) + +appHttp2.register(fastifyCors, { + hook: 'preParsing', + origin: function (origin) { + expectType(origin) + }, +})