@sudobility/auth_lib 0.0.5 → 0.0.9

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.
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @fileoverview Admin email whitelist utilities
3
+ *
4
+ * Provides functions for parsing and checking admin email whitelists,
5
+ * typically used for bypassing rate limits and subscription checks.
6
+ */
7
+ /**
8
+ * Parse admin emails from environment variable or string
9
+ *
10
+ * @param input - Comma-separated string of admin emails (e.g., "admin@example.com, other@example.com")
11
+ * @returns Array of normalized (lowercase, trimmed) email addresses
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const adminEmails = parseAdminEmails(process.env.ADMIN_EMAILS || "");
16
+ * // Returns: ["admin@example.com", "other@example.com"]
17
+ * ```
18
+ */
19
+ export declare function parseAdminEmails(input: string | undefined | null): string[];
20
+ /**
21
+ * Check if an email is in the admin whitelist
22
+ *
23
+ * @param email - Email address to check
24
+ * @param adminEmails - Array of admin emails (from parseAdminEmails)
25
+ * @returns True if the email is an admin
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const adminEmails = parseAdminEmails(process.env.ADMIN_EMAILS || "");
30
+ * if (isAdminEmail(user.email, adminEmails)) {
31
+ * // Skip rate limiting, subscription checks, etc.
32
+ * }
33
+ * ```
34
+ */
35
+ export declare function isAdminEmail(email: string | undefined | null, adminEmails: string[]): boolean;
36
+ /**
37
+ * Create a cached admin email checker
38
+ *
39
+ * Parses the admin emails once and returns a checker function.
40
+ * Useful for middleware where you don't want to re-parse on every request.
41
+ *
42
+ * @param input - Comma-separated string of admin emails
43
+ * @returns Function that checks if an email is an admin
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const isAdmin = createAdminChecker(process.env.ADMIN_EMAILS);
48
+ *
49
+ * // In middleware:
50
+ * if (isAdmin(user.email)) {
51
+ * // Bypass checks
52
+ * }
53
+ * ```
54
+ */
55
+ export declare function createAdminChecker(input: string | undefined | null): (email: string | undefined | null) => boolean;
56
+ //# sourceMappingURL=admin-emails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-emails.d.ts","sourceRoot":"","sources":["../../src/admin/admin-emails.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,EAAE,CAS3E;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,EAChC,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAMT;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAC/B,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,KAAK,OAAO,CAM/C"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @fileoverview Admin email whitelist utilities
3
+ *
4
+ * Provides functions for parsing and checking admin email whitelists,
5
+ * typically used for bypassing rate limits and subscription checks.
6
+ */
7
+ /**
8
+ * Parse admin emails from environment variable or string
9
+ *
10
+ * @param input - Comma-separated string of admin emails (e.g., "admin@example.com, other@example.com")
11
+ * @returns Array of normalized (lowercase, trimmed) email addresses
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const adminEmails = parseAdminEmails(process.env.ADMIN_EMAILS || "");
16
+ * // Returns: ["admin@example.com", "other@example.com"]
17
+ * ```
18
+ */
19
+ export function parseAdminEmails(input) {
20
+ if (!input) {
21
+ return [];
22
+ }
23
+ return input
24
+ .split(',')
25
+ .map(email => email.trim().toLowerCase())
26
+ .filter(email => email.length > 0 && email.includes('@'));
27
+ }
28
+ /**
29
+ * Check if an email is in the admin whitelist
30
+ *
31
+ * @param email - Email address to check
32
+ * @param adminEmails - Array of admin emails (from parseAdminEmails)
33
+ * @returns True if the email is an admin
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const adminEmails = parseAdminEmails(process.env.ADMIN_EMAILS || "");
38
+ * if (isAdminEmail(user.email, adminEmails)) {
39
+ * // Skip rate limiting, subscription checks, etc.
40
+ * }
41
+ * ```
42
+ */
43
+ export function isAdminEmail(email, adminEmails) {
44
+ if (!email) {
45
+ return false;
46
+ }
47
+ return adminEmails.includes(email.toLowerCase());
48
+ }
49
+ /**
50
+ * Create a cached admin email checker
51
+ *
52
+ * Parses the admin emails once and returns a checker function.
53
+ * Useful for middleware where you don't want to re-parse on every request.
54
+ *
55
+ * @param input - Comma-separated string of admin emails
56
+ * @returns Function that checks if an email is an admin
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const isAdmin = createAdminChecker(process.env.ADMIN_EMAILS);
61
+ *
62
+ * // In middleware:
63
+ * if (isAdmin(user.email)) {
64
+ * // Bypass checks
65
+ * }
66
+ * ```
67
+ */
68
+ export function createAdminChecker(input) {
69
+ const adminEmails = parseAdminEmails(input);
70
+ return (email) => {
71
+ return isAdminEmail(email, adminEmails);
72
+ };
73
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @fileoverview Admin utilities exports
3
+ */
4
+ export { parseAdminEmails, isAdminEmail, createAdminChecker, } from './admin-emails';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/admin/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,GACnB,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @fileoverview Admin utilities exports
3
+ */
4
+ export { parseAdminEmails, isAdminEmail, createAdminChecker, } from './admin-emails';
package/dist/index.d.ts CHANGED
@@ -10,4 +10,5 @@ export { initializeFirebaseAuth, getFirebaseApp, getFirebaseAuth, getFirebaseCon
10
10
  export type { FirebaseConfig, FirebaseInitOptions, FirebaseInitResult, FirebaseAuthNetworkClientOptions, } from './config';
11
11
  export { useFirebaseAuthNetworkClient } from './hooks';
12
12
  export { getFirebaseErrorMessage, getFirebaseErrorCode, formatFirebaseError, isFirebaseAuthError, } from './utils';
13
+ export { parseAdminEmails, isAdminEmail, createAdminChecker } from './admin';
13
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gCAAgC,GACjC,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAGvD,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAElB,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,gCAAgC,GACjC,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAGvD,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -12,3 +12,5 @@ export { initializeFirebaseAuth, getFirebaseApp, getFirebaseAuth, getFirebaseCon
12
12
  export { useFirebaseAuthNetworkClient } from './hooks';
13
13
  // Utils
14
14
  export { getFirebaseErrorMessage, getFirebaseErrorCode, formatFirebaseError, isFirebaseAuthError, } from './utils';
15
+ // Admin
16
+ export { parseAdminEmails, isAdminEmail, createAdminChecker } from './admin';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sudobility/auth_lib",
3
- "version": "0.0.5",
3
+ "version": "0.0.9",
4
4
  "description": "Firebase authentication utilities with token refresh handling",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -31,8 +31,8 @@
31
31
  "peerDependencies": {
32
32
  "react": "^19.2.3",
33
33
  "firebase": "^12.7.0",
34
- "@sudobility/di": "^1.5.17",
35
- "@sudobility/types": "^1.9.43"
34
+ "@sudobility/di": "^1.5.18",
35
+ "@sudobility/types": "^1.9.44"
36
36
  },
37
37
  "devDependencies": {
38
38
  "vitest": "^4.0.4",