@nest-boot/hash 7.0.1 → 7.0.2

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.
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Configuration options for the HashModule.
3
+ */
1
4
  export interface HashModuleOptions {
5
+ /**
6
+ * The secret key used for hashing.
7
+ * If not provided, falls back to HASH_SECRET or APP_SECRET environment variables.
8
+ */
2
9
  secret?: string;
3
10
  }
@@ -1,8 +1,2 @@
1
1
  import { type HashModuleOptions } from "./hash-module-options.interface";
2
- export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<HashModuleOptions, "register", "create", {
3
- isGlobal: boolean;
4
- }>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: HashModuleOptions & Partial<{
5
- isGlobal: boolean;
6
- }>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<HashModuleOptions, "create"> & Partial<{
7
- isGlobal: boolean;
8
- }>;
2
+ export declare const ConfigurableModuleClass: import("@nestjs/common").ConfigurableModuleCls<HashModuleOptions, "register", "create", {}>, MODULE_OPTIONS_TOKEN: string | symbol, OPTIONS_TYPE: HashModuleOptions & Partial<{}>, ASYNC_OPTIONS_TYPE: import("@nestjs/common").ConfigurableModuleAsyncOptions<HashModuleOptions, "create"> & Partial<{}>;
@@ -3,12 +3,5 @@ var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.ASYNC_OPTIONS_TYPE = exports.OPTIONS_TYPE = exports.MODULE_OPTIONS_TOKEN = exports.ConfigurableModuleClass = void 0;
5
5
  const common_1 = require("@nestjs/common");
6
- _a = new common_1.ConfigurableModuleBuilder()
7
- .setExtras({
8
- isGlobal: false,
9
- }, (definition, extras) => ({
10
- ...definition,
11
- global: extras.isGlobal,
12
- }))
13
- .build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
6
+ _a = new common_1.ConfigurableModuleBuilder().build(), exports.ConfigurableModuleClass = _a.ConfigurableModuleClass, exports.MODULE_OPTIONS_TOKEN = _a.MODULE_OPTIONS_TOKEN, exports.OPTIONS_TYPE = _a.OPTIONS_TYPE, exports.ASYNC_OPTIONS_TYPE = _a.ASYNC_OPTIONS_TYPE;
14
7
  //# sourceMappingURL=hash.module-definition.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.module-definition.js","sourceRoot":"","sources":["../src/hash.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAI9C,KAKT,IAAI,kCAAyB,EAAqB;KACnD,SAAS,CACR;IACE,QAAQ,EAAE,KAAK;CAChB,EACD,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACvB,GAAG,UAAU;IACb,MAAM,EAAE,MAAM,CAAC,QAAQ;CACxB,CAAC,CACH;KACA,KAAK,EAAE,EAdR,+BAAuB,+BACvB,4BAAoB,4BACpB,oBAAY,oBACZ,0BAAkB,yBAWT"}
1
+ {"version":3,"file":"hash.module-definition.js","sourceRoot":"","sources":["../src/hash.module-definition.ts"],"names":[],"mappings":";;;;AAAA,2CAA2D;AAI9C,KAKT,IAAI,kCAAyB,EAAqB,CAAC,KAAK,EAAE,EAJ5D,+BAAuB,+BACvB,4BAAoB,4BACpB,oBAAY,oBACZ,0BAAkB,yBAC2C"}
@@ -1,3 +1,34 @@
1
- import { ConfigurableModuleClass } from "./hash.module-definition";
1
+ import { type DynamicModule } from "@nestjs/common";
2
+ import { ASYNC_OPTIONS_TYPE, ConfigurableModuleClass, OPTIONS_TYPE } from "./hash.module-definition";
3
+ /**
4
+ * Module that provides password hashing services using Argon2.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { HashModule } from '@nest-boot/hash';
9
+ *
10
+ * @Module({
11
+ * imports: [
12
+ * HashModule.register({
13
+ * secret: 'your-secret-key',
14
+ * isGlobal: true,
15
+ * }),
16
+ * ],
17
+ * })
18
+ * export class AppModule {}
19
+ * ```
20
+ */
2
21
  export declare class HashModule extends ConfigurableModuleClass {
22
+ /**
23
+ * Registers the HashModule with the given options.
24
+ * @param options - Configuration options including secret and isGlobal
25
+ * @returns Dynamic module configuration
26
+ */
27
+ static register(options: typeof OPTIONS_TYPE): DynamicModule;
28
+ /**
29
+ * Registers the HashModule asynchronously with factory functions.
30
+ * @param options - Async configuration options
31
+ * @returns Dynamic module configuration
32
+ */
33
+ static registerAsync(options: typeof ASYNC_OPTIONS_TYPE): DynamicModule;
3
34
  }
