@citec-spbu/jwt 1.0.4 → 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.
Files changed (39) hide show
  1. package/dist/consumer.module.d.ts +6 -0
  2. package/dist/consumer.module.js +29 -0
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +2 -2
  5. package/dist/interfaces/index.d.ts +0 -4
  6. package/dist/interfaces/index.js +0 -4
  7. package/dist/issuer.module.d.ts +6 -0
  8. package/dist/issuer.module.js +30 -0
  9. package/package.json +1 -1
  10. package/dist/constants/consumer.constants.d.ts +0 -1
  11. package/dist/constants/consumer.constants.js +0 -4
  12. package/dist/constants/index.d.ts +0 -2
  13. package/dist/constants/index.js +0 -18
  14. package/dist/constants/issuer.constants.d.ts +0 -1
  15. package/dist/constants/issuer.constants.js +0 -4
  16. package/dist/consumer/consumer.module.d.ts +0 -6
  17. package/dist/consumer/consumer.module.js +0 -101
  18. package/dist/consumer/consumer.provider.d.ts +0 -4
  19. package/dist/consumer/consumer.provider.js +0 -24
  20. package/dist/consumer/consumer.service.d.ts +0 -8
  21. package/dist/consumer/consumer.service.js +0 -66
  22. package/dist/consumer/index.d.ts +0 -3
  23. package/dist/consumer/index.js +0 -19
  24. package/dist/interfaces/consumer-async-options.interface.d.ts +0 -6
  25. package/dist/interfaces/consumer-async-options.interface.js +0 -2
  26. package/dist/interfaces/consumer-options.interface.d.ts +0 -3
  27. package/dist/interfaces/consumer-options.interface.js +0 -2
  28. package/dist/interfaces/issuer-async-options.interface.d.ts +0 -6
  29. package/dist/interfaces/issuer-async-options.interface.js +0 -2
  30. package/dist/interfaces/issuer-options.interface.d.ts +0 -3
  31. package/dist/interfaces/issuer-options.interface.js +0 -2
  32. package/dist/issuer/index.d.ts +0 -3
  33. package/dist/issuer/index.js +0 -19
  34. package/dist/issuer/issuer.module.d.ts +0 -6
  35. package/dist/issuer/issuer.module.js +0 -102
  36. package/dist/issuer/issuer.provider.d.ts +0 -4
  37. package/dist/issuer/issuer.provider.js +0 -24
  38. package/dist/issuer/issuer.service.d.ts +0 -8
  39. package/dist/issuer/issuer.service.js +0 -66
@@ -0,0 +1,6 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+ export interface ConsumerModuleOptions {
3
+ publicKey: string;
4
+ }
5
+ export declare function createConsumerModule(options: ConsumerModuleOptions): DynamicModule;
6
+ export declare function createConsumerModuleAsync(useFactory: (...args: any[]) => Promise<ConsumerModuleOptions> | ConsumerModuleOptions, inject?: any[]): DynamicModule;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createConsumerModule = createConsumerModule;
4
+ exports.createConsumerModuleAsync = createConsumerModuleAsync;
5
+ const jwt_1 = require("@nestjs/jwt");
6
+ const VERIFY_OPTIONS = {
7
+ algorithms: ["RS256"],
8
+ issuer: "auth-service",
9
+ audience: "gateway-service"
10
+ };
11
+ function createConsumerModule(options) {
12
+ const jwtOptions = {
13
+ publicKey: options.publicKey,
14
+ verifyOptions: VERIFY_OPTIONS
15
+ };
16
+ return jwt_1.JwtModule.register(jwtOptions);
17
+ }
18
+ function createConsumerModuleAsync(useFactory, inject) {
19
+ return jwt_1.JwtModule.registerAsync({
20
+ useFactory: async (...args) => {
21
+ const options = await useFactory(...args);
22
+ return {
23
+ publicKey: options.publicKey,
24
+ verifyOptions: VERIFY_OPTIONS
25
+ };
26
+ },
27
+ inject: inject || []
28
+ });
29
+ }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./issuer";
2
- export * from "./consumer";
1
+ export * from "./issuer.module";
2
+ export * from "./consumer.module";
3
3
  export * from "./interfaces";
