@scalemule/nextjs 0.1.61 → 0.1.62

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.
Files changed (41) hide show
  1. package/dist/audio.css +857 -0
  2. package/dist/audio.d.mts +334 -0
  3. package/dist/audio.d.ts +334 -0
  4. package/dist/audio.js +2178 -0
  5. package/dist/audio.mjs +2156 -0
  6. package/dist/client.d.mts +240 -0
  7. package/dist/client.d.ts +240 -0
  8. package/dist/client.js +938 -0
  9. package/dist/client.mjs +935 -0
  10. package/dist/index-CEi5Nd4L.d.mts +980 -0
  11. package/dist/index-CEi5Nd4L.d.ts +980 -0
  12. package/dist/index.d.mts +1306 -0
  13. package/dist/index.d.ts +1306 -0
  14. package/dist/index.js +5991 -0
  15. package/dist/index.mjs +5928 -0
  16. package/dist/ledvery-CxPzZpxP.d.mts +44 -0
  17. package/dist/ledvery-CxPzZpxP.d.ts +44 -0
  18. package/dist/listening-hub.global.js +1 -0
  19. package/dist/server/auth.d.mts +43 -0
  20. package/dist/server/auth.d.ts +43 -0
  21. package/dist/server/auth.js +1988 -0
  22. package/dist/server/auth.mjs +1982 -0
  23. package/dist/server/index.d.mts +1302 -0
  24. package/dist/server/index.d.ts +1302 -0
  25. package/dist/server/index.js +3633 -0
  26. package/dist/server/index.mjs +3554 -0
  27. package/dist/server/ledvery.d.mts +1 -0
  28. package/dist/server/ledvery.d.ts +1 -0
  29. package/dist/server/ledvery.js +336 -0
  30. package/dist/server/ledvery.mjs +333 -0
  31. package/dist/server/webhook-handler.d.mts +3 -0
  32. package/dist/server/webhook-handler.d.ts +3 -0
  33. package/dist/server/webhook-handler.js +59 -0
  34. package/dist/server/webhook-handler.mjs +57 -0
  35. package/dist/testing.d.mts +109 -0
  36. package/dist/testing.d.ts +109 -0
  37. package/dist/testing.js +144 -0
  38. package/dist/testing.mjs +138 -0
  39. package/dist/webhook-handler-B2GL4SDl.d.ts +826 -0
  40. package/dist/webhook-handler-D--VG8bN.d.mts +826 -0
  41. package/package.json +1 -1
