@safepassage/sdk 3.4.8 → 3.4.10

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,230 +0,0 @@
1
- /**
2
- * SafePassage SDK - Redirect-based age verification
3
- *
4
- * Lightweight SDK for integrating SafePassage age verification using redirect flow.
5
- * Provides a secure, easy-to-implement solution for age verification with comprehensive
6
- * security features and flexible integration options.
7
- *
8
- * Key Features:
9
- * - Redirect and new-tab verification modes
10
- * - Automatic session management for public API keys
11
- * - HMAC-signed state parameters for security
12
- * - Rate limiting and race condition protection
13
- * - Comprehensive security validation and logging
14
- * - PostMessage communication for new-tab mode
15
- * - Automatic cleanup and resource management
16
- * - Environment-specific configuration
17
- *
18
- * Security Features:
19
- * - Origin validation for PostMessage communication
20
- * - HTTPS enforcement in production
21
- * - Rate limiting per API key and origin
22
- * - State parameter signing with timestamps and nonces
23
- * - Comprehensive security event logging
24
- * - Protection against race conditions and replay attacks
25
- *
26
- * @author SafePassage Engineering
27
- * @version 2.0.0
28
- * @since 1.0.0
29
- */
30
- import type { SafePassageConfig, VerificationOptions } from '../types';
31
- /**
32
- * SafePassage SDK Main Class
33
- *
34
- * Primary SDK class that manages age verification sessions with comprehensive
35
- * security and error handling. Supports both redirect and new-tab modes with
36
- * automatic session management and PostMessage communication.
37
- *
38
- * The class implements multiple security layers including origin validation,
39
- * rate limiting, state signing, and comprehensive event logging to ensure
40
- * secure verification flows.
41
- */
42
- export declare class SafePassage {
43
- private config;
44
- private popupWindow;
45
- private messageListener;
46
- private popupMonitorInterval;
47
- private unloadListener;
48
- private isVerificationInProgress;
49
- private currentSessionId;
50
- private lastVerifyUrl;
51
- private lastSessionToken;
52
- private temporaryHandoffToken;
53
- /**
54
- * Initialize SafePassage SDK
55
- *
56
- * Validates configuration, sets up security measures, and prepares the SDK
57
- * for verification operations. Performs comprehensive environment validation
58
- * and security initialization.
59
- *
60
- * @param {SafePassageConfig} config - SDK configuration object
61
- * @throws {Error} If configuration validation fails
62
- */
63
- constructor(config: SafePassageConfig);
64
- /**
65
- * Initiate age verification with race condition protection
66
- *
67
- * Main verification method that handles session creation, security validation,
68
- * and verification flow initiation. Includes race condition protection and
69
- * comprehensive error handling.
70
- *
71
- * For public keys (pk_*), automatically creates sessions via the portal API.
72
- * For private keys (sk_*), requires a pre-created sessionId.
73
- *
74
- * @param {VerificationOptions} [options={}] - Verification options
75
- * @param {string} [options.sessionId] - Session ID (required for private keys)
76
- * @param {number} [options.challengeAge] - Age challenge override
77
- * @param {string} [options.verificationMode] - Verification mode override
78
- * @param {string} [options.externalUserId] - External user identifier
79
- * @returns {Promise<void>} Promise that resolves when verification is initiated
80
- * @throws {Error} If verification cannot be started or is already in progress
81
- */
82
- verify(options?: VerificationOptions): Promise<void>;
83
- /**
84
- * Build verification URL with HMAC-signed state
85
- *
86
- * Constructs the verification URL with signed state parameter containing
87
- * all necessary configuration and security information. The state parameter
88
- * includes HMAC signature for integrity protection.
89
- *
90
- * @param {VerificationOptions} options - Verification options
91
- * @returns {Promise<string>} Complete verification URL
92
- * @private
93
- */
94
- private buildVerificationUrl;
95
- /**
96
- * Redirect in same tab
97
- *
98
- * Performs a full page redirect to the verification URL.
99
- * Used for redirect mode verification.
100
- *
101
- * @param {string} url - Verification URL to redirect to
102
- * @private
103
- */
104
- private redirect;
105
- /**
106
- * Open in new tab with PostMessage communication and proper cleanup
107
- *
108
- * Opens verification URL in a new tab/window and sets up secure PostMessage
109
- * communication for receiving verification results. Includes comprehensive
110
- * security validation and automatic cleanup.
111
- *
112
- * @param {string} url - Verification URL to open
113
- * @param {string} sessionId - Session ID for result correlation
114
- * @private
115
- */
116
- private openNewTab;
117
- /**
118
- * Set up automatic cleanup on page unload to prevent memory leaks
119
- *
120
- * Registers event listeners for page unload events to ensure proper
121
- * cleanup of resources and verification state. Handles both traditional
122
- * page navigation and single-page application route changes.
123
- *
124
- * @private
125
- */
126
- private setupAutoCleanup;
127
- /**
128
- * Auto-detect environment based on current URL
129
- *
130
- * Analyzes the current hostname to determine the appropriate environment
131
- * configuration. Used when environment is not explicitly specified.
132
- * Always defaults to production unless staging is detected.
133
- *
134
- * @returns {'production' | 'staging'} Detected environment
135
- * @private
136
- */
137
- private detectEnvironment;
138
- /**
139
- * Get the current environment
140
- * @returns {string} The current environment (production or staging)
141
- */
142
- getEnvironment(): 'production' | 'staging';
143
- /**
144
- * Unlock verification process to allow new verifications
145
- *
146
- * Resets the verification lock state to allow new verification attempts.
147
- * Called after successful completion, errors, or cleanup.
148
- *
149
- * @private
150
- */
151
- private unlockVerification;
152
- /**
153
- * Internal cleanup method to prevent memory leaks
154
- *
155
- * Cleans up popup windows, event listeners, and intervals.
156
- * Does not unlock verification state - that's handled by specific callers.
157
- *
158
- * @private
159
- */
160
- private cleanup;
161
- /**
162
- * Remove auto-cleanup listeners
163
- *
164
- * Removes page unload event listeners that were set up for automatic cleanup.
165
- *
166
- * @private
167
- */
168
- private removeAutoCleanupListeners;
169
- /**
170
- * Public cleanup method for manual resource management
171
- *
172
- * Completely destroys the SDK instance, cleaning up all resources and
173
- * removing all event listeners. Should be called when the SDK is no longer needed.
174
- *
175
- * @public
176
- */
177
- destroy(): void;
178
- /**
179
- * Get Portal API URL based on environment
180
- *
181
- * Returns the appropriate portal-api URL for the current environment.
182
- *
183
- * @returns {string} Portal API URL
184
- * @private
185
- */
186
- private getPortalApiUrl;
187
- /**
188
- * Get Engine URL based on environment
189
- *
190
- * Returns the appropriate verify-engine URL for the current environment.
191
- * In production, engine access is proxied through portal-api.
192
- *
193
- * @returns {string} Engine URL
194
- * @private
195
- */
196
- private getEngineUrl;
197
- /**
198
- * Get WebSocket URL based on environment
199
- *
200
- * Returns the appropriate WebSocket URL for the current environment.
201
- * In production, WebSocket connections are proxied through portal-api.
202
- *
203
- * @returns {string} WebSocket URL
204
- * @private
205
- */
206
- private getWebSocketUrl;
207
- /**
208
- * Detect if this is a public key (pk_ prefix) vs private key (sk_ prefix)
209
- *
210
- * Determines API key type based on prefix to handle different authentication flows.
211
- *
212
- * @returns {boolean} True if public key, false if private key
213
- * @private
214
- */
215
- private isPublicKey;
216
- /**
217
- * Create session internally for public keys
218
- *
219
- * Creates a verification session via the portal API for public key authentication.
220
- * Generates a UUID session ID and submits session creation request with
221
- * verification parameters.
222
- *
223
- * @param {VerificationOptions} options - Verification options
224
- * @returns {Promise<string>} Created session ID
225
- * @throws {Error} If session creation fails
226
- * @private
227
- */
228
- private createInternalSession;
229
- }
230
- export default SafePassage;