@markwharton/pwa-core 2.1.0 → 3.0.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/server.d.ts CHANGED
@@ -8,13 +8,27 @@ import { TableClient } from '@azure/data-tables';
8
8
  import { Result, BaseJwtPayload, RoleTokenPayload } from './shared';
9
9
  /**
10
10
  * Initializes the JWT authentication system. Call once at application startup.
11
- * @param secret - The JWT secret key (from environment variable)
12
- * @param minLength - Minimum required secret length (default: 32)
11
+ * @param config - Configuration object
12
+ * @param config.secret - The JWT secret key (from environment variable)
13
+ * @param config.minLength - Minimum required secret length (default: 32)
13
14
  * @throws Error if secret is missing or too short
14
15
  * @example
15
- * initAuth(process.env.JWT_SECRET);
16
+ * initAuth({ secret: process.env.JWT_SECRET });
17
+ * initAuth({ secret: process.env.JWT_SECRET, minLength: 64 });
18
+ */
19
+ export declare function initAuth(config: {
20
+ secret?: string;
21
+ minLength?: number;
22
+ }): void;
23
+ /**
24
+ * Initializes JWT authentication from environment variables.
25
+ * Reads JWT_SECRET from process.env.
26
+ * @param minLength - Minimum required secret length (default: 32)
27
+ * @throws Error if JWT_SECRET is missing or too short
28
+ * @example
29
+ * initAuthFromEnv(); // Uses process.env.JWT_SECRET
16
30
  */
17
- export declare function initAuth(secret: string | undefined, minLength?: number): void;
31
+ export declare function initAuthFromEnv(minLength?: number): void;
18
32
  /**
19
33
  * Gets the configured JWT secret.
20
34
  * @returns The JWT secret string
package/dist/server.js CHANGED
@@ -10,6 +10,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.HTTP_STATUS = exports.isAdmin = exports.hasRole = exports.hasUsername = exports.getErrorMessage = exports.err = exports.okVoid = exports.ok = exports.DEFAULT_TOKEN_EXPIRY_SECONDS = exports.DEFAULT_TOKEN_EXPIRY = void 0;
12
12
  exports.initAuth = initAuth;
13
+ exports.initAuthFromEnv = initAuthFromEnv;
13
14
  exports.getJwtSecret = getJwtSecret;
14
15
  exports.extractToken = extractToken;
15
16
  exports.validateToken = validateToken;
@@ -50,18 +51,35 @@ const shared_1 = require("./shared");
50
51
  let jwtSecret = null;
51
52
  /**
52
53
  * Initializes the JWT authentication system. Call once at application startup.
53
- * @param secret - The JWT secret key (from environment variable)
54
- * @param minLength - Minimum required secret length (default: 32)
54
+ * @param config - Configuration object
55
+ * @param config.secret - The JWT secret key (from environment variable)
56
+ * @param config.minLength - Minimum required secret length (default: 32)
55
57
  * @throws Error if secret is missing or too short
56
58
  * @example
57
- * initAuth(process.env.JWT_SECRET);
59
+ * initAuth({ secret: process.env.JWT_SECRET });
60
+ * initAuth({ secret: process.env.JWT_SECRET, minLength: 64 });
58
61
  */
59
- function initAuth(secret, minLength = 32) {
62
+ function initAuth(config) {
63
+ const { secret, minLength = 32 } = config;
60
64
  if (!secret || secret.length < minLength) {
61
65
  throw new Error(`JWT_SECRET must be at least ${minLength} characters`);
62
66
  }
63
67
  jwtSecret = secret;
64
68
  }
69
+ /**
70
+ * Initializes JWT authentication from environment variables.
71
+ * Reads JWT_SECRET from process.env.
72
+ * @param minLength - Minimum required secret length (default: 32)
73
+ * @throws Error if JWT_SECRET is missing or too short
74
+ * @example
75
+ * initAuthFromEnv(); // Uses process.env.JWT_SECRET
76
+ */
77
+ function initAuthFromEnv(minLength = 32) {
78
+ initAuth({
79
+ secret: process.env.JWT_SECRET,
80
+ minLength
81
+ });
82
+ }
65
83
  /**
66
84
  * Gets the configured JWT secret.
67
85
  * @returns The JWT secret string
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markwharton/pwa-core",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "Shared patterns for Azure PWA projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",