package/dist/index.js CHANGED
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./issuer"), exports);
18
- __exportStar(require("./consumer"), exports);
17
+ __exportStar(require("./issuer.module"), exports);
18
+ __exportStar(require("./consumer.module"), exports);
19
19
  __exportStar(require("./interfaces"), exports);
@@ -1,5 +1 @@
1
1
  export * from "./token.interface";
2
- export * from "./issuer-options.interface";
3
- export * from "./issuer-async-options.interface";
4
- export * from "./consumer-options.interface";
5
- export * from "./consumer-async-options.interface";
@@ -15,7 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./token.interface"), exports);
18
- __exportStar(require("./issuer-options.interface"), exports);
19
- __exportStar(require("./issuer-async-options.interface"), exports);
20
- __exportStar(require("./consumer-options.interface"), exports);
21
- __exportStar(require("./consumer-async-options.interface"), exports);
@@ -0,0 +1,6 @@
1
+ import { DynamicModule } from "@nestjs/common";
2
+ export interface IssuerModuleOptions {
3
+ privateKey: string;
4
+ }
5
+ export declare function createIssuerModule(options: IssuerModuleOptions): DynamicModule;
6
+ export declare function createIssuerModuleAsync(useFactory: (...args: any[]) => Promise<IssuerModuleOptions> | IssuerModuleOptions, inject?: any[]): DynamicModule;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createIssuerModule = createIssuerModule;
4
+ exports.createIssuerModuleAsync = createIssuerModuleAsync;
5
+ const jwt_1 = require("@nestjs/jwt");
6
+ const SIGN_OPTIONS = {
7
+ algorithm: "RS256",
8
+ issuer: "auth-service",
9
+ audience: "gateway-service",
10
+ keyid: "auth.v1"
11
+ };
12
+ function createIssuerModule(options) {
13
+ const jwtOptions = {
14
+ privateKey: options.privateKey,
15
+ signOptions: SIGN_OPTIONS
16
+ };
17
+ return jwt_1.JwtModule.register(jwtOptions);
18
+ }
19
+ function createIssuerModuleAsync(useFactory, inject) {
20
+ return jwt_1.JwtModule.registerAsync({
21
+ useFactory: async (...args) => {
22
+ const options = await useFactory(...args);
23
+ return {
24
+ privateKey: options.privateKey,
25
+ signOptions: SIGN_OPTIONS
26
+ };
27
+ },
28
+ inject: inject || []
29
+ });
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@citec-spbu/jwt",
3
- "version": "1.0.4",
3
+ "version": "1.1.0",
4
4
  "description": "Lightweight auth lib",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -1 +0,0 @@
1
- export declare const CONSUMER_OPTIONS: unique symbol;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONSUMER_OPTIONS = void 0;
4
- exports.CONSUMER_OPTIONS = Symbol("ConsumerOptions");
@@ -1,2 +0,0 @@
1
- export * from "./issuer.constants";
2
- export * from "./consumer.constants";
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./issuer.constants"), exports);
18
- __exportStar(require("./consumer.constants"), exports);
@@ -1 +0,0 @@
1
- export declare const ISSUER_OPTIONS: unique symbol;
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ISSUER_OPTIONS = void 0;
4
- exports.ISSUER_OPTIONS = Symbol("IssuerOptions");
@@ -1,6 +0,0 @@
1
- import { DynamicModule } from "@nestjs/common";
2
- import { ConsumerAsyncOptions, ConsumerOptions } from "../interfaces";
3
- export declare class ConsumerModule {
4
- static register(options: ConsumerOptions): DynamicModule;
5
- static registerAsync(options: ConsumerAsyncOptions): DynamicModule;
6
- }
@@ -1,101 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.ConsumerModule = void 0;
38
- const common_1 = require("@nestjs/common");
39
- const jwt_1 = require("@nestjs/jwt");
40
- const constants_1 = require("../constants");
41
- const consumer_provider_1 = require("./consumer.provider");
42
- const consumer_service_1 = require("./consumer.service");
43
- const JWT_VERIFY_OPTIONS = {
44
- algorithms: ["RS256"],
45
- issuer: "auth-service",
46
- audience: "gateway-service"
47
- };
48
- let ConsumerModule = (() => {
49
- let _classDecorators = [(0, common_1.Global)(), (0, common_1.Module)({})];
50
- let _classDescriptor;
51
- let _classExtraInitializers = [];
52
- let _classThis;
53
- var ConsumerModule = class {
54
- static { _classThis = this; }
55
- static {
56
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
57
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
58
- ConsumerModule = _classThis = _classDescriptor.value;
59
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
60
- __runInitializers(_classThis, _classExtraInitializers);
61
- }
62
- static register(options) {
63
- const optionsProvider = (0, consumer_provider_1.createConsumerOptionsProvider)(options);
64
- return {
65
- module: ConsumerModule,
66
- imports: [
67
- jwt_1.JwtModule.register({
68
- publicKey: options.publicKey,
69
- signOptions: JWT_VERIFY_OPTIONS
70
- })
71
- ],
72
- providers: [optionsProvider, consumer_service_1.ConsumerService],
73
- exports: [consumer_service_1.ConsumerService, constants_1.CONSUMER_OPTIONS]
74
- };
75
- }
76
- static registerAsync(options) {
77
- const optionsProvider = (0, consumer_provider_1.createConsumerAsyncOptionsProvider)(options);
78
- return {
79
- module: ConsumerModule,
80
- imports: [
81
- ...(options.imports || []),
82
- jwt_1.JwtModule.registerAsync({
83
- imports: options.imports || [],
84
- useFactory: async (...args) => {
85
- const consumerOptions = await options.useFactory(...args);
86
- return {
87
- publicKey: consumerOptions.publicKey,
88
- signOptions: JWT_VERIFY_OPTIONS
89
- };
90
- },
91
- inject: options.inject ?? []
92
- })
93
- ],
94
- providers: [optionsProvider, consumer_service_1.ConsumerService],
95
- exports: [consumer_service_1.ConsumerService, constants_1.CONSUMER_OPTIONS]
96
- };
97
- }
98
- };
99
- return ConsumerModule = _classThis;
100
- })();
101
- exports.ConsumerModule = ConsumerModule;
@@ -1,4 +0,0 @@
1
- import { Provider } from "@nestjs/common";
2
- import { ConsumerAsyncOptions, ConsumerOptions } from "../interfaces";
3
- export declare function createConsumerOptionsProvider(options: ConsumerOptions): Provider;
4
- export declare function createConsumerAsyncOptionsProvider(options: ConsumerAsyncOptions): Provider;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createConsumerOptionsProvider = createConsumerOptionsProvider;
4
- exports.createConsumerAsyncOptionsProvider = createConsumerAsyncOptionsProvider;
5
- const constants_1 = require("../constants");
6
- function createConsumerOptionsProvider(options) {
7
- return {
8
- provide: constants_1.CONSUMER_OPTIONS,
9
- useValue: Object.freeze({ ...options })
10
- };
11
- }
12
- function createConsumerAsyncOptionsProvider(options) {
13
- return {
14
- provide: constants_1.CONSUMER_OPTIONS,
15
- useFactory: async (...args) => {
16
- const resolved = await options.useFactory(...args);
17
- if (!resolved || typeof resolved.publicKey !== "string") {
18
- throw new Error(`[ConsumerModule] "publicKey" is required and must be a string`);
19
- }
20
- return Object.freeze({ ...resolved });
21
- },
22
- inject: options.inject ?? []
23
- };
24
- }
@@ -1,8 +0,0 @@
1
- import { JwtService, JwtVerifyOptions } from "@nestjs/jwt";
2
- import { TokenPayload } from "../interfaces";
3
- export declare class ConsumerService {
4
- private readonly jwtService;
5
- constructor(jwtService: JwtService);
6
- verify(token: string, options?: JwtVerifyOptions): TokenPayload;
7
- verifyAsync(token: string, options?: JwtVerifyOptions): Promise<TokenPayload>;
8
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.ConsumerService = void 0;
38
- const common_1 = require("@nestjs/common");
39
- let ConsumerService = (() => {
40
- let _classDecorators = [(0, common_1.Injectable)()];
41
- let _classDescriptor;
42
- let _classExtraInitializers = [];
43
- let _classThis;
44
- var ConsumerService = class {
45
- static { _classThis = this; }
46
- static {
47
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
48
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
49
- ConsumerService = _classThis = _classDescriptor.value;
50
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
51
- __runInitializers(_classThis, _classExtraInitializers);
52
- }
53
- jwtService;
54
- constructor(jwtService) {
55
- this.jwtService = jwtService;
56
- }
57
- verify(token, options) {
58
- return this.jwtService.verify(token, options);
59
- }
60
- verifyAsync(token, options) {
61
- return this.jwtService.verifyAsync(token, options);
62
- }
63
- };
64
- return ConsumerService = _classThis;
65
- })();
66
- exports.ConsumerService = ConsumerService;
@@ -1,3 +0,0 @@
1
- export * from "./consumer.module";
2
- export * from "./consumer.service";
3
- export * from "./consumer.provider";
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./consumer.module"), exports);
18
- __exportStar(require("./consumer.service"), exports);
19
- __exportStar(require("./consumer.provider"), exports);
@@ -1,6 +0,0 @@
1
- import type { FactoryProvider, ModuleMetadata } from "@nestjs/common";
2
- import type { ConsumerOptions } from "./consumer-options.interface";
3
- export interface ConsumerAsyncOptions extends Pick<ModuleMetadata, "imports"> {
4
- useFactory?: (...args: any[]) => Promise<ConsumerOptions> | ConsumerOptions;
5
- inject?: FactoryProvider["inject"];
6
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- export interface ConsumerOptions {
2
- publicKey: string;
3
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +0,0 @@
1
- import type { FactoryProvider, ModuleMetadata } from "@nestjs/common";
2
- import type { IssuerOptions } from "./issuer-options.interface";
3
- export interface IssuerAsyncOptions extends Pick<ModuleMetadata, "imports"> {
4
- useFactory?: (...args: any[]) => Promise<IssuerOptions> | IssuerOptions;
5
- inject?: FactoryProvider["inject"];
6
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- export interface IssuerOptions {
2
- privateKey: string;
3
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- export * from "./issuer.module";
2
- export * from "./issuer.service";
3
- export * from "./issuer.provider";
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./issuer.module"), exports);
18
- __exportStar(require("./issuer.service"), exports);
19
- __exportStar(require("./issuer.provider"), exports);
@@ -1,6 +0,0 @@
1
- import { DynamicModule } from "@nestjs/common";
2
- import { IssuerAsyncOptions, IssuerOptions } from "../interfaces";
3
- export declare class IssuerModule {
4
- static register(options: IssuerOptions): DynamicModule;
5
- static registerAsync(options: IssuerAsyncOptions): DynamicModule;
6
- }
@@ -1,102 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.IssuerModule = void 0;
38
- const common_1 = require("@nestjs/common");
39
- const jwt_1 = require("@nestjs/jwt");
40
- const constants_1 = require("../constants");
41
- const issuer_provider_1 = require("./issuer.provider");
42
- const issuer_service_1 = require("./issuer.service");
43
- const JWT_SIGN_OPTIONS = {
44
- algorithm: "RS256",
45
- issuer: "auth-service",
46
- audience: "gateway-service",
47
- keyid: "auth.v1"
48
- };
49
- let IssuerModule = (() => {
50
- let _classDecorators = [(0, common_1.Global)(), (0, common_1.Module)({})];
51
- let _classDescriptor;
52
- let _classExtraInitializers = [];
53
- let _classThis;
54
- var IssuerModule = class {
55
- static { _classThis = this; }
56
- static {
57
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
58
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
59
- IssuerModule = _classThis = _classDescriptor.value;
60
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
61
- __runInitializers(_classThis, _classExtraInitializers);
62
- }
63
- static register(options) {
64
- const optionsProvider = (0, issuer_provider_1.createIssuerOptionsProvider)(options);
65
- return {
66
- module: IssuerModule,
67
- imports: [
68
- jwt_1.JwtModule.register({
69
- privateKey: options.privateKey,
70
- signOptions: JWT_SIGN_OPTIONS
71
- })
72
- ],
73
- providers: [optionsProvider, issuer_service_1.IssuerService],
74
- exports: [issuer_service_1.IssuerService, constants_1.ISSUER_OPTIONS]
75
- };
76
- }
77
- static registerAsync(options) {
78
- const optionsProvider = (0, issuer_provider_1.createIssuerAsyncOptionsProvider)(options);
79
- return {
80
- module: IssuerModule,
81
- imports: [
82
- ...(options.imports || []),
83
- jwt_1.JwtModule.registerAsync({
84
- imports: options.imports || [],
85
- useFactory: async (...args) => {
86
- const issuerOptions = await options.useFactory(...args);
87
- return {
88
- privateKey: issuerOptions.privateKey,
89
- signOptions: JWT_SIGN_OPTIONS
90
- };
91
- },
92
- inject: options.inject ?? []
93
- })
94
- ],
95
- providers: [optionsProvider, issuer_service_1.IssuerService],
96
- exports: [issuer_service_1.IssuerService, constants_1.ISSUER_OPTIONS]
97
- };
98
- }
99
- };
100
- return IssuerModule = _classThis;
101
- })();
102
- exports.IssuerModule = IssuerModule;
@@ -1,4 +0,0 @@
1
- import { Provider } from "@nestjs/common";
2
- import { IssuerAsyncOptions, IssuerOptions } from "../interfaces";
3
- export declare function createIssuerOptionsProvider(options: IssuerOptions): Provider;
4
- export declare function createIssuerAsyncOptionsProvider(options: IssuerAsyncOptions): Provider;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createIssuerOptionsProvider = createIssuerOptionsProvider;
4
- exports.createIssuerAsyncOptionsProvider = createIssuerAsyncOptionsProvider;
5
- const constants_1 = require("../constants");
6
- function createIssuerOptionsProvider(options) {
7
- return {
8
- provide: constants_1.ISSUER_OPTIONS,
9
- useValue: Object.freeze({ ...options })
10
- };
11
- }
12
- function createIssuerAsyncOptionsProvider(options) {
13
- return {
14
- provide: constants_1.ISSUER_OPTIONS,
15
- useFactory: async (...args) => {
16
- const resolved = await options.useFactory(...args);
17
- if (!resolved || typeof resolved.privateKey !== "string") {
18
- throw new Error(`[IssuerModule] "privateKey" is required and must be a string`);
19
- }
20
- return Object.freeze({ ...resolved });
21
- },
22
- inject: options.inject ?? []
23
- };
24
- }
@@ -1,8 +0,0 @@
1
- import { JwtService, JwtSignOptions } from "@nestjs/jwt";
2
- import { TokenPayload } from "../interfaces";
3
- export declare class IssuerService {
4
- private readonly jwtService;
5
- constructor(jwtService: JwtService);
6
- sign(payload: TokenPayload, options?: JwtSignOptions): string;
7
- signAsync(payload: TokenPayload, options?: JwtSignOptions): Promise<string>;
8
- }
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
- function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
- var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
5
- var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
6
- var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
7
- var _, done = false;
8
- for (var i = decorators.length - 1; i >= 0; i--) {
9
- var context = {};
10
- for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
11
- for (var p in contextIn.access) context.access[p] = contextIn.access[p];
12
- context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
13
- var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
14
- if (kind === "accessor") {
15
- if (result === void 0) continue;
16
- if (result === null || typeof result !== "object") throw new TypeError("Object expected");
17
- if (_ = accept(result.get)) descriptor.get = _;
18
- if (_ = accept(result.set)) descriptor.set = _;
19
- if (_ = accept(result.init)) initializers.unshift(_);
20
- }
21
- else if (_ = accept(result)) {
22
- if (kind === "field") initializers.unshift(_);
23
- else descriptor[key] = _;
24
- }
25
- }
26
- if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
- done = true;
28
- };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.IssuerService = void 0;
38
- const common_1 = require("@nestjs/common");
39
- let IssuerService = (() => {
40
- let _classDecorators = [(0, common_1.Injectable)()];
41
- let _classDescriptor;
42
- let _classExtraInitializers = [];
43
- let _classThis;
44
- var IssuerService = class {
45
- static { _classThis = this; }
46
- static {
47
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
48
- __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
49
- IssuerService = _classThis = _classDescriptor.value;
50
- if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
51
- __runInitializers(_classThis, _classExtraInitializers);
52
- }
53
- jwtService;
54
- constructor(jwtService) {
55
- this.jwtService = jwtService;
56
- }
57
- sign(payload, options) {
58
- return this.jwtService.sign(payload, options);
59
- }
60
- signAsync(payload, options) {
61
- return this.jwtService.signAsync(payload, options);
62
- }
63
- };
64
- return IssuerService = _classThis;
65
- })();
66
- exports.IssuerService = IssuerService;