From 8ef65d5503b75ab60bbacbeb0698b8096f913b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Fri, 4 Dec 2026 11:44:54 +0100 Subject: [PATCH] refactor(types): strip internals from the built declarations What the package marks as internal no longer ships in its declarations (`stripInternal`), such as `WebhookVerifier.receiverConfig()` and `requireInbox()`. The JavaScript is unchanged; an app can no longer call them through the types. `WebhooksModuleRootOptions`, which `forRoot()` takes, and `WebhooksModuleStructure` are now exported. CI now type-checks the built declarations, as a consumer does and with `skipLibCheck` off, so a declaration that names something stripped fails there instead of in an application. --- .github/workflows/ci.yml | 8 ++++++++ lib/index.ts | 2 ++ tests/declarations/consumer.ts | 16 ++++++++++++++++ tests/declarations/tsconfig.json | 13 +++++++++++++ tests/declarations/tsconfig.lib.json | 13 +++++++++++++ tsconfig.build.json | 1 + tsconfig.json | 3 ++- 7 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/declarations/consumer.ts create mode 100644 tests/declarations/tsconfig.json create mode 100644 tests/declarations/tsconfig.lib.json diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c85a29..7a2157a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,14 @@ jobs: cache: npm - run: npm install - run: npm run build + # Against `dist`, through the package's own `exports`, as an application sees it: + # the test expects an error on each member the package marks as internal. + - name: Typecheck the built declarations as a consumer + run: npx tsc -p tests/declarations + # With `skipLibCheck` off: a declaration that names something stripped as internal + # fails here, instead of in an application that checks its libraries. + - name: Typecheck the built declarations themselves + run: npx tsc -p tests/declarations/tsconfig.lib.json - run: npm run lint e2e: diff --git a/lib/index.ts b/lib/index.ts index c66e3bc..ffcdb2e 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -8,6 +8,8 @@ export type { WebhookRetryOptions, WebhooksModuleAsyncOptions, WebhooksModuleOptions, + WebhooksModuleRootOptions, + WebhooksModuleStructure, WebhooksOptionsFactory, WebhookWorkerOptions, } from './interfaces/index.js'; diff --git a/tests/declarations/consumer.ts b/tests/declarations/consumer.ts new file mode 100644 index 0000000..41264df --- /dev/null +++ b/tests/declarations/consumer.ts @@ -0,0 +1,16 @@ +import type { WebhookVerifier, WebhooksModuleRootOptions, WebhooksModuleStructure } from '@nestjs/webhooks'; + +// Compile-time checks against the built declarations in `dist`, as a consumer +// sees them. Verified by `tsc -p tests/declarations` after `npm run build`. + +// What `forRoot()` takes can be named by an app. +export type Named = [WebhooksModuleRootOptions, WebhooksModuleStructure]; + +// What the package marks as internal is not in its declarations. +export function internals(verifier: WebhookVerifier) { + // @ts-expect-error internal + verifier.receiverConfig('stripe'); + // @ts-expect-error internal + verifier.requireInbox(); + verifier.verify; +} diff --git a/tests/declarations/tsconfig.json b/tests/declarations/tsconfig.json new file mode 100644 index 0000000..cfda542 --- /dev/null +++ b/tests/declarations/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "NodeNext", + "target": "ES2022", + "strict": true, + "experimentalDecorators": true, + "noEmit": true, + "skipLibCheck": true, + "types": ["node"] + }, + "files": ["consumer.ts"] +} diff --git a/tests/declarations/tsconfig.lib.json b/tests/declarations/tsconfig.lib.json new file mode 100644 index 0000000..f87c5b3 --- /dev/null +++ b/tests/declarations/tsconfig.lib.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "module": "NodeNext", + "moduleResolution": "NodeNext", + "target": "ES2022", + "strict": true, + "experimentalDecorators": true, + "noEmit": true, + "skipLibCheck": false, + "types": ["node"] + }, + "files": ["../../dist/index.d.ts", "../../dist/testing/index.d.ts", "../../dist/postgres/index.d.ts", "../../dist/mysql/index.d.ts"] +} diff --git a/tsconfig.build.json b/tsconfig.build.json index 262bf11..5024ba8 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -3,6 +3,7 @@ "module": "NodeNext", "moduleResolution": "NodeNext", "declaration": true, + "stripInternal": true, "strict": true, "removeComments": false, "noLib": false, diff --git a/tsconfig.json b/tsconfig.json index f4093cd..bda4877 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -22,6 +22,7 @@ "tests/**/*" ], "exclude": [ - "node_modules" + "node_modules", + "tests/declarations" ] } \ No newline at end of file