@@ -0,0 +1,240 @@
1
+ import { ac as StorageAdapter, A as ApiError } from './index-CEi5Nd4L.mjs';
2
+
3
+ /**
4
+ * ScaleMule API Client
5
+ *
6
+ * Core HTTP client that handles:
7
+ * - Automatic x-api-key header injection
8
+ * - Automatic Authorization: Bearer header injection when authenticated
9
+ * - Session token management
10
+ * - Error handling and response parsing
11
+ */
12
+
13
+ type ScaleMuleEnvironment = 'dev' | 'prod';
14
+ interface ClientConfig {
15
+ /** Keep sessions exclusively in HTTP-only cookies. */
16
+ cookieSession?: boolean;
17
+ /** Your ScaleMule API key */
18
+ apiKey: string;
19
+ /** Your ScaleMule Application ID (required for realtime features) */
20
+ applicationId?: string;
21
+ /** Environment: 'dev' or 'prod' - automatically sets gateway URL */
22
+ environment?: ScaleMuleEnvironment;
23
+ /** Custom gateway URL (overrides environment preset) */
24
+ gatewayUrl?: string;
25
+ /** Enable debug logging */
26
+ debug?: boolean;
27
+ /** Custom storage adapter */
28
+ storage?: StorageAdapter;
29
+ /** Enable rate limit queue (automatically queues requests when rate limited) */
30
+ enableRateLimitQueue?: boolean;
31
+ /** Enable offline queue (queues requests when offline, syncs when back online) */
32
+ enableOfflineQueue?: boolean;
33
+ /**
34
+ * Signal that a session will be established asynchronously (e.g. via auth proxy).
35
+ * When true, API requests will wait for the session to be resolved before sending,
36
+ * preventing race conditions where requests fire before the auth token is available.
37
+ */
38
+ pendingSessionInit?: boolean;
39
+ /** Enable the account switcher */
40
+ enableAccountSwitcher?: boolean;
41
+ /** Privacy level for account switcher */
42
+ accountSwitcherPrivacy?: 'full' | 'masked' | 'minimal';
43
+ /** Optional: Callback when a 401 auto-refresh starts. */
44
+ onRefreshStart?: () => void;
45
+ /** Optional: Callback when a 401 auto-refresh finishes. */
46
+ onRefreshEnd?: () => void;
47
+ /** Optional: Callback when an automatic 401 refresh fails. */
48
+ onAutoRefreshFailed?: (error: ApiError) => void;
49
+ }
50
+ interface RequestOptions extends RequestInit {
51
+ /** Skip adding auth headers (for public endpoints) */
52
+ skipAuth?: boolean;
53
+ /** Custom timeout in milliseconds */
54
+ timeout?: number;
55
+ /** Number of retry attempts for transient failures (default: 2) */
56
+ retries?: number;
57
+ /** Skip retries */
58
+ skipRetry?: boolean;
59
+ /** Internal flag to prevent infinite refresh loops */
60
+ isAutoRefresh?: boolean;
61
+ }
62
+ /**
63
+ * ScaleMule API Client
64
+ *
65
+ * Handles all HTTP communication with the ScaleMule gateway.
66
+ */
67
+ declare class ScaleMuleClient {
68
+ private apiKey;
69
+ private applicationId;
70
+ private gatewayUrl;
71
+ private debug;
72
+ private storage;
73
+ private cookieSession;
74
+ private sessionToken;
75
+ private userId;
76
+ private rateLimitQueue;
77
+ private offlineQueue;
78
+ private enableRateLimitQueue;
79
+ private enableOfflineQueue;
80
+ private sessionGate;
81
+ private resolveSessionGate;
82
+ private workspaceId;
83
+ private anonymousId;
84
+ private anonymousIdPromise;
85
+ private refreshPromise;
86
+ private onRefreshStart?;
87
+ private onRefreshEnd?;
88
+ private onAutoRefreshFailed?;
89
+ constructor(config: ClientConfig);
90
+ /**
91
+ * Sync offline queue when coming back online
92
+ */
93
+ private syncOfflineQueue;
94
+ /**
95
+ * Check if client is online
96
+ */
97
+ isOnline(): boolean;
98
+ /**
99
+ * Get number of pending offline requests
100
+ */
101
+ getOfflineQueueLength(): number;
102
+ /**
103
+ * Get number of pending rate-limited requests
104
+ */
105
+ getRateLimitQueueLength(): number;
106
+ /**
107
+ * Check if currently rate limited
108
+ */
109
+ isRateLimited(): boolean;
110
+ /**
111
+ * Set the active workspace context. All subsequent requests will include
112
+ * x-sm-workspace-id header. Pass null to clear.
113
+ */
114
+ setWorkspaceContext(id: string | null): void;
115
+ /**
116
+ * Get the current workspace ID
117
+ */
118
+ getWorkspaceId(): string | null;
119
+ /**
120
+ * Get the gateway URL
121
+ */
122
+ getGatewayUrl(): string;
123
+ /**
124
+ * Get the application ID (required for realtime features)
125
+ */
126
+ getApplicationId(): string | null;
127
+ /**
128
+ * Signal that a session is being established asynchronously.
129
+ * API requests will wait until resolveSessionPending() is called.
130
+ */
131
+ setSessionPending(): void;
132
+ /**
133
+ * Resolve the pending session gate, allowing queued API requests to proceed.
134
+ * Must be called after setSessionPending(), whether session was established or not.
135
+ */
136
+ resolveSessionPending(): void;
137
+ /**
138
+ * Initialize client by loading persisted session
139
+ */
140
+ initialize(): Promise<void>;
141
+ /**
142
+ * Sync accessor for the cached anonymous ID. Returns `null` until either
143
+ * `initialize()` has run or `ensureAnonymousId()` has been awaited at
144
+ * least once. Use `ensureAnonymousId()` if you need a guaranteed value.
145
+ */
146
+ getAnonymousId(): string | null;
147
+ /**
148
+ * Lazy-mint or cache-then-return the anonymous ID via the shared
149
+ * `@scalemule/sdk` helper. Concurrent callers receive the same in-flight
150
+ * promise, so a burst of simultaneous first-use requests all see the
151
+ * same minted value.
152
+ */
153
+ ensureAnonymousId(): Promise<string>;
154
+ /**
155
+ * Set session after login
156
+ */
157
+ setSession(token: string, userId: string): Promise<void>;
158
+ /**
159
+ * Token-only setter for member-auth surfaces.
160
+ *
161
+ * Unlike `setSession(token, userId)`, this does NOT persist a userId or
162
+ * write to local storage — useful when the host platform owns identity
163
+ * (e.g. ScaleMule's member dashboards use `MemberAuthProvider` and the
164
+ * token comes from a `${env}_member_access_token` cookie). The token is
165
+ * applied in-memory and used as a `Bearer` Authorization header on
166
+ * subsequent requests.
167
+ *
168
+ * Pass `null` to clear without touching userId/storage.
169
+ */
170
+ setCookieSession(userId: string | null): void;
171
+ usesCookieSession(): boolean;
172
+ setSessionToken(token: string | null): void;
173
+ /**
174
+ * Clear session on logout
175
+ */
176
+ clearSession(): Promise<void>;
177
+ /**
178
+ * Get current session token
179
+ */
180
+ getSessionToken(): string | null;
181
+ /**
182
+ * Get current user ID
183
+ */
184
+ getUserId(): string | null;
185
+ /**
186
+ * Check if client has an active session
187
+ */
188
+ isAuthenticated(): boolean;
189
+ /**
190
+ * Build headers for a request
191
+ */
192
+ private buildHeaders;
193
+ /**
194
+ * Make an HTTP request to the ScaleMule API
195
+ */
196
+ request<T>(path: string, options?: RequestOptions): Promise<T>;
197
+ /**
198
+ * GET request
199
+ */
200
+ get<T>(path: string, options?: RequestOptions): Promise<T>;
201
+ /**
202
+ * POST request with JSON body
203
+ */
204
+ post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
205
+ /**
206
+ * PUT request with JSON body
207
+ */
208
+ put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
209
+ /**
210
+ * PATCH request with JSON body
211
+ */
212
+ patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
213
+ /**
214
+ * DELETE request
215
+ */
216
+ delete<T>(path: string, options?: RequestOptions): Promise<T>;
217
+ /**
218
+ * Upload a file using multipart/form-data
219
+ *
220
+ * Automatically includes Authorization: Bearer header for user identity.
221
+ * Supports progress callback via XMLHttpRequest when onProgress is provided.
222
+ */
223
+ upload<T>(path: string, file: File, additionalFields?: Record<string, string>, options?: RequestOptions & {
224
+ onProgress?: (progress: number) => void;
225
+ }): Promise<T>;
226
+ /**
227
+ * Upload with progress using XMLHttpRequest (with retry)
228
+ */
229
+ private uploadWithProgress;
230
+ /**
231
+ * Single upload attempt with progress using XMLHttpRequest
232
+ */
233
+ private singleUploadWithProgress;
234
+ }
235
+ /**
236
+ * Create a new ScaleMule client instance
237
+ */
238
+ declare function createClient(config: ClientConfig): ScaleMuleClient;
239
+
240
+ export { type ClientConfig, type RequestOptions, ScaleMuleClient, type ScaleMuleEnvironment, createClient };
@@ -0,0 +1,240 @@
1
+ import { ac as StorageAdapter, A as ApiError } from './index-CEi5Nd4L.js';
2
+
3
+ /**
4
+ * ScaleMule API Client
5
+ *
6
+ * Core HTTP client that handles:
7
+ * - Automatic x-api-key header injection
8
+ * - Automatic Authorization: Bearer header injection when authenticated
9
+ * - Session token management
10
+ * - Error handling and response parsing
11
+ */
12
+
13
+ type ScaleMuleEnvironment = 'dev' | 'prod';
14
+ interface ClientConfig {
15
+ /** Keep sessions exclusively in HTTP-only cookies. */
16
+ cookieSession?: boolean;
17
+ /** Your ScaleMule API key */
18
+ apiKey: string;
19
+ /** Your ScaleMule Application ID (required for realtime features) */
20
+ applicationId?: string;
21
+ /** Environment: 'dev' or 'prod' - automatically sets gateway URL */
22
+ environment?: ScaleMuleEnvironment;
23
+ /** Custom gateway URL (overrides environment preset) */
24
+ gatewayUrl?: string;
25
+ /** Enable debug logging */
26
+ debug?: boolean;
27
+ /** Custom storage adapter */
28
+ storage?: StorageAdapter;
29
+ /** Enable rate limit queue (automatically queues requests when rate limited) */
30
+ enableRateLimitQueue?: boolean;
31
+ /** Enable offline queue (queues requests when offline, syncs when back online) */
32
+ enableOfflineQueue?: boolean;
33
+ /**
34
+ * Signal that a session will be established asynchronously (e.g. via auth proxy).
35
+ * When true, API requests will wait for the session to be resolved before sending,
36
+ * preventing race conditions where requests fire before the auth token is available.
37
+ */
38
+ pendingSessionInit?: boolean;
39
+ /** Enable the account switcher */
40
+ enableAccountSwitcher?: boolean;
41
+ /** Privacy level for account switcher */
42
+ accountSwitcherPrivacy?: 'full' | 'masked' | 'minimal';
43
+ /** Optional: Callback when a 401 auto-refresh starts. */
44
+ onRefreshStart?: () => void;
45
+ /** Optional: Callback when a 401 auto-refresh finishes. */
46
+ onRefreshEnd?: () => void;
47
+ /** Optional: Callback when an automatic 401 refresh fails. */
48
+ onAutoRefreshFailed?: (error: ApiError) => void;
49
+ }
50
+ interface RequestOptions extends RequestInit {
51
+ /** Skip adding auth headers (for public endpoints) */
52
+ skipAuth?: boolean;
53
+ /** Custom timeout in milliseconds */
54
+ timeout?: number;
55
+ /** Number of retry attempts for transient failures (default: 2) */
56
+ retries?: number;
57
+ /** Skip retries */
58
+ skipRetry?: boolean;
59
+ /** Internal flag to prevent infinite refresh loops */
60
+ isAutoRefresh?: boolean;
61
+ }
62
+ /**
63
+ * ScaleMule API Client
64
+ *
65
+ * Handles all HTTP communication with the ScaleMule gateway.
66
+ */
67
+ declare class ScaleMuleClient {
68
+ private apiKey;
69
+ private applicationId;
70
+ private gatewayUrl;
71
+ private debug;
72
+ private storage;
73
+ private cookieSession;
74
+ private sessionToken;
75
+ private userId;
76
+ private rateLimitQueue;
77
+ private offlineQueue;
78
+ private enableRateLimitQueue;
79
+ private enableOfflineQueue;
80
+ private sessionGate;
81
+ private resolveSessionGate;
82
+ private workspaceId;
83
+ private anonymousId;
84
+ private anonymousIdPromise;
85
+ private refreshPromise;
86
+ private onRefreshStart?;
87
+ private onRefreshEnd?;
88
+ private onAutoRefreshFailed?;
89
+ constructor(config: ClientConfig);
90
+ /**
91
+ * Sync offline queue when coming back online
92
+ */
93
+ private syncOfflineQueue;
94
+ /**
95
+ * Check if client is online
96
+ */
97
+ isOnline(): boolean;
98
+ /**
99
+ * Get number of pending offline requests
100
+ */
101
+ getOfflineQueueLength(): number;
102
+ /**
103
+ * Get number of pending rate-limited requests
104
+ */
105
+ getRateLimitQueueLength(): number;
106
+ /**
107
+ * Check if currently rate limited
108
+ */
109
+ isRateLimited(): boolean;
110
+ /**
111
+ * Set the active workspace context. All subsequent requests will include
112
+ * x-sm-workspace-id header. Pass null to clear.
113
+ */
114
+ setWorkspaceContext(id: string | null): void;
115
+ /**
116
+ * Get the current workspace ID
117
+ */
118
+ getWorkspaceId(): string | null;
119
+ /**
120
+ * Get the gateway URL
121
+ */
122
+ getGatewayUrl(): string;
123
+ /**
124
+ * Get the application ID (required for realtime features)
125
+ */
126
+ getApplicationId(): string | null;
127
+ /**
128
+ * Signal that a session is being established asynchronously.
129
+ * API requests will wait until resolveSessionPending() is called.
130
+ */
131
+ setSessionPending(): void;
132
+ /**
133
+ * Resolve the pending session gate, allowing queued API requests to proceed.
134
+ * Must be called after setSessionPending(), whether session was established or not.
135
+ */
136
+ resolveSessionPending(): void;
137
+ /**
138
+ * Initialize client by loading persisted session
139
+ */
140
+ initialize(): Promise<void>;
141
+ /**
142
+ * Sync accessor for the cached anonymous ID. Returns `null` until either
143
+ * `initialize()` has run or `ensureAnonymousId()` has been awaited at
144
+ * least once. Use `ensureAnonymousId()` if you need a guaranteed value.
145
+ */
146
+ getAnonymousId(): string | null;
147
+ /**
148
+ * Lazy-mint or cache-then-return the anonymous ID via the shared
149
+ * `@scalemule/sdk` helper. Concurrent callers receive the same in-flight
150
+ * promise, so a burst of simultaneous first-use requests all see the
151
+ * same minted value.
152
+ */
153
+ ensureAnonymousId(): Promise<string>;
154
+ /**
155
+ * Set session after login
156
+ */
157
+ setSession(token: string, userId: string): Promise<void>;
158
+ /**
159
+ * Token-only setter for member-auth surfaces.
160
+ *
161
+ * Unlike `setSession(token, userId)`, this does NOT persist a userId or
162
+ * write to local storage — useful when the host platform owns identity
163
+ * (e.g. ScaleMule's member dashboards use `MemberAuthProvider` and the
164
+ * token comes from a `${env}_member_access_token` cookie). The token is
165
+ * applied in-memory and used as a `Bearer` Authorization header on
166
+ * subsequent requests.
167
+ *
168
+ * Pass `null` to clear without touching userId/storage.
169
+ */
170
+ setCookieSession(userId: string | null): void;
171
+ usesCookieSession(): boolean;
172
+ setSessionToken(token: string | null): void;
173
+ /**
174
+ * Clear session on logout
175
+ */
176
+ clearSession(): Promise<void>;
177
+ /**
178
+ * Get current session token
179
+ */
180
+ getSessionToken(): string | null;
181
+ /**
182
+ * Get current user ID
183
+ */
184
+ getUserId(): string | null;
185
+ /**
186
+ * Check if client has an active session
187
+ */
188
+ isAuthenticated(): boolean;
189
+ /**
190
+ * Build headers for a request
191
+ */
192
+ private buildHeaders;
193
+ /**
194
+ * Make an HTTP request to the ScaleMule API
195
+ */
196
+ request<T>(path: string, options?: RequestOptions): Promise<T>;
197
+ /**
198
+ * GET request
199
+ */
200
+ get<T>(path: string, options?: RequestOptions): Promise<T>;
201
+ /**
202
+ * POST request with JSON body
203
+ */
204
+ post<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
205
+ /**
206
+ * PUT request with JSON body
207
+ */
208
+ put<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
209
+ /**
210
+ * PATCH request with JSON body
211
+ */
212
+ patch<T>(path: string, body?: unknown, options?: RequestOptions): Promise<T>;
213
+ /**
214
+ * DELETE request
215
+ */
216
+ delete<T>(path: string, options?: RequestOptions): Promise<T>;
217
+ /**
218
+ * Upload a file using multipart/form-data
219
+ *
220
+ * Automatically includes Authorization: Bearer header for user identity.
221
+ * Supports progress callback via XMLHttpRequest when onProgress is provided.
222
+ */
223
+ upload<T>(path: string, file: File, additionalFields?: Record<string, string>, options?: RequestOptions & {
224
+ onProgress?: (progress: number) => void;
225
+ }): Promise<T>;
226
+ /**
227
+ * Upload with progress using XMLHttpRequest (with retry)
228
+ */
229
+ private uploadWithProgress;
230
+ /**
231
+ * Single upload attempt with progress using XMLHttpRequest
232
+ */
233
+ private singleUploadWithProgress;
234
+ }
235
+ /**
236
+ * Create a new ScaleMule client instance
237
+ */
238
+ declare function createClient(config: ClientConfig): ScaleMuleClient;
239
+
240
+ export { type ClientConfig, type RequestOptions, ScaleMuleClient, type ScaleMuleEnvironment, createClient };