@@ -10,10 +10,45 @@ exports.HashModule = void 0;
10
10
  const common_1 = require("@nestjs/common");
11
11
  const hash_module_definition_1 = require("./hash.module-definition");
12
12
  const hash_service_1 = require("./hash.service");
13
+ /**
14
+ * Module that provides password hashing services using Argon2.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { HashModule } from '@nest-boot/hash';
19
+ *
20
+ * @Module({
21
+ * imports: [
22
+ * HashModule.register({
23
+ * secret: 'your-secret-key',
24
+ * isGlobal: true,
25
+ * }),
26
+ * ],
27
+ * })
28
+ * export class AppModule {}
29
+ * ```
30
+ */
13
31
  let HashModule = class HashModule extends hash_module_definition_1.ConfigurableModuleClass {
32
+ /**
33
+ * Registers the HashModule with the given options.
34
+ * @param options - Configuration options including secret and isGlobal
35
+ * @returns Dynamic module configuration
36
+ */
37
+ static register(options) {
38
+ return super.register(options);
39
+ }
40
+ /**
41
+ * Registers the HashModule asynchronously with factory functions.
42
+ * @param options - Async configuration options
43
+ * @returns Dynamic module configuration
44
+ */
45
+ static registerAsync(options) {
46
+ return super.registerAsync(options);
47
+ }
14
48
  };
15
49
  exports.HashModule = HashModule;
16
50
  exports.HashModule = HashModule = __decorate([
51
+ (0, common_1.Global)(),
17
52
  (0, common_1.Module)({ providers: [hash_service_1.HashService], exports: [hash_service_1.HashService] })
18
53
  ], HashModule);
19
54
  //# sourceMappingURL=hash.module.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hash.module.js","sourceRoot":"","sources":["../src/hash.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AAExC,qEAAmE;AACnE,iDAA6C;AAGtC,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,gDAAuB;CAAG,CAAA;AAA7C,gCAAU;qBAAV,UAAU;IADtB,IAAA,eAAM,EAAC,EAAE,SAAS,EAAE,CAAC,0BAAW,CAAC,EAAE,OAAO,EAAE,CAAC,0BAAW,CAAC,EAAE,CAAC;GAChD,UAAU,CAAmC"}
