@deflectbot/deflect-sdk 1.4.4 → 1.4.6

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,140 @@
1
+ import PulseReporter from "./pulse";
2
+ import { DeflectExtraArgs } from "./scriptClient";
3
+ /** Shared configuration for both the singleton and client instances */
4
+ export interface DeflectConfig {
5
+ /** The action ID to fetch the script for. */
6
+ actionId: string;
7
+ /** Override URL for the script. For staging/enterprise customers */
8
+ scriptUrl?: string;
9
+ /** Enable/disable automatic warmup/prefetch. Defaults to true. */
10
+ prefetch?: boolean;
11
+ /** Additional query params to append to the JS fetch (e.g., debug: true => &debug=true) */
12
+ extraArgs?: DeflectExtraArgs;
13
+ }
14
+ declare global {
15
+ interface Window {
16
+ Deflect: any;
17
+ }
18
+ }
19
+ /**
20
+ * Instance-based Deflect client. Use `Deflect.createClient()` to create instances.
21
+ * Each client manages its own actionId, caching, and rate limiting state.
22
+ */
23
+ export declare class DeflectClient {
24
+ private readonly config;
25
+ private scriptCache;
26
+ private isWarmupInProgress;
27
+ private hasWarmupError;
28
+ private warmupPromise;
29
+ private scriptFetchPromise;
30
+ private pulseReporter;
31
+ private getTokenPromise;
32
+ private lastErrorTime;
33
+ private consecutiveErrorCount;
34
+ private fetchCountInWindow;
35
+ private fetchWindowStart;
36
+ constructor(config: DeflectConfig, pulseReporter?: PulseReporter);
37
+ /** Get the actionId this client is configured for */
38
+ getActionId(): string;
39
+ private scheduleWarmup;
40
+ private static resolvePulseConfig;
41
+ private reportError;
42
+ private isInErrorCooldown;
43
+ private isRateLimited;
44
+ private hasExceededMaxErrors;
45
+ private recordFetchSuccess;
46
+ private recordFetchError;
47
+ private incrementFetchCount;
48
+ private tryWarmup;
49
+ private validateActionId;
50
+ private prefetchNextScript;
51
+ private fetchScriptOnce;
52
+ private isTestMode;
53
+ /** Get a challenge token for this client's actionId */
54
+ getToken(): Promise<string>;
55
+ private getTokenInternal;
56
+ private executeScript;
57
+ /** Manually trigger warmup/prefetch */
58
+ warmup(): Promise<boolean>;
59
+ /** Clear the cached script */
60
+ clearCache(): void;
61
+ /** Reset error state to allow retries */
62
+ resetErrorState(): void;
63
+ /** Get current rate limit and error status for debugging */
64
+ getStatus(): {
65
+ actionId: string;
66
+ isRateLimited: boolean;
67
+ isInCooldown: boolean;
68
+ consecutiveErrors: number;
69
+ fetchesInWindow: number;
70
+ canFetch: boolean;
71
+ };
72
+ /** Inject token into a form and submit */
73
+ injectToken(event: SubmitEvent): Promise<void>;
74
+ }
75
+ declare class Deflect {
76
+ private config;
77
+ private scriptCache;
78
+ private isWarmupInProgress;
79
+ private hasWarmupError;
80
+ private warmupPromise;
81
+ private pulseReporter;
82
+ private getTokenPromise;
83
+ private lastErrorTime;
84
+ private consecutiveErrorCount;
85
+ private fetchCountInWindow;
86
+ private fetchWindowStart;
87
+ constructor();
88
+ private initializeGlobalState;
89
+ private setupAutomaticWarmup;
90
+ private resolvePulseConfig;
91
+ private reportError;
92
+ /** Check if we're in error cooldown period */
93
+ private isInErrorCooldown;
94
+ /** Check if we've exceeded the rate limit */
95
+ private isRateLimited;
96
+ /** Check if we've hit max consecutive errors */
97
+ private hasExceededMaxErrors;
98
+ /** Record a successful fetch - resets error state */
99
+ private recordFetchSuccess;
100
+ /** Record a failed fetch - increments error tracking */
101
+ private recordFetchError;
102
+ /** Increment fetch counter for rate limiting */
103
+ private incrementFetchCount;
104
+ private tryWarmup;
105
+ private validateActionId;
106
+ private prefetchNextScript;
107
+ private isTestMode;
108
+ configure(params: DeflectConfig): void;
109
+ getToken(): Promise<string>;
110
+ private getTokenInternal;
111
+ private executeScript;
112
+ warmup(): Promise<boolean>;
113
+ clearCache(): void;
114
+ /** Reset error state to allow retries. Use after fixing configuration issues. */
115
+ resetErrorState(): void;
116
+ /** Get current rate limit and error status for debugging */
117
+ getStatus(): {
118
+ isRateLimited: boolean;
119
+ isInCooldown: boolean;
120
+ consecutiveErrors: number;
121
+ fetchesInWindow: number;
122
+ canFetch: boolean;
123
+ };
124
+ injectToken(event: SubmitEvent): Promise<void>;
125
+ /**
126
+ * Create a new Deflect client instance with its own configuration.
127
+ * Use this when you need multiple actionIds on the same page.
128
+ *
129
+ * @example
130
+ * const loginClient = Deflect.createClient({ actionId: 'login-form' });
131
+ * const signupClient = Deflect.createClient({ actionId: 'signup-form' });
132
+ *
133
+ * // Each client manages its own state
134
+ * const loginToken = await loginClient.getToken();
135
+ * const signupToken = await signupClient.getToken();
136
+ */
137
+ createClient(config: DeflectConfig): DeflectClient;
138
+ }
139
+ declare const DeflectInstance: Deflect;
140
+ export default DeflectInstance;