@warlock.js/auth 4.0.31 → 4.0.41

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 (169) hide show
  1. package/cjs/index.js +725 -1
  2. package/cjs/index.js.map +1 -1
  3. package/esm/index.js +705 -1
  4. package/esm/index.js.map +1 -1
  5. package/package.json +48 -34
  6. package/cjs/commands/auth-cleanup-command.d.ts +0 -10
  7. package/cjs/commands/auth-cleanup-command.d.ts.map +0 -1
  8. package/cjs/commands/auth-cleanup-command.js +0 -29
  9. package/cjs/commands/auth-cleanup-command.js.map +0 -1
  10. package/cjs/commands/jwt-secret-generator-command.d.ts +0 -2
  11. package/cjs/commands/jwt-secret-generator-command.d.ts.map +0 -1
  12. package/cjs/commands/jwt-secret-generator-command.js +0 -7
  13. package/cjs/commands/jwt-secret-generator-command.js.map +0 -1
  14. package/cjs/contracts/auth-contract.d.ts +0 -23
  15. package/cjs/contracts/auth-contract.d.ts.map +0 -1
  16. package/cjs/contracts/index.d.ts +0 -3
  17. package/cjs/contracts/index.d.ts.map +0 -1
  18. package/cjs/contracts/types.d.ts +0 -134
  19. package/cjs/contracts/types.d.ts.map +0 -1
  20. package/cjs/contracts/types.js +0 -20
  21. package/cjs/contracts/types.js.map +0 -1
  22. package/cjs/index.d.ts +0 -8
  23. package/cjs/index.d.ts.map +0 -1
  24. package/cjs/middleware/auth.middleware.d.ts +0 -2
  25. package/cjs/middleware/auth.middleware.d.ts.map +0 -1
  26. package/cjs/middleware/auth.middleware.js +0 -73
  27. package/cjs/middleware/auth.middleware.js.map +0 -1
  28. package/cjs/middleware/index.d.ts +0 -2
  29. package/cjs/middleware/index.d.ts.map +0 -1
  30. package/cjs/models/access-token/access-token.d.ts +0 -12
  31. package/cjs/models/access-token/access-token.d.ts.map +0 -1
  32. package/cjs/models/access-token/access-token.js +0 -16
  33. package/cjs/models/access-token/access-token.js.map +0 -1
  34. package/cjs/models/access-token/index.d.ts +0 -3
  35. package/cjs/models/access-token/index.d.ts.map +0 -1
  36. package/cjs/models/access-token/migration.d.ts +0 -3
  37. package/cjs/models/access-token/migration.d.ts.map +0 -1
  38. package/cjs/models/access-token/migration.js +0 -10
  39. package/cjs/models/access-token/migration.js.map +0 -1
  40. package/cjs/models/auth.d.ts +0 -47
  41. package/cjs/models/auth.d.ts.map +0 -1
  42. package/cjs/models/auth.js +0 -58
  43. package/cjs/models/auth.js.map +0 -1
  44. package/cjs/models/casts/cast-password.d.ts +0 -7
  45. package/cjs/models/casts/cast-password.d.ts.map +0 -1
  46. package/cjs/models/casts/cast-password.js +0 -9
  47. package/cjs/models/casts/cast-password.js.map +0 -1
  48. package/cjs/models/casts/index.d.ts +0 -2
  49. package/cjs/models/casts/index.d.ts.map +0 -1
  50. package/cjs/models/index.d.ts +0 -5
  51. package/cjs/models/index.d.ts.map +0 -1
  52. package/cjs/models/refresh-token/index.d.ts +0 -2
  53. package/cjs/models/refresh-token/index.d.ts.map +0 -1
  54. package/cjs/models/refresh-token/migration.d.ts +0 -3
  55. package/cjs/models/refresh-token/migration.d.ts.map +0 -1
  56. package/cjs/models/refresh-token/refresh-token.d.ts +0 -32
  57. package/cjs/models/refresh-token/refresh-token.d.ts.map +0 -1
  58. package/cjs/models/refresh-token/refresh-token.js +0 -52
  59. package/cjs/models/refresh-token/refresh-token.js.map +0 -1
  60. package/cjs/services/auth-events.d.ts +0 -84
  61. package/cjs/services/auth-events.d.ts.map +0 -1
  62. package/cjs/services/auth-events.js +0 -65
  63. package/cjs/services/auth-events.js.map +0 -1
  64. package/cjs/services/auth.service.d.ts +0 -78
  65. package/cjs/services/auth.service.d.ts.map +0 -1
  66. package/cjs/services/auth.service.js +0 -265
  67. package/cjs/services/auth.service.js.map +0 -1
  68. package/cjs/services/generate-jwt-secret.d.ts +0 -2
  69. package/cjs/services/generate-jwt-secret.d.ts.map +0 -1
  70. package/cjs/services/generate-jwt-secret.js +0 -26
  71. package/cjs/services/generate-jwt-secret.js.map +0 -1
  72. package/cjs/services/index.d.ts +0 -5
  73. package/cjs/services/index.d.ts.map +0 -1
  74. package/cjs/services/jwt.d.ts +0 -23
  75. package/cjs/services/jwt.d.ts.map +0 -1
  76. package/cjs/services/jwt.js +0 -39
  77. package/cjs/services/jwt.js.map +0 -1
  78. package/cjs/utils/auth-error-codes.d.ts +0 -18
  79. package/cjs/utils/auth-error-codes.d.ts.map +0 -1
  80. package/cjs/utils/auth-error-codes.js +0 -18
  81. package/cjs/utils/auth-error-codes.js.map +0 -1
  82. package/cjs/utils/duration.d.ts +0 -45
  83. package/cjs/utils/duration.d.ts.map +0 -1
  84. package/cjs/utils/duration.js +0 -93
  85. package/cjs/utils/duration.js.map +0 -1
  86. package/cjs/utils/index.d.ts +0 -3
  87. package/cjs/utils/index.d.ts.map +0 -1
  88. package/esm/commands/auth-cleanup-command.d.ts +0 -10
  89. package/esm/commands/auth-cleanup-command.d.ts.map +0 -1
  90. package/esm/commands/auth-cleanup-command.js +0 -29
  91. package/esm/commands/auth-cleanup-command.js.map +0 -1
  92. package/esm/commands/jwt-secret-generator-command.d.ts +0 -2
  93. package/esm/commands/jwt-secret-generator-command.d.ts.map +0 -1
  94. package/esm/commands/jwt-secret-generator-command.js +0 -7
  95. package/esm/commands/jwt-secret-generator-command.js.map +0 -1
  96. package/esm/contracts/auth-contract.d.ts +0 -23
  97. package/esm/contracts/auth-contract.d.ts.map +0 -1
  98. package/esm/contracts/index.d.ts +0 -3
  99. package/esm/contracts/index.d.ts.map +0 -1
  100. package/esm/contracts/types.d.ts +0 -134
  101. package/esm/contracts/types.d.ts.map +0 -1
  102. package/esm/contracts/types.js +0 -20
  103. package/esm/contracts/types.js.map +0 -1
  104. package/esm/index.d.ts +0 -8
  105. package/esm/index.d.ts.map +0 -1
  106. package/esm/middleware/auth.middleware.d.ts +0 -2
  107. package/esm/middleware/auth.middleware.d.ts.map +0 -1
  108. package/esm/middleware/auth.middleware.js +0 -73
  109. package/esm/middleware/auth.middleware.js.map +0 -1
  110. package/esm/middleware/index.d.ts +0 -2
  111. package/esm/middleware/index.d.ts.map +0 -1
  112. package/esm/models/access-token/access-token.d.ts +0 -12
  113. package/esm/models/access-token/access-token.d.ts.map +0 -1
  114. package/esm/models/access-token/access-token.js +0 -16
  115. package/esm/models/access-token/access-token.js.map +0 -1
  116. package/esm/models/access-token/index.d.ts +0 -3
  117. package/esm/models/access-token/index.d.ts.map +0 -1
  118. package/esm/models/access-token/migration.d.ts +0 -3
  119. package/esm/models/access-token/migration.d.ts.map +0 -1
  120. package/esm/models/access-token/migration.js +0 -10
  121. package/esm/models/access-token/migration.js.map +0 -1
  122. package/esm/models/auth.d.ts +0 -47
  123. package/esm/models/auth.d.ts.map +0 -1
  124. package/esm/models/auth.js +0 -58
  125. package/esm/models/auth.js.map +0 -1
  126. package/esm/models/casts/cast-password.d.ts +0 -7
  127. package/esm/models/casts/cast-password.d.ts.map +0 -1
  128. package/esm/models/casts/cast-password.js +0 -9
  129. package/esm/models/casts/cast-password.js.map +0 -1
  130. package/esm/models/casts/index.d.ts +0 -2
  131. package/esm/models/casts/index.d.ts.map +0 -1
  132. package/esm/models/index.d.ts +0 -5
  133. package/esm/models/index.d.ts.map +0 -1
  134. package/esm/models/refresh-token/index.d.ts +0 -2
  135. package/esm/models/refresh-token/index.d.ts.map +0 -1
  136. package/esm/models/refresh-token/migration.d.ts +0 -3
  137. package/esm/models/refresh-token/migration.d.ts.map +0 -1
  138. package/esm/models/refresh-token/refresh-token.d.ts +0 -32
  139. package/esm/models/refresh-token/refresh-token.d.ts.map +0 -1
  140. package/esm/models/refresh-token/refresh-token.js +0 -52
  141. package/esm/models/refresh-token/refresh-token.js.map +0 -1
  142. package/esm/services/auth-events.d.ts +0 -84
  143. package/esm/services/auth-events.d.ts.map +0 -1
  144. package/esm/services/auth-events.js +0 -65
  145. package/esm/services/auth-events.js.map +0 -1
  146. package/esm/services/auth.service.d.ts +0 -78
  147. package/esm/services/auth.service.d.ts.map +0 -1
  148. package/esm/services/auth.service.js +0 -265
  149. package/esm/services/auth.service.js.map +0 -1
  150. package/esm/services/generate-jwt-secret.d.ts +0 -2
  151. package/esm/services/generate-jwt-secret.d.ts.map +0 -1
  152. package/esm/services/generate-jwt-secret.js +0 -26
  153. package/esm/services/generate-jwt-secret.js.map +0 -1
  154. package/esm/services/index.d.ts +0 -5
  155. package/esm/services/index.d.ts.map +0 -1
  156. package/esm/services/jwt.d.ts +0 -23
  157. package/esm/services/jwt.d.ts.map +0 -1
  158. package/esm/services/jwt.js +0 -39
  159. package/esm/services/jwt.js.map +0 -1
  160. package/esm/utils/auth-error-codes.d.ts +0 -18
  161. package/esm/utils/auth-error-codes.d.ts.map +0 -1
  162. package/esm/utils/auth-error-codes.js +0 -18
  163. package/esm/utils/auth-error-codes.js.map +0 -1
  164. package/esm/utils/duration.d.ts +0 -45
  165. package/esm/utils/duration.d.ts.map +0 -1
  166. package/esm/utils/duration.js +0 -93
  167. package/esm/utils/duration.js.map +0 -1
  168. package/esm/utils/index.d.ts +0 -3
  169. package/esm/utils/index.d.ts.map +0 -1
