@donotdev/functions 0.0.18 → 0.0.20
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/lib/firebase/auth/getCustomClaims.d.ts +25 -0
- package/lib/firebase/auth/getUserAuthStatus.d.ts +29 -0
- package/lib/firebase/auth/index.d.ts +12 -0
- package/lib/firebase/auth/removeCustomClaims.d.ts +28 -0
- package/lib/firebase/auth/setCustomClaims.d.ts +34 -0
- package/lib/firebase/baseFunction.d.ts +26 -0
- package/lib/firebase/billing/cancelSubscription.d.ts +10 -0
- package/lib/firebase/billing/changePlan.d.ts +13 -0
- package/lib/firebase/billing/createCheckoutSession.d.ts +21 -0
- package/lib/firebase/billing/createCustomerPortal.d.ts +19 -0
- package/lib/firebase/billing/healthCheck.d.ts +5 -0
- package/lib/firebase/billing/index.d.ts +18 -0
- package/lib/firebase/billing/refreshSubscriptionStatus.d.ts +19 -0
- package/lib/firebase/billing/webhookHandler.d.ts +6 -0
- package/lib/firebase/config/constants.d.ts +89 -0
- package/lib/firebase/config/index.d.ts +9 -0
- package/lib/firebase/config/secrets.d.ts +15 -0
- package/lib/firebase/crud/aggregate.d.ts +98 -0
- package/lib/firebase/crud/create.d.ts +16 -0
- package/lib/firebase/crud/delete.d.ts +20 -0
- package/lib/firebase/crud/get.d.ts +24 -0
- package/lib/firebase/crud/index.d.ts +14 -0
- package/lib/firebase/crud/list.d.ts +25 -0
- package/lib/firebase/crud/update.d.ts +25 -0
- package/lib/firebase/helpers/githubAccessHelper.d.ts +30 -0
- package/lib/firebase/helpers/githubTeamAccessHelper.d.ts +36 -0
- package/lib/firebase/helpers/index.d.ts +10 -0
- package/lib/firebase/index.d.ts +17 -0
- package/lib/firebase/index.js +25 -9110
- package/lib/firebase/index.js.map +4 -4
- package/lib/firebase/oauth/disconnect.d.ts +12 -0
- package/lib/firebase/oauth/exchangeToken.d.ts +9 -0
- package/lib/firebase/oauth/getConnections.d.ts +11 -0
- package/lib/firebase/oauth/githubAccess.d.ts +83 -0
- package/lib/firebase/oauth/index.d.ts +13 -0
- package/lib/firebase/oauth/refreshToken.d.ts +9 -0
- package/lib/firebase/registerCrudFunctions.d.ts +32 -0
- package/lib/firebase/scheduled/checkExpiredSubscriptions.d.ts +14 -0
- package/lib/firebase/scheduled/index.d.ts +9 -0
- package/lib/shared/billing/createCheckout.d.ts +50 -0
- package/lib/shared/billing/helpers/index.d.ts +10 -0
- package/lib/shared/billing/helpers/subscriptionManagement.d.ts +34 -0
- package/lib/shared/billing/helpers/updateUserSubscription.d.ts +45 -0
- package/lib/shared/billing/idempotency.d.ts +22 -0
- package/lib/shared/billing/index.d.ts +11 -0
- package/lib/shared/billing/webhookHandler.d.ts +37 -0
- package/lib/shared/errorHandling.d.ts +14 -0
- package/lib/shared/firebase.d.ts +73 -0
- package/lib/shared/github.d.ts +128 -0
- package/lib/shared/index.d.ts +16 -0
- package/lib/shared/index.js +25 -6927
- package/lib/shared/index.js.map +4 -4
- package/lib/shared/logger.d.ts +133 -0
- package/lib/shared/metadata.d.ts +36 -0
- package/lib/shared/oauth/exchangeToken.d.ts +24 -0
- package/lib/shared/oauth/grantAccess.d.ts +30 -0
- package/lib/shared/oauth/index.d.ts +10 -0
- package/lib/shared/schema.d.ts +56 -0
- package/lib/shared/utils/detectFirestore.d.ts +31 -0
- package/lib/shared/utils/external/date.d.ts +36 -0
- package/lib/shared/utils/external/index.d.ts +11 -0
- package/lib/shared/utils/external/references.d.ts +12 -0
- package/lib/shared/utils/external/subscription.d.ts +41 -0
- package/lib/shared/utils/firebaseHelpers.d.ts +23 -0
- package/lib/shared/utils/functionWrapper.d.ts +36 -0
- package/lib/shared/utils/index.d.ts +14 -0
- package/lib/shared/utils/internal/auth.d.ts +57 -0
- package/lib/shared/utils/internal/firebase.d.ts +5 -0
- package/lib/shared/utils/internal/idempotency.d.ts +21 -0
- package/lib/shared/utils/internal/index.d.ts +14 -0
- package/lib/shared/utils/internal/monitoring.d.ts +80 -0
- package/lib/shared/utils/internal/rateLimiter.d.ts +82 -0
- package/lib/shared/utils/internal/validation.d.ts +43 -0
- package/lib/shared/utils/schemaValidation.d.ts +60 -0
- package/lib/shared/utils/validation.d.ts +98 -0
- package/lib/shared/utils/vercelHelpers.d.ts +18 -0
- package/lib/shared/utils.d.ts +234 -0
- package/lib/shared/validation.d.ts +16 -0
- package/lib/supabase/auth/deleteAccount.d.ts +16 -0
- package/lib/supabase/auth/getCustomClaims.d.ts +16 -0
- package/lib/supabase/auth/getUserAuthStatus.d.ts +18 -0
- package/lib/supabase/auth/removeCustomClaims.d.ts +16 -0
- package/lib/supabase/auth/setCustomClaims.d.ts +18 -0
- package/lib/supabase/baseFunction.d.ts +43 -0
- package/lib/supabase/billing/cancelSubscription.d.ts +9 -0
- package/lib/supabase/billing/changePlan.d.ts +11 -0
- package/lib/supabase/billing/createCheckoutSession.d.ts +11 -0
- package/lib/supabase/billing/createCustomerPortal.d.ts +9 -0
- package/lib/supabase/billing/refreshSubscriptionStatus.d.ts +9 -0
- package/lib/supabase/crud/aggregate.d.ts +27 -0
- package/lib/supabase/crud/create.d.ts +23 -0
- package/lib/supabase/crud/delete.d.ts +30 -0
- package/lib/supabase/crud/get.d.ts +23 -0
- package/lib/supabase/crud/index.d.ts +20 -0
- package/lib/supabase/crud/list.d.ts +33 -0
- package/lib/supabase/crud/update.d.ts +24 -0
- package/lib/supabase/helpers/authProvider.d.ts +22 -0
- package/lib/supabase/index.d.ts +29 -0
- package/lib/supabase/index.js +23 -0
- package/lib/supabase/index.js.map +7 -0
- package/lib/supabase/registerCrudFunctions.d.ts +24 -0
- package/lib/supabase/utils/idempotency.d.ts +36 -0
- package/lib/supabase/utils/monitoring.d.ts +59 -0
- package/lib/supabase/utils/rateLimiter.d.ts +56 -0
- package/lib/vercel/api/auth/get-custom-claims.d.ts +2 -0
- package/lib/vercel/api/auth/get-user-auth-status.d.ts +2 -0
- package/lib/vercel/api/auth/index.d.ts +12 -0
- package/lib/vercel/api/auth/remove-custom-claims.d.ts +2 -0
- package/lib/vercel/api/auth/set-custom-claims.d.ts +10 -0
- package/lib/vercel/api/billing/cancel.d.ts +10 -0
- package/lib/vercel/api/billing/change-plan.d.ts +11 -0
- package/lib/vercel/api/billing/create-checkout-session.d.ts +13 -0
- package/lib/vercel/api/billing/customer-portal.d.ts +3 -0
- package/lib/vercel/api/billing/index.d.ts +14 -0
- package/lib/vercel/api/billing/refresh-subscription-status.d.ts +31 -0
- package/lib/vercel/api/billing/webhook-handler.d.ts +22 -0
- package/lib/vercel/api/config/constants.d.ts +103 -0
- package/lib/vercel/api/config/firebase-admin.d.ts +19 -0
- package/lib/vercel/api/config/index.d.ts +10 -0
- package/lib/vercel/api/crud/create.d.ts +2 -0
- package/lib/vercel/api/crud/delete.d.ts +2 -0
- package/lib/vercel/api/crud/get.d.ts +2 -0
- package/lib/vercel/api/crud/index.d.ts +13 -0
- package/lib/vercel/api/crud/list.d.ts +2 -0
- package/lib/vercel/api/crud/update.d.ts +2 -0
- package/lib/vercel/api/index.d.ts +13 -0
- package/lib/vercel/api/index.js +22 -4790
- package/lib/vercel/api/index.js.map +4 -4
- package/lib/vercel/api/oauth/check-github-access.d.ts +12 -0
- package/lib/vercel/api/oauth/exchange-token.d.ts +8 -0
- package/lib/vercel/api/oauth/grant-github-access.d.ts +12 -0
- package/lib/vercel/api/oauth/index.d.ts +12 -0
- package/lib/vercel/api/oauth/revoke-github-access.d.ts +11 -0
- package/lib/vercel/api/utils/cors.d.ts +49 -0
- package/lib/vercel/baseFunction.d.ts +25 -0
- package/package.json +4 -4
- package/src/firebase/auth/setCustomClaims.ts +61 -16
- package/src/firebase/billing/healthCheck.ts +7 -23
- package/src/firebase/billing/webhookHandler.ts +0 -1
- package/src/firebase/crud/create.ts +17 -2
- package/src/firebase/oauth/exchangeToken.ts +5 -5
- package/src/shared/billing/createCheckout.ts +6 -1
- package/src/shared/utils/internal/validation.ts +1 -1
- package/src/supabase/crud/aggregate.ts +10 -7
- package/src/supabase/crud/create.ts +1 -1
- package/src/supabase/crud/get.ts +1 -1
- package/src/supabase/crud/list.ts +1 -1
- package/src/supabase/crud/update.ts +1 -1
- package/src/vercel/api/auth/set-custom-claims.ts +70 -23
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Log levels for structured logging
|
|
3
|
+
*/
|
|
4
|
+
export declare enum LogLevel {
|
|
5
|
+
DEBUG = 0,
|
|
6
|
+
INFO = 1,
|
|
7
|
+
WARN = 2,
|
|
8
|
+
ERROR = 3,
|
|
9
|
+
FATAL = 4
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Log entry interface for structured logging
|
|
13
|
+
*/
|
|
14
|
+
export interface LogEntry {
|
|
15
|
+
level: LogLevel;
|
|
16
|
+
message: string;
|
|
17
|
+
timestamp: string;
|
|
18
|
+
context?: Record<string, any>;
|
|
19
|
+
error?: Error;
|
|
20
|
+
metadata?: Record<string, any>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Server-side logger with Sentry integration
|
|
24
|
+
*
|
|
25
|
+
* Features:
|
|
26
|
+
* - Structured logging with context
|
|
27
|
+
* - Automatic Sentry error reporting
|
|
28
|
+
* - Performance monitoring
|
|
29
|
+
* - Request correlation
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { logger } from '../shared/logger.js';
|
|
34
|
+
*
|
|
35
|
+
* // Basic logging
|
|
36
|
+
* logger.info('Server started', { port: 3000 });
|
|
37
|
+
*
|
|
38
|
+
* // Error logging with Sentry
|
|
39
|
+
* logger.error('Database error', { error: err, query: 'SELECT * FROM users' });
|
|
40
|
+
*
|
|
41
|
+
* // Performance logging
|
|
42
|
+
* logger.info('Request completed', {
|
|
43
|
+
* duration: 150,
|
|
44
|
+
* status: 200,
|
|
45
|
+
* path: '/api/users'
|
|
46
|
+
* });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const logger: {
|
|
50
|
+
/**
|
|
51
|
+
* Log debug information
|
|
52
|
+
* @param message - Log message
|
|
53
|
+
* @param context - Additional context data
|
|
54
|
+
*
|
|
55
|
+
* @version 0.0.1
|
|
56
|
+
* @since 0.0.1
|
|
57
|
+
* @author AMBROISE PARK Consulting
|
|
58
|
+
*/
|
|
59
|
+
debug(message: string, context?: Record<string, any>): void;
|
|
60
|
+
/**
|
|
61
|
+
* Log informational messages
|
|
62
|
+
* @param message - Log message
|
|
63
|
+
* @param context - Additional context data
|
|
64
|
+
*
|
|
65
|
+
* @version 0.0.1
|
|
66
|
+
* @since 0.0.1
|
|
67
|
+
* @author AMBROISE PARK Consulting
|
|
68
|
+
*/
|
|
69
|
+
info(message: string, context?: Record<string, any>): void;
|
|
70
|
+
/**
|
|
71
|
+
* Log warning messages
|
|
72
|
+
* @param message - Log message
|
|
73
|
+
* @param context - Additional context data
|
|
74
|
+
*
|
|
75
|
+
* @version 0.0.1
|
|
76
|
+
* @since 0.0.1
|
|
77
|
+
* @author AMBROISE PARK Consulting
|
|
78
|
+
*/
|
|
79
|
+
warn(message: string, context?: Record<string, any>): void;
|
|
80
|
+
/**
|
|
81
|
+
* Log error messages with Sentry integration
|
|
82
|
+
* @param message - Log message
|
|
83
|
+
* @param context - Additional context data
|
|
84
|
+
*
|
|
85
|
+
* @version 0.0.1
|
|
86
|
+
* @since 0.0.1
|
|
87
|
+
* @author AMBROISE PARK Consulting
|
|
88
|
+
*/
|
|
89
|
+
error(message: string, context?: Record<string, any>): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Log fatal errors with Sentry integration
|
|
92
|
+
* @param message - Log message
|
|
93
|
+
* @param context - Additional context data
|
|
94
|
+
*
|
|
95
|
+
* @version 0.0.1
|
|
96
|
+
* @since 0.0.1
|
|
97
|
+
* @author AMBROISE PARK Consulting
|
|
98
|
+
*/
|
|
99
|
+
fatal(message: string, context?: Record<string, any>): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Core logging method
|
|
102
|
+
* @param level - Log level
|
|
103
|
+
* @param message - Log message
|
|
104
|
+
* @param context - Additional context data
|
|
105
|
+
*
|
|
106
|
+
* @version 0.0.1
|
|
107
|
+
* @since 0.0.1
|
|
108
|
+
* @author AMBROISE PARK Consulting
|
|
109
|
+
*/
|
|
110
|
+
log(level: LogLevel, message: string, context?: Record<string, any>): void;
|
|
111
|
+
/**
|
|
112
|
+
* Check if Sentry is enabled
|
|
113
|
+
* @returns True if Sentry is available and configured
|
|
114
|
+
*/
|
|
115
|
+
isSentryEnabled(): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Get current log level (always DEBUG for server)
|
|
118
|
+
* @returns Current log level
|
|
119
|
+
*/
|
|
120
|
+
getLevel(): LogLevel;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Create a child logger with additional context
|
|
124
|
+
* @param context - Additional context to include in all logs
|
|
125
|
+
* @returns Child logger instance
|
|
126
|
+
*/
|
|
127
|
+
export declare function createChildLogger(context: Record<string, any>): {
|
|
128
|
+
debug: (message: string, additionalContext?: Record<string, any>) => void;
|
|
129
|
+
info: (message: string, additionalContext?: Record<string, any>) => void;
|
|
130
|
+
warn: (message: string, additionalContext?: Record<string, any>) => void;
|
|
131
|
+
error: (message: string, additionalContext?: Record<string, any>) => Promise<void>;
|
|
132
|
+
fatal: (message: string, additionalContext?: Record<string, any>) => Promise<void>;
|
|
133
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Document metadata utilities for functions
|
|
3
|
+
* @description Server-safe metadata creation and update utilities
|
|
4
|
+
*
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Creates metadata for a new document.
|
|
11
|
+
* @param userId - The ID of the user creating the document
|
|
12
|
+
* @returns An object with creation and update timestamps and user IDs
|
|
13
|
+
*
|
|
14
|
+
* @version 0.0.1
|
|
15
|
+
* @since 0.0.1
|
|
16
|
+
* @author AMBROISE PARK Consulting
|
|
17
|
+
*/
|
|
18
|
+
export declare function createMetadata(userId: string): {
|
|
19
|
+
_createdAt: string;
|
|
20
|
+
_updatedAt: string;
|
|
21
|
+
_createdBy: string;
|
|
22
|
+
_updatedBy: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Creates update metadata for an existing document.
|
|
26
|
+
* @param userId - The ID of the user updating the document
|
|
27
|
+
* @returns An object with update timestamp and user ID
|
|
28
|
+
*
|
|
29
|
+
* @version 0.0.1
|
|
30
|
+
* @since 0.0.1
|
|
31
|
+
* @author AMBROISE PARK Consulting
|
|
32
|
+
*/
|
|
33
|
+
export declare function updateMetadata(userId: string): {
|
|
34
|
+
_updatedAt: string;
|
|
35
|
+
_updatedBy: string;
|
|
36
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview OAuth Token Exchange Algorithm
|
|
3
|
+
* @description Platform-agnostic algorithm for exchanging OAuth codes for tokens
|
|
4
|
+
*
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
import type { ExchangeTokenRequest, TokenResponse } from '@donotdev/core/server';
|
|
10
|
+
export interface OAuthProvider {
|
|
11
|
+
exchangeCodeForToken(params: {
|
|
12
|
+
code: string;
|
|
13
|
+
redirectUri: string;
|
|
14
|
+
codeVerifier?: string;
|
|
15
|
+
}): Promise<TokenResponse>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Exchange OAuth code for token
|
|
19
|
+
*
|
|
20
|
+
* @version 0.0.1
|
|
21
|
+
* @since 0.0.1
|
|
22
|
+
* @author AMBROISE PARK Consulting
|
|
23
|
+
*/
|
|
24
|
+
export declare function exchangeTokenAlgorithm(request: ExchangeTokenRequest, oauthProvider: OAuthProvider): Promise<TokenResponse>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Grant OAuth Access Algorithm
|
|
3
|
+
* @description Platform-agnostic algorithm for granting OAuth access
|
|
4
|
+
*
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
export interface OAuthGrantProvider {
|
|
10
|
+
grantAccess(params: {
|
|
11
|
+
userId: string;
|
|
12
|
+
provider: string;
|
|
13
|
+
accessToken: string;
|
|
14
|
+
refreshToken?: string;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
message: string;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Grant OAuth access to user
|
|
22
|
+
*
|
|
23
|
+
* @version 0.0.1
|
|
24
|
+
* @since 0.0.1
|
|
25
|
+
* @author AMBROISE PARK Consulting
|
|
26
|
+
*/
|
|
27
|
+
export declare function grantAccessAlgorithm(userId: string, provider: string, accessToken: string, refreshToken: string | undefined, oauthProvider: OAuthGrantProvider): Promise<{
|
|
28
|
+
success: boolean;
|
|
29
|
+
message: string;
|
|
30
|
+
}>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview OAuth utilities barrel exports
|
|
3
|
+
* @description Centralized exports for OAuth-related functions
|
|
4
|
+
*
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
export * from './exchangeToken.js';
|
|
10
|
+
export * from './grantAccess.js';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** Visibility levels matching @donotdev/core */
|
|
2
|
+
type Visibility = 'guest' | 'user' | 'admin' | 'technical' | 'hidden' | 'owner';
|
|
3
|
+
/**
|
|
4
|
+
* Determines if a field should be visible based on its visibility setting
|
|
5
|
+
* and the user's authentication/admin status.
|
|
6
|
+
*
|
|
7
|
+
* Visibility levels:
|
|
8
|
+
* - 'guest': Always visible (even to unauthenticated users)
|
|
9
|
+
* - 'user': Visible to authenticated users (users see both guest and user fields)
|
|
10
|
+
* - 'admin': Visible only to admins
|
|
11
|
+
* - 'technical': Visible to admins only (shown as read-only in edit forms)
|
|
12
|
+
* - 'hidden': Never visible (passwords, tokens, API keys - only in DB)
|
|
13
|
+
* - 'owner': Visible only when uid matches one of entity.ownership.ownerFields (requires document context; here treated as not visible for aggregate)
|
|
14
|
+
* - undefined: Defaults to 'user' behavior (visible to authenticated users)
|
|
15
|
+
*
|
|
16
|
+
* @param key - The name (key) of the field.
|
|
17
|
+
* @param visibility - The visibility setting.
|
|
18
|
+
* @param isAdmin - Whether the current user is an admin.
|
|
19
|
+
* @param isAuthenticated - Whether the current user is authenticated (defaults to true for backward compat).
|
|
20
|
+
* @returns True if the field should be visible, false otherwise.
|
|
21
|
+
*
|
|
22
|
+
* @version 0.0.2
|
|
23
|
+
* @since 0.0.1
|
|
24
|
+
* @author AMBROISE PARK Consulting
|
|
25
|
+
*/
|
|
26
|
+
export declare function isFieldVisible(key: string, visibility: Visibility | undefined, isAdmin: boolean, isAuthenticated?: boolean): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Extracts the names of all fields from a Valibot object schema that should be visible
|
|
29
|
+
* based on the user's administrative status and the visibility rules defined in the schema.
|
|
30
|
+
*
|
|
31
|
+
* @param schema - The Valibot schema, expected to be an object schema (v.object).
|
|
32
|
+
* @param isAdmin - Whether the current user is an admin.
|
|
33
|
+
* @returns An array of strings, where each string is the name of a visible field.
|
|
34
|
+
* Returns an empty array if the schema is not an object schema or has no entries.
|
|
35
|
+
*
|
|
36
|
+
* @version 0.0.1
|
|
37
|
+
* @since 0.0.1
|
|
38
|
+
* @author AMBROISE PARK Consulting
|
|
39
|
+
*/
|
|
40
|
+
export declare function getVisibleFields(schema: any, // Accept any Valibot type, but process only objects
|
|
41
|
+
isAdmin: boolean): string[];
|
|
42
|
+
/**
|
|
43
|
+
* Filters the fields of a data object based on visibility rules defined
|
|
44
|
+
* in a Valibot schema and the user's admin status.
|
|
45
|
+
*
|
|
46
|
+
* @template T - The expected type of the data object.
|
|
47
|
+
* @param {T | null | undefined} data - The document data object to filter.
|
|
48
|
+
* @param {any} schema - The Valibot schema defining the structure and field visibility.
|
|
49
|
+
* Expected to be a v.object schema with entries property.
|
|
50
|
+
* @param {boolean} isAdmin - Whether the current user has administrative privileges.
|
|
51
|
+
* @returns {Partial<T>} A new object containing only the fields visible to the user,
|
|
52
|
+
* or an empty object if input data is null/undefined.
|
|
53
|
+
*/
|
|
54
|
+
export declare function filterVisibleFields<T extends Record<string, any>>(data: T | null | undefined, schema: any, // Use any for broader compatibility
|
|
55
|
+
isAdmin: boolean): Partial<T>;
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Firestore Detection Utility
|
|
3
|
+
* @description Detects if Firestore credentials are available
|
|
4
|
+
*
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Check if Firestore is configured in environment
|
|
11
|
+
*
|
|
12
|
+
* Checks for Firebase Admin SDK credentials:
|
|
13
|
+
* - FIREBASE_PROJECT_ID (required)
|
|
14
|
+
* - FIREBASE_CLIENT_EMAIL (service account)
|
|
15
|
+
* - FIREBASE_PRIVATE_KEY (service account)
|
|
16
|
+
*
|
|
17
|
+
* OR checks if running in Firebase Functions environment
|
|
18
|
+
*
|
|
19
|
+
* @version 0.0.1
|
|
20
|
+
* @since 0.0.1
|
|
21
|
+
* @author AMBROISE PARK Consulting
|
|
22
|
+
*/
|
|
23
|
+
export declare function isFirestoreConfigured(): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Check if Firestore is actually available (can connect)
|
|
26
|
+
*
|
|
27
|
+
* @version 0.0.1
|
|
28
|
+
* @since 0.0.1
|
|
29
|
+
* @author AMBROISE PARK Consulting
|
|
30
|
+
*/
|
|
31
|
+
export declare function isFirestoreAvailable(): Promise<boolean>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a date value in various formats accepted by Firebase.
|
|
3
|
+
* Can be a JavaScript Date, a Firestore Timestamp, or an ISO 8601 string.
|
|
4
|
+
*/
|
|
5
|
+
export type DateValue = Date | FirestoreTimestamp | string;
|
|
6
|
+
/**
|
|
7
|
+
* Interface mimicking Firebase Timestamp for type compatibility
|
|
8
|
+
*/
|
|
9
|
+
export interface FirestoreTimestamp {
|
|
10
|
+
seconds: number;
|
|
11
|
+
nanoseconds: number;
|
|
12
|
+
toDate(): Date;
|
|
13
|
+
toMillis(): number;
|
|
14
|
+
isEqual(other: FirestoreTimestamp): boolean;
|
|
15
|
+
valueOf(): string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Converts various date formats to ISO string
|
|
19
|
+
* Handles Date, FirestoreTimestamp, and string inputs
|
|
20
|
+
*
|
|
21
|
+
* @version 0.0.1
|
|
22
|
+
* @since 0.0.1
|
|
23
|
+
* @author AMBROISE PARK Consulting
|
|
24
|
+
*/
|
|
25
|
+
export declare function toISOString(date: DateValue): string;
|
|
26
|
+
/**
|
|
27
|
+
* Calculate subscription end date with proper edge case handling
|
|
28
|
+
*
|
|
29
|
+
* @version 0.0.1
|
|
30
|
+
* @since 0.0.1
|
|
31
|
+
* @author AMBROISE PARK Consulting
|
|
32
|
+
* @param duration - Duration string (e.g., '1month', '3months', '1year', 'lifetime')
|
|
33
|
+
* @param startDate - Start date (defaults to now)
|
|
34
|
+
* @returns ISO string of end date (required for Firestore compatibility)
|
|
35
|
+
*/
|
|
36
|
+
export declare function calculateSubscriptionEndDate(duration: string, startDate?: Date): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview External utilities barrel exports
|
|
3
|
+
* @description Centralized exports for external utility functions
|
|
4
|
+
*
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
export * from './date.js';
|
|
10
|
+
export * from './references.js';
|
|
11
|
+
export { getTierFromPriceId, getUserSubscription, cancelUserSubscription, } from './subscription.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds all documents that reference the given document ID
|
|
3
|
+
*
|
|
4
|
+
* @version 0.0.1
|
|
5
|
+
* @since 0.0.1
|
|
6
|
+
* @author AMBROISE PARK Consulting
|
|
7
|
+
*/
|
|
8
|
+
export declare function findReferences(collection: string, documentId: string): Promise<Array<{
|
|
9
|
+
id: string;
|
|
10
|
+
collection: string;
|
|
11
|
+
field: string;
|
|
12
|
+
}>>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Subscription utility functions
|
|
3
|
+
* @description Functions for managing user subscriptions and billing
|
|
4
|
+
*
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
import type { SubscriptionClaims } from '@donotdev/core/server';
|
|
10
|
+
/**
|
|
11
|
+
* Maps Stripe price ID to subscription tier
|
|
12
|
+
*
|
|
13
|
+
* @version 0.0.1
|
|
14
|
+
* @since 0.0.1
|
|
15
|
+
* @author AMBROISE PARK Consulting
|
|
16
|
+
*/
|
|
17
|
+
export declare function getTierFromPriceId(priceId: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Validates subscription status and updates Firebase custom claims
|
|
20
|
+
*
|
|
21
|
+
* @version 0.0.1
|
|
22
|
+
* @since 0.0.1
|
|
23
|
+
* @author AMBROISE PARK Consulting
|
|
24
|
+
*/
|
|
25
|
+
export declare function updateFirebaseUserSubscription(firebaseUid: string, subscription: any): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Cancels user subscription and resets to free tier
|
|
28
|
+
*
|
|
29
|
+
* @version 0.0.1
|
|
30
|
+
* @since 0.0.1
|
|
31
|
+
* @author AMBROISE PARK Consulting
|
|
32
|
+
*/
|
|
33
|
+
export declare function cancelUserSubscription(firebaseUid: string, subscription: any): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Gets user's current subscription from Firebase
|
|
36
|
+
*
|
|
37
|
+
* @version 0.0.1
|
|
38
|
+
* @since 0.0.1
|
|
39
|
+
* @author AMBROISE PARK Consulting
|
|
40
|
+
*/
|
|
41
|
+
export declare function getUserSubscription(firebaseUid: string): Promise<SubscriptionClaims | null>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CallableRequest } from 'firebase-functions/v2/https';
|
|
2
|
+
import type * as v from 'valibot';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Firebase onCall function with schema validation
|
|
5
|
+
*
|
|
6
|
+
* @version 0.0.1
|
|
7
|
+
* @since 0.0.1
|
|
8
|
+
* @author AMBROISE PARK Consulting
|
|
9
|
+
*/
|
|
10
|
+
export declare function createFirebaseCallable<TRequest, TResponse>(config: any, defaultSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>, handler: (request: CallableRequest<TRequest>, validatedData: TRequest) => Promise<TResponse>): {
|
|
11
|
+
onCall: import("firebase-functions/https").CallableFunction<TRequest, Promise<TResponse>, unknown>;
|
|
12
|
+
withSchema: (request: CallableRequest<TRequest>, customSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>) => Promise<TResponse>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Creates both onCall and withSchema exports for a Firebase function
|
|
16
|
+
*
|
|
17
|
+
* @version 0.0.1
|
|
18
|
+
* @since 0.0.1
|
|
19
|
+
* @author AMBROISE PARK Consulting
|
|
20
|
+
*/
|
|
21
|
+
export declare function createFirebaseFunctionExports<TRequest, TResponse>(config: any, defaultSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>, handler: (request: CallableRequest<TRequest>, validatedData: TRequest) => Promise<TResponse>): {
|
|
22
|
+
[x: string]: import("firebase-functions/https").CallableFunction<TRequest, Promise<TResponse>, unknown> | ((request: CallableRequest<TRequest>, customSchema: v.BaseSchema<unknown, TRequest, v.BaseIssue<unknown>>) => Promise<TResponse>);
|
|
23
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Simple DRY wrapper for functions with schema validation
|
|
3
|
+
* @description Eliminates duplication by providing a clean pattern for all functions
|
|
4
|
+
*
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
import * as v from 'valibot';
|
|
10
|
+
import type { CallableRequest } from 'firebase-functions/v2/https';
|
|
11
|
+
import type { NextApiRequest, NextApiResponse } from 'next';
|
|
12
|
+
/**
|
|
13
|
+
* Simple wrapper that validates data against schema and calls the handler
|
|
14
|
+
* This is the ONLY pattern needed for all functions
|
|
15
|
+
*
|
|
16
|
+
* @version 0.0.1
|
|
17
|
+
* @since 0.0.1
|
|
18
|
+
* @author AMBROISE PARK Consulting
|
|
19
|
+
*/
|
|
20
|
+
export declare function withValidation<TData, TResponse>(schema: v.BaseSchema<unknown, TData, v.BaseIssue<unknown>>, handler: (data: TData) => Promise<TResponse>): (data: any) => Promise<TResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Firebase function wrapper
|
|
23
|
+
*
|
|
24
|
+
* @version 0.0.1
|
|
25
|
+
* @since 0.0.1
|
|
26
|
+
* @author AMBROISE PARK Consulting
|
|
27
|
+
*/
|
|
28
|
+
export declare function firebaseFunction<TData, TResponse>(schema: v.BaseSchema<unknown, TData, v.BaseIssue<unknown>>, handler: (data: TData) => Promise<TResponse>): (request: CallableRequest<TData>) => Promise<TResponse>;
|
|
29
|
+
/**
|
|
30
|
+
* Vercel function wrapper
|
|
31
|
+
*
|
|
32
|
+
* @version 0.0.1
|
|
33
|
+
* @since 0.0.1
|
|
34
|
+
* @author AMBROISE PARK Consulting
|
|
35
|
+
*/
|
|
36
|
+
export declare function vercelFunction<TData, TResponse>(schema: v.BaseSchema<unknown, TData, v.BaseIssue<unknown>>, handler: (req: NextApiRequest, res: NextApiResponse, data: TData) => Promise<TResponse>): (req: NextApiRequest, res: NextApiResponse) => Promise<TResponse>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Utils barrel exports
|
|
3
|
+
* @description Centralized exports for utility functions
|
|
4
|
+
*
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
export * from './validation.js';
|
|
10
|
+
export * from './schemaValidation.js';
|
|
11
|
+
export * from './firebaseHelpers.js';
|
|
12
|
+
export * from './vercelHelpers.js';
|
|
13
|
+
export * from './external/index.js';
|
|
14
|
+
export * from './internal/index.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { NextApiRequest } from 'next';
|
|
2
|
+
/** Auth provider type for explicit configuration */
|
|
3
|
+
export type AuthProvider = 'firebase' | 'supabase';
|
|
4
|
+
/**
|
|
5
|
+
* Validates that user is authenticated
|
|
6
|
+
*
|
|
7
|
+
* @version 0.0.1
|
|
8
|
+
* @since 0.0.1
|
|
9
|
+
* @author AMBROISE PARK Consulting
|
|
10
|
+
*/
|
|
11
|
+
export declare function assertAuthenticated(uid: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Validates that user has admin privileges.
|
|
14
|
+
* Uses IServerAuthAdapter when configured, falls back to Firebase Admin SDK.
|
|
15
|
+
*
|
|
16
|
+
* @version 0.0.2
|
|
17
|
+
* @since 0.0.1
|
|
18
|
+
* @author AMBROISE PARK Consulting
|
|
19
|
+
*/
|
|
20
|
+
export declare function assertAdmin(uid: string): Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Verify a Bearer token using the specified auth provider.
|
|
23
|
+
* Returns `{ uid: string }` on success, throws on failure.
|
|
24
|
+
*
|
|
25
|
+
* Provider resolution order:
|
|
26
|
+
* 1. Explicit `provider` parameter ('firebase' | 'supabase')
|
|
27
|
+
* 2. Provider registry (IServerAuthAdapter via `hasProvider('serverAuth')`)
|
|
28
|
+
* 3. Firebase Admin SDK fallback
|
|
29
|
+
*
|
|
30
|
+
* @param token - Raw JWT token (without "Bearer " prefix)
|
|
31
|
+
* @param provider - Optional explicit auth provider
|
|
32
|
+
* @returns Object with verified user's uid
|
|
33
|
+
*
|
|
34
|
+
* @version 0.0.1
|
|
35
|
+
* @since 0.5.0
|
|
36
|
+
* @author AMBROISE PARK Consulting
|
|
37
|
+
*/
|
|
38
|
+
export declare function verifyToken(token: string, provider?: AuthProvider): Promise<{
|
|
39
|
+
uid: string;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Verifies auth token from request.
|
|
43
|
+
* Uses IServerAuthAdapter when configured, falls back to Firebase Admin SDK.
|
|
44
|
+
*
|
|
45
|
+
* @param req - Next.js API request
|
|
46
|
+
* @param provider - Optional explicit auth provider ('firebase' | 'supabase')
|
|
47
|
+
* @returns Verified user's uid
|
|
48
|
+
*
|
|
49
|
+
* @version 0.0.3
|
|
50
|
+
* @since 0.0.1
|
|
51
|
+
* @author AMBROISE PARK Consulting
|
|
52
|
+
*/
|
|
53
|
+
export declare function verifyAuthToken(req: NextApiRequest, provider?: AuthProvider): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated Use verifyAuthToken instead. Kept for backwards compatibility.
|
|
56
|
+
*/
|
|
57
|
+
export declare const verifyFirebaseAuthToken: typeof verifyAuthToken;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface IdempotencyResult<T = any> {
|
|
2
|
+
result: T;
|
|
3
|
+
processedAt: string;
|
|
4
|
+
processedBy: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Check if an operation has already been processed (idempotency check)
|
|
8
|
+
*
|
|
9
|
+
* @version 0.0.1
|
|
10
|
+
* @since 0.0.1
|
|
11
|
+
* @author AMBROISE PARK Consulting
|
|
12
|
+
*/
|
|
13
|
+
export declare function checkIdempotency<T = any>(key: string, operation: string): Promise<T | null>;
|
|
14
|
+
/**
|
|
15
|
+
* Store the result of an operation for idempotency
|
|
16
|
+
*
|
|
17
|
+
* @version 0.0.1
|
|
18
|
+
* @since 0.0.1
|
|
19
|
+
* @author AMBROISE PARK Consulting
|
|
20
|
+
*/
|
|
21
|
+
export declare function storeIdempotencyResult<T = any>(key: string, operation: string, result: T, processedBy: string): Promise<void>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Internal utilities barrel exports
|
|
3
|
+
* @description Centralized exports for internal utility functions
|
|
4
|
+
*
|
|
5
|
+
* @version 0.0.1
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
* @author AMBROISE PARK Consulting
|
|
8
|
+
*/
|
|
9
|
+
export * from './auth.js';
|
|
10
|
+
export * from './firebase.js';
|
|
11
|
+
export * from './idempotency.js';
|
|
12
|
+
export * from './monitoring.js';
|
|
13
|
+
export * from './rateLimiter.js';
|
|
14
|
+
export * from './validation.js';
|