1
+ {"version":3,"file":"hash.module.js","sourceRoot":"","sources":["../src/hash.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAoE;AAEpE,qEAIkC;AAClC,iDAA6C;AAE7C;;;;;;;;;;;;;;;;;GAiBG;AAGI,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,gDAAuB;IACrD;;;;OAIG;IACH,MAAM,CAAU,QAAQ,CAAC,OAA4B;QACnD,OAAO,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAU,aAAa,CAC3B,OAAkC;QAElC,OAAO,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;CACF,CAAA;AApBY,gCAAU;qBAAV,UAAU;IAFtB,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,SAAS,EAAE,CAAC,0BAAW,CAAC,EAAE,OAAO,EAAE,CAAC,0BAAW,CAAC,EAAE,CAAC;GAChD,UAAU,CAoBtB"}
@@ -1,8 +1,45 @@
1
1
  import { HashModuleOptions } from "./hash-module-options.interface";
2
+ /**
3
+ * Service that provides password hashing and verification using Argon2 algorithm.
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * import { HashService } from '@nest-boot/hash';
8
+ *
9
+ * @Injectable()
10
+ * export class AuthService {
11
+ * constructor(private readonly hashService: HashService) {}
12
+ *
13
+ * async hashPassword(password: string): Promise<string> {
14
+ * return this.hashService.create(password);
15
+ * }
16
+ *
17
+ * async verifyPassword(hash: string, password: string): Promise<boolean> {
18
+ * return this.hashService.verify(hash, password);
19
+ * }
20
+ * }
21
+ * ```
22
+ */
2
23
  export declare class HashService {
3
- private readonly options;
4
24
  private readonly secret?;
25
+ /**
26
+ * Creates an instance of HashService.
27
+ * @param options - Configuration options for the hash service
28
+ */
5
29
  constructor(options?: HashModuleOptions);
30
+ /**
31
+ * Creates a hash from the given value using Argon2.
32
+ * @param value - The value to hash (password or other sensitive data)
33
+ * @param secret - Optional secret key to use instead of the default
34
+ * @returns The hashed string
35
+ */
6
36
  create(value: string | Buffer, secret?: string): Promise<string>;
37
+ /**
38
+ * Verifies a value against a hash.
39
+ * @param hashed - The hash to verify against
40
+ * @param value - The value to verify
41
+ * @param secret - Optional secret key to use instead of the default
42
+ * @returns True if the value matches the hash, false otherwise
43
+ */
7
44
  verify(hashed: string | Buffer, value: string | Buffer, secret?: string): Promise<boolean>;
8
45
  }
@@ -16,19 +16,56 @@ exports.HashService = void 0;
16
16
  const common_1 = require("@nestjs/common");
17
17
  const argon2_1 = require("@node-rs/argon2");
18
18
  const hash_module_definition_1 = require("./hash.module-definition");
19
+ /**
20
+ * Service that provides password hashing and verification using Argon2 algorithm.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { HashService } from '@nest-boot/hash';
25
+ *
26
+ * @Injectable()
27
+ * export class AuthService {
28
+ * constructor(private readonly hashService: HashService) {}
29
+ *
30
+ * async hashPassword(password: string): Promise<string> {
31
+ * return this.hashService.create(password);
32
+ * }
33
+ *
34
+ * async verifyPassword(hash: string, password: string): Promise<boolean> {
35
+ * return this.hashService.verify(hash, password);
36
+ * }
37
+ * }
38
+ * ```
39
+ */
19
40
  let HashService = class HashService {
41
+ /**
42
+ * Creates an instance of HashService.
43
+ * @param options - Configuration options for the hash service
44
+ */
20
45
  constructor(options = {}) {
21
- this.options = options;
22
46
  const secret = options.secret ?? process.env.HASH_SECRET ?? process.env.APP_SECRET;
23
47
  if (secret) {
24
48
  this.secret = Buffer.from(secret);
25
49
  }
26
50
  }
51
+ /**
52
+ * Creates a hash from the given value using Argon2.
53
+ * @param value - The value to hash (password or other sensitive data)
54
+ * @param secret - Optional secret key to use instead of the default
55
+ * @returns The hashed string
56
+ */
27
57
  async create(value, secret) {
28
58
  return await (0, argon2_1.hash)(value, {
29
59
  secret: typeof secret !== "undefined" ? Buffer.from(secret) : this.secret,
30
60
  });
31
61
  }
62
+ /**
63
+ * Verifies a value against a hash.
64
+ * @param hashed - The hash to verify against
65
+ * @param value - The value to verify
66
+ * @param secret - Optional secret key to use instead of the default
67
+ * @returns True if the value matches the hash, false otherwise
68
+ */
32
69
  async verify(hashed, value, secret) {
33
70
  return await (0, argon2_1.verify)(hashed, value, {
34
71
  secret: typeof secret !== "undefined" ? Buffer.from(secret) : this.secret,
@@ -1 +1 @@
1
- {"version":3,"file":"hash.service.js","sourceRoot":"","sources":["../src/hash.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA8D;AAC9D,4CAA+C;AAE/C,qEAAgE;AAIzD,IAAM,WAAW,GAAjB,MAAM,WAAW;IAGtB,YAGmB,UAA6B,EAAE;QAA/B,YAAO,GAAP,OAAO,CAAwB;QAEhD,MAAM,MAAM,GACV,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;QAEtE,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAsB,EAAE,MAAe;QAClD,OAAO,MAAM,IAAA,aAAI,EAAC,KAAK,EAAE;YACvB,MAAM,EAAE,OAA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KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM;SAC1E,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,CACV,MAAuB,EACvB,KAAsB,EACtB,MAAe;QAEf,OAAO,MAAM,IAAA,eAAM,EAAC,MAAM,EAAE,KAAK,EAAE;YACjC,MAAM,EAAE,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM;SAC1E,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAhDY,kCAAW;sBAAX,WAAW;IADvB,IAAA,mBAAU,GAAE;IASR,WAAA,IAAA,iBAAQ,GAAE,CAAA;IACV,WAAA,IAAA,eAAM,EAAC,6CAAoB,CAAC,CAAA;;GATpB,WAAW,CAgDvB"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./hash.module";
2
2
  export * from "./hash.service";
3
+ export * from "./hash-module-options.interface";
package/dist/index.js CHANGED
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./hash.module"), exports);
18
18
  __exportStar(require("./hash.service"), exports);
19
+ __exportStar(require("./hash-module-options.interface"), exports);
19
20
  //# 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,gDAA8B;AAC9B,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,iDAA+B;AAC/B,kEAAgD"}