@scalemule/nextjs 0.0.1

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/dist/client.js ADDED
@@ -0,0 +1,700 @@
1
+ 'use strict';
2
+
3
+ // src/client.ts
4
+ var GATEWAY_URLS = {
5
+ dev: "https://api-dev.scalemule.com",
6
+ prod: "https://api.scalemule.com"
7
+ };
8
+ var SESSION_STORAGE_KEY = "scalemule_session";
9
+ var USER_ID_STORAGE_KEY = "scalemule_user_id";
10
+ var RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([408, 429, 500, 502, 503, 504]);
11
+ function sleep(ms) {
12
+ return new Promise((resolve) => setTimeout(resolve, ms));
13
+ }
14
+ function getBackoffDelay(attempt, baseDelay = 1e3) {
15
+ const exponentialDelay = baseDelay * Math.pow(2, attempt);
16
+ const jitter = Math.random() * 0.3 * exponentialDelay;
17
+ return Math.min(exponentialDelay + jitter, 3e4);
18
+ }
19
+ function sanitizeFilename(filename) {
20
+ let sanitized = filename.replace(/[\x00-\x1f\x7f]/g, "");
21
+ sanitized = sanitized.replace(/["\\/\n\r]/g, "_").normalize("NFC").replace(/[\u200b-\u200f\ufeff\u2028\u2029]/g, "");
22
+ if (!sanitized || sanitized.trim() === "") {
23
+ sanitized = "unnamed";
24
+ }
25
+ if (sanitized.length > 200) {
26
+ const ext = sanitized.split(".").pop();
27
+ const base = sanitized.substring(0, 190);
28
+ sanitized = ext ? `${base}.${ext}` : base;
29
+ }
30
+ return sanitized.trim();
31
+ }
32
+ var RateLimitQueue = class {
33
+ constructor() {
34
+ this.queue = [];
35
+ this.processing = false;
36
+ this.rateLimitedUntil = 0;
37
+ this.requestsInWindow = 0;
38
+ this.windowStart = Date.now();
39
+ this.maxRequestsPerWindow = 100;
40
+ this.windowDurationMs = 6e4;
41
+ }
42
+ // 1 minute
43
+ /**
44
+ * Add request to queue
45
+ */
46
+ enqueue(execute, priority = 0) {
47
+ return new Promise((resolve, reject) => {
48
+ this.queue.push({
49
+ execute,
50
+ resolve,
51
+ reject,
52
+ priority
53
+ });
54
+ this.queue.sort((a, b) => b.priority - a.priority);
55
+ this.processQueue();
56
+ });
57
+ }
58
+ /**
59
+ * Process queued requests
60
+ */
61
+ async processQueue() {
62
+ if (this.processing || this.queue.length === 0) return;
63
+ this.processing = true;
64
+ while (this.queue.length > 0) {
65
+ const now = Date.now();
66
+ if (now < this.rateLimitedUntil) {
67
+ const waitTime = this.rateLimitedUntil - now;
68
+ await sleep(waitTime);
69
+ }
70
+ if (now - this.windowStart >= this.windowDurationMs) {
71
+ this.windowStart = now;
72
+ this.requestsInWindow = 0;
73
+ }
74
+ if (this.requestsInWindow >= this.maxRequestsPerWindow) {
75
+ const waitTime = this.windowDurationMs - (now - this.windowStart);
76
+ await sleep(waitTime);
77
+ this.windowStart = Date.now();
78
+ this.requestsInWindow = 0;
79
+ }
80
+ const request = this.queue.shift();
81
+ if (!request) continue;
82
+ try {
83
+ this.requestsInWindow++;
84
+ const result = await request.execute();
85
+ if (!result.success && result.error?.code === "RATE_LIMITED") {
86
+ this.queue.unshift(request);
87
+ this.rateLimitedUntil = Date.now() + 6e4;
88
+ } else {
89
+ request.resolve(result);
90
+ }
91
+ } catch (error) {
92
+ request.reject(error);
93
+ }
94
+ }
95
+ this.processing = false;
96
+ }
97
+ /**
98
+ * Update rate limit from response headers
99
+ */
100
+ updateFromHeaders(headers) {
101
+ const retryAfter = headers.get("Retry-After");
102
+ if (retryAfter) {
103
+ const seconds = parseInt(retryAfter, 10);
104
+ if (!isNaN(seconds)) {
105
+ this.rateLimitedUntil = Date.now() + seconds * 1e3;
106
+ }
107
+ }
108
+ const remaining = headers.get("X-RateLimit-Remaining");
109
+ if (remaining) {
110
+ const count = parseInt(remaining, 10);
111
+ if (!isNaN(count) && count === 0) {
112
+ const reset = headers.get("X-RateLimit-Reset");
113
+ if (reset) {
114
+ const resetTime = parseInt(reset, 10) * 1e3;
115
+ if (!isNaN(resetTime)) {
116
+ this.rateLimitedUntil = resetTime;
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+ /**
123
+ * Get queue length
124
+ */
125
+ get length() {
126
+ return this.queue.length;
127
+ }
128
+ /**
129
+ * Check if rate limited
130
+ */
131
+ get isRateLimited() {
132
+ return Date.now() < this.rateLimitedUntil;
133
+ }
134
+ };
135
+ var OfflineQueue = class {
136
+ constructor(storage) {
137
+ this.queue = [];
138
+ this.storageKey = "scalemule_offline_queue";
139
+ this.isOnline = true;
140
+ this.onOnline = null;
141
+ this.storage = storage;
142
+ this.loadFromStorage();
143
+ this.setupOnlineListener();
144
+ }
145
+ /**
146
+ * Setup online/offline event listeners
147
+ */
148
+ setupOnlineListener() {
149
+ if (typeof window === "undefined") return;
150
+ this.isOnline = navigator.onLine;
151
+ window.addEventListener("online", () => {
152
+ this.isOnline = true;
153
+ if (this.onOnline) this.onOnline();
154
+ });
155
+ window.addEventListener("offline", () => {
156
+ this.isOnline = false;
157
+ });
158
+ }
159
+ /**
160
+ * Load queue from storage
161
+ */
162
+ async loadFromStorage() {
163
+ try {
164
+ const data = await this.storage.getItem(this.storageKey);
165
+ if (data) {
166
+ this.queue = JSON.parse(data);
167
+ }
168
+ } catch {
169
+ }
170
+ }
171
+ /**
172
+ * Save queue to storage
173
+ */
174
+ async saveToStorage() {
175
+ try {
176
+ await this.storage.setItem(this.storageKey, JSON.stringify(this.queue));
177
+ } catch {
178
+ }
179
+ }
180
+ /**
181
+ * Add request to offline queue
182
+ */
183
+ async add(method, path, body) {
184
+ const item = {
185
+ id: `${Date.now()}-${Math.random().toString(36).slice(2)}`,
186
+ method,
187
+ path,
188
+ body: body ? JSON.stringify(body) : void 0,
189
+ timestamp: Date.now()
190
+ };
191
+ this.queue.push(item);
192
+ await this.saveToStorage();
193
+ }
194
+ /**
195
+ * Get all queued requests
196
+ */
197
+ getAll() {
198
+ return [...this.queue];
199
+ }
200
+ /**
201
+ * Remove a request from queue
202
+ */
203
+ async remove(id) {
204
+ this.queue = this.queue.filter((item) => item.id !== id);
205
+ await this.saveToStorage();
206
+ }
207
+ /**
208
+ * Clear all queued requests
209
+ */
210
+ async clear() {
211
+ this.queue = [];
212
+ await this.saveToStorage();
213
+ }
214
+ /**
215
+ * Set callback for when coming back online
216
+ */
217
+ setOnlineCallback(callback) {
218
+ this.onOnline = callback;
219
+ }
220
+ /**
221
+ * Check if currently online
222
+ */
223
+ get online() {
224
+ return this.isOnline;
225
+ }
226
+ /**
227
+ * Get queue length
228
+ */
229
+ get length() {
230
+ return this.queue.length;
231
+ }
232
+ };
233
+ function resolveGatewayUrl(config) {
234
+ if (config.gatewayUrl) {
235
+ return config.gatewayUrl;
236
+ }
237
+ const env = config.environment || "prod";
238
+ return GATEWAY_URLS[env];
239
+ }
240
+ function createDefaultStorage() {
241
+ if (typeof window !== "undefined" && window.localStorage) {
242
+ return {
243
+ getItem: (key) => localStorage.getItem(key),
244
+ setItem: (key, value) => localStorage.setItem(key, value),
245
+ removeItem: (key) => localStorage.removeItem(key)
246
+ };
247
+ }
248
+ const memoryStorage = /* @__PURE__ */ new Map();
249
+ return {
250
+ getItem: (key) => memoryStorage.get(key) ?? null,
251
+ setItem: (key, value) => {
252
+ memoryStorage.set(key, value);
253
+ },
254
+ removeItem: (key) => {
255
+ memoryStorage.delete(key);
256
+ }
257
+ };
258
+ }
259
+ var ScaleMuleClient = class {
260
+ constructor(config) {
261
+ this.applicationId = null;
262
+ this.sessionToken = null;
263
+ this.userId = null;
264
+ this.rateLimitQueue = null;
265
+ this.offlineQueue = null;
266
+ this.apiKey = config.apiKey;
267
+ this.applicationId = config.applicationId || null;
268
+ this.gatewayUrl = resolveGatewayUrl(config);
269
+ this.debug = config.debug || false;
270
+ this.storage = config.storage || createDefaultStorage();
271
+ this.enableRateLimitQueue = config.enableRateLimitQueue || false;
272
+ this.enableOfflineQueue = config.enableOfflineQueue || false;
273
+ if (this.enableRateLimitQueue) {
274
+ this.rateLimitQueue = new RateLimitQueue();
275
+ }
276
+ if (this.enableOfflineQueue) {
277
+ this.offlineQueue = new OfflineQueue(this.storage);
278
+ this.offlineQueue.setOnlineCallback(() => this.syncOfflineQueue());
279
+ }
280
+ }
281
+ /**
282
+ * Sync offline queue when coming back online
283
+ */
284
+ async syncOfflineQueue() {
285
+ if (!this.offlineQueue) return;
286
+ const items = this.offlineQueue.getAll();
287
+ if (this.debug && items.length > 0) {
288
+ console.log(`[ScaleMule] Syncing ${items.length} offline requests`);
289
+ }
290
+ for (const item of items) {
291
+ try {
292
+ await this.request(item.path, {
293
+ method: item.method,
294
+ body: item.body,
295
+ skipRetry: true
296
+ });
297
+ await this.offlineQueue.remove(item.id);
298
+ } catch (err) {
299
+ if (this.debug) {
300
+ console.error("[ScaleMule] Failed to sync offline request:", err);
301
+ }
302
+ break;
303
+ }
304
+ }
305
+ }
306
+ /**
307
+ * Check if client is online
308
+ */
309
+ isOnline() {
310
+ if (this.offlineQueue) {
311
+ return this.offlineQueue.online;
312
+ }
313
+ return typeof navigator === "undefined" || navigator.onLine;
314
+ }
315
+ /**
316
+ * Get number of pending offline requests
317
+ */
318
+ getOfflineQueueLength() {
319
+ return this.offlineQueue?.length || 0;
320
+ }
321
+ /**
322
+ * Get number of pending rate-limited requests
323
+ */
324
+ getRateLimitQueueLength() {
325
+ return this.rateLimitQueue?.length || 0;
326
+ }
327
+ /**
328
+ * Check if currently rate limited
329
+ */
330
+ isRateLimited() {
331
+ return this.rateLimitQueue?.isRateLimited || false;
332
+ }
333
+ /**
334
+ * Get the gateway URL
335
+ */
336
+ getGatewayUrl() {
337
+ return this.gatewayUrl;
338
+ }
339
+ /**
340
+ * Get the application ID (required for realtime features)
341
+ */
342
+ getApplicationId() {
343
+ return this.applicationId;
344
+ }
345
+ /**
346
+ * Initialize client by loading persisted session
347
+ */
348
+ async initialize() {
349
+ const token = await this.storage.getItem(SESSION_STORAGE_KEY);
350
+ const userId = await this.storage.getItem(USER_ID_STORAGE_KEY);
351
+ if (token) this.sessionToken = token;
352
+ if (userId) this.userId = userId;
353
+ if (this.debug) {
354
+ console.log("[ScaleMule] Initialized with session:", !!token);
355
+ }
356
+ }
357
+ /**
358
+ * Set session after login
359
+ */
360
+ async setSession(token, userId) {
361
+ this.sessionToken = token;
362
+ this.userId = userId;
363
+ await this.storage.setItem(SESSION_STORAGE_KEY, token);
364
+ await this.storage.setItem(USER_ID_STORAGE_KEY, userId);
365
+ if (this.debug) {
366
+ console.log("[ScaleMule] Session set for user:", userId);
367
+ }
368
+ }
369
+ /**
370
+ * Clear session on logout
371
+ */
372
+ async clearSession() {
373
+ this.sessionToken = null;
374
+ this.userId = null;
375
+ await this.storage.removeItem(SESSION_STORAGE_KEY);
376
+ await this.storage.removeItem(USER_ID_STORAGE_KEY);
377
+ if (this.debug) {
378
+ console.log("[ScaleMule] Session cleared");
379
+ }
380
+ }
381
+ /**
382
+ * Get current session token
383
+ */
384
+ getSessionToken() {
385
+ return this.sessionToken;
386
+ }
387
+ /**
388
+ * Get current user ID
389
+ */
390
+ getUserId() {
391
+ return this.userId;
392
+ }
393
+ /**
394
+ * Check if client has an active session
395
+ */
396
+ isAuthenticated() {
397
+ return this.sessionToken !== null && this.userId !== null;
398
+ }
399
+ /**
400
+ * Build headers for a request
401
+ */
402
+ buildHeaders(options) {
403
+ const headers = new Headers(options?.headers);
404
+ headers.set("x-api-key", this.apiKey);
405
+ if (!options?.skipAuth && this.sessionToken) {
406
+ headers.set("Authorization", `Bearer ${this.sessionToken}`);
407
+ }
408
+ if (!headers.has("Content-Type") && options?.body && typeof options.body === "string") {
409
+ headers.set("Content-Type", "application/json");
410
+ }
411
+ return headers;
412
+ }
413
+ /**
414
+ * Make an HTTP request to the ScaleMule API
415
+ */
416
+ async request(path, options = {}) {
417
+ const url = `${this.gatewayUrl}${path}`;
418
+ const headers = this.buildHeaders(options);
419
+ const maxRetries = options.skipRetry ? 0 : options.retries ?? 2;
420
+ const timeout = options.timeout || 3e4;
421
+ if (this.debug) {
422
+ console.log(`[ScaleMule] ${options.method || "GET"} ${path}`);
423
+ }
424
+ let lastError = null;
425
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
426
+ const controller = new AbortController();
427
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
428
+ try {
429
+ const response = await fetch(url, {
430
+ ...options,
431
+ headers,
432
+ signal: controller.signal
433
+ });
434
+ clearTimeout(timeoutId);
435
+ const data = await response.json();
436
+ if (!response.ok) {
437
+ const error = data.error || {
438
+ code: `HTTP_${response.status}`,
439
+ message: data.message || response.statusText
440
+ };
441
+ if (attempt < maxRetries && RETRYABLE_STATUS_CODES.has(response.status)) {
442
+ lastError = error;
443
+ const delay = getBackoffDelay(attempt);
444
+ if (this.debug) {
445
+ console.log(`[ScaleMule] Retrying in ${delay}ms (attempt ${attempt + 1}/${maxRetries})`);
446
+ }
447
+ await sleep(delay);
448
+ continue;
449
+ }
450
+ if (this.debug) {
451
+ console.error("[ScaleMule] Request failed:", error);
452
+ }
453
+ return { success: false, error };
454
+ }
455
+ return data;
456
+ } catch (err) {
457
+ clearTimeout(timeoutId);
458
+ const error = {
459
+ code: err instanceof Error && err.name === "AbortError" ? "TIMEOUT" : "NETWORK_ERROR",
460
+ message: err instanceof Error ? err.message : "Network request failed"
461
+ };
462
+ if (attempt < maxRetries) {
463
+ lastError = error;
464
+ const delay = getBackoffDelay(attempt);
465
+ if (this.debug) {
466
+ console.log(`[ScaleMule] Retrying after error in ${delay}ms (attempt ${attempt + 1}/${maxRetries})`);
467
+ }
468
+ await sleep(delay);
469
+ continue;
470
+ }
471
+ if (this.debug) {
472
+ console.error("[ScaleMule] Network error:", err);
473
+ }
474
+ return { success: false, error };
475
+ }
476
+ }
477
+ return { success: false, error: lastError || { code: "UNKNOWN", message: "Request failed" } };
478
+ }
479
+ /**
480
+ * GET request
481
+ */
482
+ async get(path, options) {
483
+ return this.request(path, { ...options, method: "GET" });
484
+ }
485
+ /**
486
+ * POST request with JSON body
487
+ */
488
+ async post(path, body, options) {
489
+ return this.request(path, {
490
+ ...options,
491
+ method: "POST",
492
+ body: body ? JSON.stringify(body) : void 0
493
+ });
494
+ }
495
+ /**
496
+ * PUT request with JSON body
497
+ */
498
+ async put(path, body, options) {
499
+ return this.request(path, {
500
+ ...options,
501
+ method: "PUT",
502
+ body: body ? JSON.stringify(body) : void 0
503
+ });
504
+ }
505
+ /**
506
+ * PATCH request with JSON body
507
+ */
508
+ async patch(path, body, options) {
509
+ return this.request(path, {
510
+ ...options,
511
+ method: "PATCH",
512
+ body: body ? JSON.stringify(body) : void 0
513
+ });
514
+ }
515
+ /**
516
+ * DELETE request
517
+ */
518
+ async delete(path, options) {
519
+ return this.request(path, { ...options, method: "DELETE" });
520
+ }
521
+ /**
522
+ * Upload a file using multipart/form-data
523
+ *
524
+ * Automatically includes Authorization: Bearer header for user identity.
525
+ * Supports progress callback via XMLHttpRequest when onProgress is provided.
526
+ */
527
+ async upload(path, file, additionalFields, options) {
528
+ const sanitizedName = sanitizeFilename(file.name);
529
+ const sanitizedFile = sanitizedName !== file.name ? new File([file], sanitizedName, { type: file.type }) : file;
530
+ const formData = new FormData();
531
+ formData.append("file", sanitizedFile);
532
+ if (this.userId) {
533
+ formData.append("sm_user_id", this.userId);
534
+ }
535
+ if (additionalFields) {
536
+ for (const [key, value] of Object.entries(additionalFields)) {
537
+ formData.append(key, value);
538
+ }
539
+ }
540
+ const url = `${this.gatewayUrl}${path}`;
541
+ if (this.debug) {
542
+ console.log(`[ScaleMule] UPLOAD ${path}`);
543
+ }
544
+ if (options?.onProgress && typeof XMLHttpRequest !== "undefined") {
545
+ return this.uploadWithProgress(url, formData, options.onProgress);
546
+ }
547
+ const maxRetries = options?.retries ?? 2;
548
+ const headers = new Headers();
549
+ headers.set("x-api-key", this.apiKey);
550
+ if (this.sessionToken) {
551
+ headers.set("Authorization", `Bearer ${this.sessionToken}`);
552
+ }
553
+ let lastError = null;
554
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
555
+ try {
556
+ const retryFormData = attempt === 0 ? formData : new FormData();
557
+ if (attempt > 0) {
558
+ retryFormData.append("file", sanitizedFile);
559
+ if (this.userId) {
560
+ retryFormData.append("sm_user_id", this.userId);
561
+ }
562
+ if (additionalFields) {
563
+ for (const [key, value] of Object.entries(additionalFields)) {
564
+ retryFormData.append(key, value);
565
+ }
566
+ }
567
+ }
568
+ const response = await fetch(url, {
569
+ method: "POST",
570
+ headers,
571
+ body: retryFormData
572
+ });
573
+ const data = await response.json();
574
+ if (!response.ok) {
575
+ const error = data.error || {
576
+ code: `HTTP_${response.status}`,
577
+ message: data.message || response.statusText
578
+ };
579
+ if (attempt < maxRetries && RETRYABLE_STATUS_CODES.has(response.status)) {
580
+ lastError = error;
581
+ const delay = getBackoffDelay(attempt);
582
+ if (this.debug) {
583
+ console.log(`[ScaleMule] Upload retry ${attempt + 1}/${maxRetries} after ${delay}ms`);
584
+ }
585
+ await sleep(delay);
586
+ continue;
587
+ }
588
+ return { success: false, error };
589
+ }
590
+ return data;
591
+ } catch (err) {
592
+ lastError = {
593
+ code: "UPLOAD_ERROR",
594
+ message: err instanceof Error ? err.message : "Upload failed"
595
+ };
596
+ if (attempt < maxRetries) {
597
+ const delay = getBackoffDelay(attempt);
598
+ if (this.debug) {
599
+ console.log(`[ScaleMule] Upload retry ${attempt + 1}/${maxRetries} after ${delay}ms (network error)`);
600
+ }
601
+ await sleep(delay);
602
+ continue;
603
+ }
604
+ }
605
+ }
606
+ return {
607
+ success: false,
608
+ error: lastError || { code: "UPLOAD_ERROR", message: "Upload failed after retries" }
609
+ };
610
+ }
611
+ /**
612
+ * Upload with progress using XMLHttpRequest (with retry)
613
+ */
614
+ async uploadWithProgress(url, formData, onProgress, maxRetries = 2) {
615
+ let lastError = null;
616
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
617
+ const result = await this.singleUploadWithProgress(url, formData, onProgress);
618
+ if (result.success) {
619
+ return result;
620
+ }
621
+ const errorCode = result.error?.code || "";
622
+ const isNetworkError = errorCode === "UPLOAD_ERROR" || errorCode === "NETWORK_ERROR";
623
+ const isRetryableHttp = errorCode.startsWith("HTTP_") && RETRYABLE_STATUS_CODES.has(parseInt(errorCode.replace("HTTP_", ""), 10));
624
+ if (attempt < maxRetries && (isNetworkError || isRetryableHttp)) {
625
+ lastError = result.error || null;
626
+ const delay = getBackoffDelay(attempt);
627
+ if (this.debug) {
628
+ console.log(`[ScaleMule] Upload retry ${attempt + 1}/${maxRetries} after ${delay}ms`);
629
+ }
630
+ await sleep(delay);
631
+ onProgress(0);
632
+ continue;
633
+ }
634
+ return result;
635
+ }
636
+ return {
637
+ success: false,
638
+ error: lastError || { code: "UPLOAD_ERROR", message: "Upload failed after retries" }
639
+ };
640
+ }
641
+ /**
642
+ * Single upload attempt with progress using XMLHttpRequest
643
+ */
644
+ singleUploadWithProgress(url, formData, onProgress) {
645
+ return new Promise((resolve) => {
646
+ const xhr = new XMLHttpRequest();
647
+ xhr.upload.addEventListener("progress", (event) => {
648
+ if (event.lengthComputable) {
649
+ const progress = Math.round(event.loaded / event.total * 100);
650
+ onProgress(progress);
651
+ }
652
+ });
653
+ xhr.addEventListener("load", () => {
654
+ try {
655
+ const data = JSON.parse(xhr.responseText);
656
+ if (xhr.status >= 200 && xhr.status < 300) {
657
+ resolve(data);
658
+ } else {
659
+ resolve({
660
+ success: false,
661
+ error: data.error || {
662
+ code: `HTTP_${xhr.status}`,
663
+ message: data.message || "Upload failed"
664
+ }
665
+ });
666
+ }
667
+ } catch {
668
+ resolve({
669
+ success: false,
670
+ error: { code: "PARSE_ERROR", message: "Failed to parse response" }
671
+ });
672
+ }
673
+ });
674
+ xhr.addEventListener("error", () => {
675
+ resolve({
676
+ success: false,
677
+ error: { code: "UPLOAD_ERROR", message: "Upload failed" }
678
+ });
679
+ });
680
+ xhr.addEventListener("abort", () => {
681
+ resolve({
682
+ success: false,
683
+ error: { code: "UPLOAD_ABORTED", message: "Upload cancelled" }
684
+ });
685
+ });
686
+ xhr.open("POST", url);
687
+ xhr.setRequestHeader("x-api-key", this.apiKey);
688
+ if (this.sessionToken) {
689
+ xhr.setRequestHeader("Authorization", `Bearer ${this.sessionToken}`);
690
+ }
691
+ xhr.send(formData);
692
+ });
693
+ }
694
+ };
695
+ function createClient(config) {
696
+ return new ScaleMuleClient(config);
697
+ }
698
+
699
+ exports.ScaleMuleClient = ScaleMuleClient;
700
+ exports.createClient = createClient;