@safepassage/sdk 3.4.9 → 3.4.11

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