@navios/jwt 0.5.0 → 0.7.1

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,9 +1,22 @@
1
1
  import type { Secret as JwtSecret } from 'jsonwebtoken';
2
2
  import { z } from 'zod/v4';
3
+ /**
4
+ * Request type for secret or key provider functions.
5
+ *
6
+ * Used to distinguish between signing and verification operations when
7
+ * dynamically resolving secrets or keys.
8
+ */
3
9
  export declare enum RequestType {
10
+ /** Request is for signing a token */
4
11
  Sign = "Sign",
12
+ /** Request is for verifying a token */
5
13
  Verify = "Verify"
6
14
  }
15
+ /**
16
+ * Supported JWT algorithms.
17
+ *
18
+ * Includes symmetric (HMAC) and asymmetric (RSA, ECDSA, EdDSA) algorithms.
19
+ */
7
20
  export declare const AlgorithmType: z.ZodEnum<{
8
21
  HS256: "HS256";
9
22
  HS384: "HS384";
@@ -19,6 +32,11 @@ export declare const AlgorithmType: z.ZodEnum<{
19
32
  PS512: "PS512";
20
33
  none: "none";
21
34
  }>;
35
+ /**
36
+ * JWT header schema.
37
+ *
38
+ * Defines the structure of the JWT header with standard claims.
39
+ */
22
40
  export declare const JwtHeaderSchema: z.ZodObject<{
23
41
  alg: z.ZodUnion<[z.ZodEnum<{
24
42
  HS256: "HS256";
@@ -45,7 +63,18 @@ export declare const JwtHeaderSchema: z.ZodObject<{
45
63
  x5t: z.ZodOptional<z.ZodString>;
46
64
  x5c: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
47
65
  }, z.core.$strip>;
66
+ /**
67
+ * JWT header type.
68
+ *
69
+ * Contains algorithm, type, and optional header claims.
70
+ */
48
71
  export type JwtHeader = z.infer<typeof JwtHeaderSchema>;
72
+ /**
73
+ * Schema for JWT signing options.
74
+ *
75
+ * Defines all available options for signing tokens including algorithm,
76
+ * expiration, audience, issuer, and other standard JWT claims.
77
+ */
49
78
  export declare const SignOptionsSchema: z.ZodObject<{
50
79
  algorithm: z.ZodOptional<z.ZodEnum<{
51
80
  HS256: "HS256";
@@ -101,7 +130,18 @@ export declare const SignOptionsSchema: z.ZodObject<{
101
130
  allowInsecureKeySizes: z.ZodOptional<z.ZodBoolean>;
102
131
  allowInvalidAsymmetricKeyTypes: z.ZodOptional<z.ZodBoolean>;
103
132
  }, z.core.$strip>;
133
+ /**
134
+ * Options for signing JWT tokens.
135
+ *
136
+ * @see SignOptionsSchema for the complete schema definition
137
+ */
104
138
  export type SignOptions = z.infer<typeof SignOptionsSchema>;
139
+ /**
140
+ * Schema for JWT verification options.
141
+ *
142
+ * Defines all available options for verifying tokens including allowed
143
+ * algorithms, audience, issuer, expiration handling, and other validation rules.
144
+ */
105
145
  export declare const VerifyOptionsSchema: z.ZodObject<{
106
146
  algorithms: z.ZodOptional<z.ZodArray<z.ZodEnum<{
107
147
  HS256: "HS256";
@@ -131,13 +171,28 @@ export declare const VerifyOptionsSchema: z.ZodObject<{
131
171
  maxAge: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
132
172
  allowInvalidAsymmetricKeyTypes: z.ZodOptional<z.ZodBoolean>;
133
173
  }, z.core.$strip>;
174
+ /**
175
+ * Options for verifying JWT tokens.
176
+ *
177
+ * @see VerifyOptionsSchema for the complete schema definition
178
+ */
134
179
  export type VerifyOptions = z.infer<typeof VerifyOptionsSchema>;
180
+ /**
181
+ * Schema for JWT secret/key types.
182
+ *
183
+ * Supports string secrets, Buffer objects, and key objects with passphrases.
184
+ */
135
185
  export declare const SecretSchema: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>, z.ZodObject<{
136
186
  type: z.ZodString;
137
187
  }, z.core.$loose>, z.ZodObject<{
138
188
  key: z.ZodUnion<readonly [z.ZodString, z.ZodCustom<Buffer<ArrayBufferLike>, Buffer<ArrayBufferLike>>]>;
139
189
  passphrase: z.ZodString;
140
190
  }, z.core.$strip>]>;
191
+ /**
192
+ * Secret or key type for JWT operations.
193
+ *
194
+ * Can be a string, Buffer, or an object with key and optional passphrase.
195
+ */
141
196
  export type Secret = z.infer<typeof SecretSchema>;
142
197
  export declare const JwtServiceOptionsSchema: z.ZodObject<{
143
198
  signOptions: z.ZodOptional<z.ZodObject<{
@@ -326,14 +381,65 @@ export declare const JwtServiceOptionsSchema: z.ZodObject<{
326
381
  passphrase: z.ZodString;
327
382
  }, z.core.$strip>]>>]>>>;
328
383
  }, z.core.$strip>;
384
+ /**
385
+ * Configuration options for the JWT service.
386
+ *
387
+ * @property signOptions - Default options for signing tokens
388
+ * @property secret - Default secret for symmetric algorithms (HS256, HS384, HS512)
389
+ * @property publicKey - Default public key for asymmetric algorithms (RS256, ES256, etc.)
390
+ * @property privateKey - Default private key for asymmetric algorithms
391
+ * @property verifyOptions - Default options for verifying tokens
392
+ * @property secretOrKeyProvider - Optional function to dynamically resolve secrets/keys
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * const options: JwtServiceOptions = {
397
+ * secret: 'your-secret-key',
398
+ * signOptions: {
399
+ * expiresIn: '1h',
400
+ * algorithm: 'HS256',
401
+ * },
402
+ * verifyOptions: {
403
+ * algorithms: ['HS256'],
404
+ * },
405
+ * }
406
+ * ```
407
+ */
329
408
  export type JwtServiceOptions = z.infer<typeof JwtServiceOptionsSchema>;
409
+ /**
410
+ * Options for signing JWT tokens.
411
+ *
412
+ * Extends `SignOptions` with additional properties for specifying
413
+ * the secret or private key to use for signing.
414
+ *
415
+ * @property secret - Secret key for symmetric algorithms (overrides service default)
416
+ * @property privateKey - Private key for asymmetric algorithms (overrides service default)
417
+ */
330
418
  export interface JwtSignOptions extends SignOptions {
419
+ /** Secret key for symmetric algorithms */
331
420
  secret?: string | Buffer;
421
+ /** Private key for asymmetric algorithms */
332
422
  privateKey?: Secret;
333
423
  }
424
+ /**
425
+ * Options for verifying JWT tokens.
426
+ *
427
+ * Extends `VerifyOptions` with additional properties for specifying
428
+ * the secret or public key to use for verification.
429
+ *
430
+ * @property secret - Secret key for symmetric algorithms (overrides service default)
431
+ * @property publicKey - Public key for asymmetric algorithms (overrides service default)
432
+ */
334
433
  export interface JwtVerifyOptions extends VerifyOptions {
434
+ /** Secret key for symmetric algorithms */
335
435
  secret?: string | Buffer;
436
+ /** Public key for asymmetric algorithms */
336
437
  publicKey?: string | Buffer;
337
438
  }
439
+ /**
440
+ * Result type for secret/key resolution.
441
+ *
442
+ * Represents the possible return types from secret or key provider functions.
443
+ */
338
444
  export type GetSecretKeyResult = string | Buffer | JwtSecret;
339
445
  //# sourceMappingURL=jwt-service.options.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jwt-service.options.d.mts","sourceRoot":"","sources":["../../../src/options/jwt-service.options.mts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,cAAc,CAAA;AAEvD,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA;AAE1B,oBAAY,WAAW;IACrB,IAAI,SAAS;IACb,MAAM,WAAW;CAClB;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;;;;EAcxB,CAAA;AAEF,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;iBAW1B,CAAA;AAEF,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAA;AAEvD,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqB5B,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAA;AAE3D,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAoB9B,CAAA;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAE/D,eAAO,MAAM,YAAY;;;;;mBAYvB,CAAA;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