@@ -1,23 +0,0 @@
1
- import { type SignerOptions, type VerifierOptions } from "fast-jwt";
2
- export declare const jwt: {
3
- /**
4
- * Generate a new JWT token for the user.
5
- * @param payload The payload to encode in the JWT token.
6
- */
7
- generate(payload: any, { key, algorithm, ...options }?: any): Promise<string>;
8
- /**
9
- * Verify the given token.
10
- * @param token The JWT token to verify.
11
- * @returns The decoded token payload if verification is successful.
12
- */
13
- verify<T = any>(token: string, { key, algorithms, ...options }?: any): Promise<T>;
14
- /**
15
- * Generate a new refresh token for the user.
16
- */
17
- generateRefreshToken(payload: any, { key, expiresIn, algorithm, ...options }?: any): Promise<string>;
18
- /**
19
- * Verify the given refresh token.
20
- */
21
- verifyRefreshToken<T_1 = any>(token: string, { key, algorithms, ...options }?: any): Promise<T_1>;
22
- };
23
- //# sourceMappingURL=jwt.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../../src/services/jwt.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,eAAe,EACrB,MAAM,UAAU,CAAC;AASlB,eAAO,MAAM,GAAG;IACd;;;OAGG;sBAEQ,GAAG,yCAMX,QAAQ,MAAM,CAAC;IAOlB;;;;OAIG;2BAEM,MAAM;IAYf;;OAEG;kCAEQ,GAAG,oDAOX,QAAQ,MAAM,CAAC;IAKlB;;OAEG;yCAEM,MAAM;CAUhB,CAAC"}
@@ -1,39 +0,0 @@
1
- import {config}from'@warlock.js/core';import {createSigner,createVerifier}from'fast-jwt';const getSecretKey = () => config.key("auth.jwt.secret");
2
- const getAlgorithm = () => config.key("auth.jwt.algorithm");
3
- const getRefreshSecretKey = () => config.key("auth.jwt.refresh.secret");
4
- // Assuming there's a separate config for refresh token validity, for example, '7d' for 7 days
5
- const getRefreshTokenValidity = () => config.key("auth.jwt.refresh.expiresIn");
6
- const jwt = {
7
- /**
8
- * Generate a new JWT token for the user.
9
- * @param payload The payload to encode in the JWT token.
10
- */
11
- async generate(payload, { key = getSecretKey(), algorithm = getAlgorithm(), ...options } = {}) {
12
- // Create a signer function with predefined options
13
- const sign = createSigner({ key, ...options, algorithm });
14
- return sign({ ...payload });
15
- },
16
- /**
17
- * Verify the given token.
18
- * @param token The JWT token to verify.
19
- * @returns The decoded token payload if verification is successful.
20
- */
21
- async verify(token, { key = getSecretKey(), algorithms = getAlgorithm() ? [getAlgorithm()] : undefined, ...options } = {}) {
22
- const verify = createVerifier({ key, ...options, algorithms });
23
- return await verify(token);
24
- },
25
- /**
26
- * Generate a new refresh token for the user.
27
- */
28
- async generateRefreshToken(payload, { key = getRefreshSecretKey(), expiresIn = getRefreshTokenValidity(), algorithm = getAlgorithm(), ...options } = {}) {
29
- const sign = createSigner({ key, expiresIn, algorithm, ...options });
30
- return sign({ ...payload });
31
- },
32
- /**
33
- * Verify the given refresh token.
34
- */
35
- async verifyRefreshToken(token, { key = getRefreshSecretKey(), algorithms = [getAlgorithm()], ...options } = {}) {
36
- const verify = createVerifier({ key, algorithms, ...options });
37
- return await verify(token);
38
- },
39
- };export{jwt};//# sourceMappingURL=jwt.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"jwt.js","sources":["../../src/services/jwt.ts"],"sourcesContent":[null],"names":[],"mappings":"yFASA,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAW,CAAC;AACnE,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,oBAAoB,CAAc,CAAC;AAEzE,MAAM,mBAAmB,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,yBAAyB,CAAW,CAAC;AAClF;AACA,MAAM,uBAAuB,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,4BAA4B,CAAoB,CAAC;AAErF,MAAA,GAAG,GAAG;AACjB;;;AAGG;AACH,IAAA,MAAM,QAAQ,CACZ,OAAY,EACZ,EACE,GAAG,GAAG,YAAY,EAAE,EACpB,SAAS,GAAG,YAAY,EAAE,EAC1B,GAAG,OAAO,KAC0B,EAAE,EAAA;;AAGxC,QAAA,MAAM,IAAI,GAAG,YAAY,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC;AAE1D,QAAA,OAAO,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;KAC7B;AAED;;;;AAIG;AACH,IAAA,MAAM,MAAM,CACV,KAAa,EACb,EACE,GAAG,GAAG,YAAY,EAAE,EACpB,UAAU,GAAG,YAAY,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,GAAG,SAAS,EAC1D,GAAG,OAAO,KAC4B,EAAE,EAAA;AAE1C,QAAA,MAAM,MAAM,GAAG,cAAc,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;AAE/D,QAAA,OAAO,MAAM,MAAM,CAAC,KAAe,CAAC,CAAC;KACtC;AAED;;AAEG;IACH,MAAM,oBAAoB,CACxB,OAAY,EACZ,EACE,GAAG,GAAG,mBAAmB,EAAE,EAC3B,SAAS,GAAG,uBAAuB,EAAE,EACrC,SAAS,GAAG,YAAY,EAAE,EAC1B,GAAG,OAAO,EAAA,GAC0B,EAAE,EAAA;AAExC,QAAA,MAAM,IAAI,GAAG,YAAY,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AACrE,QAAA,OAAO,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;KAC7B;AAED;;AAEG;IACH,MAAM,kBAAkB,CACtB,KAAa,EACb,EACE,GAAG,GAAG,mBAAmB,EAAE,EAC3B,UAAU,GAAG,CAAC,YAAY,EAAE,CAAC,EAC7B,GAAG,OAAO,EAAA,GAC4B,EAAE,EAAA;AAE1C,QAAA,MAAM,MAAM,GAAG,cAAc,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAC/D,QAAA,OAAO,MAAM,MAAM,CAAC,KAAK,CAAC,CAAC;KAC5B;"}
@@ -1,18 +0,0 @@
1
- export declare enum AuthErrorCodes {
2
- /**
3
- * Missing Access Token Error Code EC001
4
- * EC001 = Missing Access Token
5
- */
6
- MissingAccessToken = "EC001",
7
- /**
8
- * Invalid Access Token Error Code EC002
9
- * EC002 = Invalid Access Token
10
- */
11
- InvalidAccessToken = "EC002",
12
- /**
13
- * Unauthorized Error Code EC003
14
- * EC003 = Unauthorized
15
- */
16
- Unauthorized = "EC003"
17
- }
18
- //# sourceMappingURL=auth-error-codes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth-error-codes.d.ts","sourceRoot":"","sources":["../../src/utils/auth-error-codes.ts"],"names":[],"mappings":"AAAA,oBAAY,cAAc;IACxB;;;OAGG;IACH,kBAAkB,UAAU;IAC5B;;;OAGG;IACH,kBAAkB,UAAU;IAC5B;;;OAGG;IACH,YAAY,UAAU;CACvB"}
@@ -1,18 +0,0 @@
1
- var AuthErrorCodes;
2
- (function (AuthErrorCodes) {
3
- /**
4
- * Missing Access Token Error Code EC001
5
- * EC001 = Missing Access Token
6
- */
7
- AuthErrorCodes["MissingAccessToken"] = "EC001";
8
- /**
9
- * Invalid Access Token Error Code EC002
10
- * EC002 = Invalid Access Token
11
- */
12
- AuthErrorCodes["InvalidAccessToken"] = "EC002";
13
- /**
14
- * Unauthorized Error Code EC003
15
- * EC003 = Unauthorized
16
- */
17
- AuthErrorCodes["Unauthorized"] = "EC003";
18
- })(AuthErrorCodes || (AuthErrorCodes = {}));export{AuthErrorCodes};//# sourceMappingURL=auth-error-codes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auth-error-codes.js","sources":["../../src/utils/auth-error-codes.ts"],"sourcesContent":[null],"names":[],"mappings":"IAAY,eAgBX;AAhBD,CAAA,UAAY,cAAc,EAAA;AACxB;;;AAGG;AACH,IAAA,cAAA,CAAA,oBAAA,CAAA,GAAA,OAA4B,CAAA;AAC5B;;;AAGG;AACH,IAAA,cAAA,CAAA,oBAAA,CAAA,GAAA,OAA4B,CAAA;AAC5B;;;AAGG;AACH,IAAA,cAAA,CAAA,cAAA,CAAA,GAAA,OAAsB,CAAA;AACxB,CAAC,EAhBW,cAAc,KAAd,cAAc,GAgBzB,EAAA,CAAA,CAAA"}
@@ -1,45 +0,0 @@
1
- import { NO_EXPIRATION } from "../contracts/types";
2
- /**
3
- * Duration object for specifying time periods
4
- * All units are additive (e.g., { days: 1, hours: 6 } = 30 hours)
5
- *
6
- * @example
7
- * ```typescript
8
- * { hours: 1 } // 1 hour
9
- * { days: 7, hours: 12 } // 7.5 days
10
- * { minutes: 30 } // 30 minutes
11
- * ```
12
- */
13
- export type Duration = {
14
- milliseconds?: number;
15
- seconds?: number;
16
- minutes?: number;
17
- hours?: number;
18
- days?: number;
19
- weeks?: number;
20
- };
21
- /**
22
- * Expiration value type - can be a Duration object, string format, or NO_EXPIRATION
23
- */
24
- export type ExpiresIn = Duration | typeof NO_EXPIRATION | string | number;
25
- /**
26
- * Parse duration to milliseconds
27
- * Supports Duration object, string format ("1d 2h 30m"), or number (raw ms)
28
- *
29
- * @example
30
- * ```typescript
31
- * parseExpirationToMs({ hours: 1 }) // 3600000
32
- * parseExpirationToMs({ days: 1 }) // 86400000
33
- * parseExpirationToMs("1h") // 3600000
34
- * parseExpirationToMs("1d 2h 30m") // 95400000
35
- * parseExpirationToMs(3600000) // 3600000
36
- * parseExpirationToMs(NO_EXPIRATION) // undefined
37
- * ```
38
- */
39
- export declare function parseExpirationToMs(expiration: ExpiresIn | undefined, defaultMs?: number): number | undefined;
40
- /**
41
- * Convert ExpiresIn to a value suitable for jwt.generate (string or number)
42
- * Returns undefined if NO_EXPIRATION
43
- */
44
- export declare function toJwtExpiresIn(expiration: ExpiresIn | undefined, defaultMs?: number): string | undefined;
45
- //# sourceMappingURL=duration.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/utils/duration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;;;;;;GAUG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,OAAO,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC;AAE1E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,SAAS,GAAG,SAAS,EACjC,SAAS,GAAE,MAAgB,GAC1B,MAAM,GAAG,SAAS,CAmBpB;AAuDD;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,SAAS,GAAG,SAAS,EACjC,SAAS,GAAE,MAAgB,GAC1B,MAAM,GAAG,SAAS,CAMpB"}
@@ -1,93 +0,0 @@
1
- import {NO_EXPIRATION}from'../contracts/types.js';/**
2
- * Parse duration to milliseconds
3
- * Supports Duration object, string format ("1d 2h 30m"), or number (raw ms)
4
- *
5
- * @example
6
- * ```typescript
7
- * parseExpirationToMs({ hours: 1 }) // 3600000
8
- * parseExpirationToMs({ days: 1 }) // 86400000
9
- * parseExpirationToMs("1h") // 3600000
10
- * parseExpirationToMs("1d 2h 30m") // 95400000
11
- * parseExpirationToMs(3600000) // 3600000
12
- * parseExpirationToMs(NO_EXPIRATION) // undefined
13
- * ```
14
- */
15
- function parseExpirationToMs(expiration, defaultMs = 3600000) {
16
- if (expiration === undefined) {
17
- return defaultMs;
18
- }
19
- if (expiration === NO_EXPIRATION) {
20
- return undefined;
21
- }
22
- if (typeof expiration === "number") {
23
- return expiration;
24
- }
25
- if (typeof expiration === "string") {
26
- return parseStringDuration(expiration);
27
- }
28
- // It's a Duration object
29
- return parseDurationObject(expiration);
30
- }
31
- /**
32
- * Parse a Duration object to milliseconds
33
- */
34
- function parseDurationObject(duration) {
35
- let ms = 0;
36
- if (duration.milliseconds)
37
- ms += duration.milliseconds;
38
- if (duration.seconds)
39
- ms += duration.seconds * 1000;
40
- if (duration.minutes)
41
- ms += duration.minutes * 60 * 1000;
42
- if (duration.hours)
43
- ms += duration.hours * 60 * 60 * 1000;
44
- if (duration.days)
45
- ms += duration.days * 24 * 60 * 60 * 1000;
46
- if (duration.weeks)
47
- ms += duration.weeks * 7 * 24 * 60 * 60 * 1000;
48
- return ms;
49
- }
50
- /**
51
- * Parse a string duration to milliseconds
52
- * Supports formats: "1h", "7d", "30m", "90s", "1d 2h 30m"
53
- */
54
- function parseStringDuration(str) {
55
- let totalMs = 0;
56
- const parts = str.trim().split(/\s+/);
57
- for (const part of parts) {
58
- const match = part.match(/^(\d+(?:\.\d+)?)([smhdw])$/i);
59
- if (!match)
60
- continue;
61
- const value = parseFloat(match[1]);
62
- const unit = match[2].toLowerCase();
63
- switch (unit) {
64
- case "s":
65
- totalMs += value * 1000;
66
- break;
67
- case "m":
68
- totalMs += value * 60 * 1000;
69
- break;
70
- case "h":
71
- totalMs += value * 60 * 60 * 1000;
72
- break;
73
- case "d":
74
- totalMs += value * 24 * 60 * 60 * 1000;
75
- break;
76
- case "w":
77
- totalMs += value * 7 * 24 * 60 * 60 * 1000;
78
- break;
79
- }
80
- }
81
- return totalMs || 3600000; // Default to 1 hour if nothing parsed
82
- }
83
- /**
84
- * Convert ExpiresIn to a value suitable for jwt.generate (string or number)
85
- * Returns undefined if NO_EXPIRATION
86
- */
87
- function toJwtExpiresIn(expiration, defaultMs = 3600000) {
88
- const ms = parseExpirationToMs(expiration, defaultMs);
89
- if (ms === undefined)
90
- return undefined;
91
- // Convert ms to seconds for JWT (more common format)
92
- return Math.floor(ms / 1000) + "s";
93
- }export{parseExpirationToMs,toJwtExpiresIn};//# sourceMappingURL=duration.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"duration.js","sources":["../../src/utils/duration.ts"],"sourcesContent":[null],"names":[],"mappings":"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"}
@@ -1,3 +0,0 @@
1
- export * from "./auth-error-codes";
2
- export * from "./duration";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC"}