nesthub 1.0.3 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './typeorm';
2
2
  export * from './cache';
3
3
  export * from './queue';
4
4
  export * from './notification';
5
+ export * from './swagger';
package/dist/index.js CHANGED
@@ -18,4 +18,5 @@ __exportStar(require("./typeorm"), exports);
18
18
  __exportStar(require("./cache"), exports);
19
19
  __exportStar(require("./queue"), exports);
20
20
  __exportStar(require("./notification"), exports);
21
+ __exportStar(require("./swagger"), exports);
21
22
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,0CAAwB;AACxB,0CAAwB;AACxB,iDAA+B;AAC/B,4CAA0B"}
@@ -0,0 +1,53 @@
1
+ # @nesthub/swagger
2
+
3
+ Scalar API reference for NestJS — powered by `@scalar/nestjs-api-reference`.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @nestjs/swagger @scalar/nestjs-api-reference
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { NestFactory } from '@nestjs/core';
15
+ import { setupSwaggerUI } from 'nesthub/swagger';
16
+ import { AppModule } from './app.module';
17
+
18
+ async function bootstrap() {
19
+ const app = await NestFactory.create(AppModule);
20
+
21
+ setupSwaggerUI(app, {
22
+ title: 'My API',
23
+ description: 'API documentation',
24
+ version: '1.0.0',
25
+ persistAuth: true,
26
+ serverUrl: 'http://localhost:3000',
27
+ });
28
+
29
+ await app.listen(3000);
30
+ }
31
+ ```
32
+
33
+ ## Options
34
+
35
+ | Option | Type | Default | Description |
36
+ |--------|------|---------|-------------|
37
+ | `path` | `string` | `'api-docs'` | Path to serve Scalar |
38
+ | `title` | `string` | `'API Documentation'` | API title |
39
+ | `description` | `string` | `''` | API description |
40
+ | `version` | `string` | `'1.0'` | API version |
41
+ | `persistAuth` | `boolean` | `false` | Persist auth in localStorage |
42
+ | `serverUrl` | `string` | `undefined` | Server URL |
43
+ | `serverDescription` | `string` | `undefined` | Server description |
44
+
45
+ ## Content Security Policy
46
+
47
+ Scalar loads UI assets from `https://cdn.jsdelivr.net` and uses inline scripts. If your app sets a `Content-Security-Policy` header, update `script-src` to allow:
48
+
49
+ ```http
50
+ Content-Security-Policy: script-src 'self' https://cdn.jsdelivr.net 'unsafe-inline'; style-src 'self' 'unsafe-inline'
51
+ ```
52
+
53
+ For stricter security, use a nonce or hash (the hash changes per Scalar version — generate it from the inline script content or pin a specific version).
@@ -0,0 +1,2 @@
1
+ export type { SwaggerSetupOptions } from './swagger.interfaces.js';
2
+ export { setupSwaggerUI } from './swagger-setup.js';
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupSwaggerUI = void 0;
4
+ var swagger_setup_js_1 = require("./swagger-setup.js");
5
+ Object.defineProperty(exports, "setupSwaggerUI", { enumerable: true, get: function () { return swagger_setup_js_1.setupSwaggerUI; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/swagger/index.ts"],"names":[],"mappings":";;;AACA,uDAAoD;AAA3C,kHAAA,cAAc,OAAA"}
@@ -0,0 +1,3 @@
1
+ import type { INestApplication } from '@nestjs/common';
2
+ import type { SwaggerSetupOptions } from './swagger.interfaces.js';
3
+ export declare function setupSwaggerUI(app: INestApplication, options: SwaggerSetupOptions): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setupSwaggerUI = setupSwaggerUI;
4
+ const swagger_1 = require("@nestjs/swagger");
5
+ const nestjs_api_reference_1 = require("@scalar/nestjs-api-reference");
6
+ function setupSwaggerUI(app, options) {
7
+ const path = (options.path || 'api-docs').replace(/^\/+|\/+$/g, '');
8
+ const config = new swagger_1.DocumentBuilder()
9
+ .setTitle(options.title || 'API Documentation')
10
+ .setDescription(options.description || '')
11
+ .setVersion(options.version || '1.0');
12
+ if (options.serverUrl) {
13
+ config.addServer(options.serverUrl, options.serverDescription);
14
+ }
15
+ const document = swagger_1.SwaggerModule.createDocument(app, config.build());
16
+ app.use(`/${path}`, (0, nestjs_api_reference_1.apiReference)({
17
+ content: document,
18
+ ...(options.persistAuth && { persistAuth: true }),
19
+ }));
20
+ }
21
+ //# sourceMappingURL=swagger-setup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swagger-setup.js","sourceRoot":"","sources":["../../src/swagger/swagger-setup.ts"],"names":[],"mappings":";;AAKA,wCAwBC;AA5BD,6CAAiE;AACjE,uEAA4D;AAG5D,SAAgB,cAAc,CAC5B,GAAqB,EACrB,OAA4B;IAE5B,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,IAAI,UAAU,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;IAEpE,MAAM,MAAM,GAAG,IAAI,yBAAe,EAAE;SACjC,QAAQ,CAAC,OAAO,CAAC,KAAK,IAAI,mBAAmB,CAAC;SAC9C,cAAc,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC;SACzC,UAAU,CAAC,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC;IAExC,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,QAAQ,GAAG,uBAAa,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;IAEnE,GAAG,CAAC,GAAG,CACL,IAAI,IAAI,EAAE,EACV,IAAA,mCAAY,EAAC;QACX,OAAO,EAAE,QAAQ;QACjB,GAAG,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;KAClD,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ export interface SwaggerSetupOptions {
2
+ path?: string;
3
+ title?: string;
4
+ description?: string;
5
+ version?: string;
6
+ serverUrl?: string;
7
+ serverDescription?: string;
8
+ persistAuth?: boolean;
9
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=swagger.interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swagger.interfaces.js","sourceRoot":"","sources":["../../src/swagger/swagger.interfaces.ts"],"names":[],"mappings":""}