skikrumb-api 2.1.2 → 2.1.3
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/index.js +64 -107
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -64,7 +64,6 @@ class SkiKrumbRealtimeClient {
|
|
|
64
64
|
}
|
|
65
65
|
else if (message.type === 'auth_error' ||
|
|
66
66
|
message.type === 'error') {
|
|
67
|
-
console.error('❌ Authentication/Connection failed:', message.message || message.error);
|
|
68
67
|
(_a = this.websocket) === null || _a === void 0 ? void 0 : _a.close();
|
|
69
68
|
reject(new Error(`Connection failed: ${message.message || message.error}`));
|
|
70
69
|
}
|
|
@@ -108,12 +107,10 @@ class SkiKrumbRealtimeClient {
|
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
catch (error) {
|
|
111
|
-
console.error('❌ Error parsing realtime message:', error);
|
|
112
110
|
this.emit('error', error);
|
|
113
111
|
}
|
|
114
112
|
};
|
|
115
113
|
this.websocket.onerror = (error) => {
|
|
116
|
-
console.warn('⚠️ Realtime connection event');
|
|
117
114
|
this.isConnecting = false;
|
|
118
115
|
this.emit('error', error);
|
|
119
116
|
reject(error);
|
|
@@ -153,9 +150,7 @@ class SkiKrumbRealtimeClient {
|
|
|
153
150
|
const delay = this.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1);
|
|
154
151
|
setTimeout(() => {
|
|
155
152
|
this.connect().catch((error) => {
|
|
156
|
-
console.error('❌ Reconnect failed:', error);
|
|
157
153
|
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
158
|
-
console.error('❌ Max reconnect attempts reached');
|
|
159
154
|
this.emit('max_reconnect_attempts_reached');
|
|
160
155
|
}
|
|
161
156
|
});
|
|
@@ -213,9 +208,7 @@ class SkiKrumbRealtimeClient {
|
|
|
213
208
|
try {
|
|
214
209
|
callback(data);
|
|
215
210
|
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
console.error(`❌ Error in realtime event listener for '${event}':`, error);
|
|
218
|
-
}
|
|
211
|
+
catch (error) { }
|
|
219
212
|
});
|
|
220
213
|
}
|
|
221
214
|
isConnected() {
|
|
@@ -319,115 +312,79 @@ export const skiKrumb = (options = {
|
|
|
319
312
|
}
|
|
320
313
|
};
|
|
321
314
|
const sendMobileLocation = async (payload) => {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
return response;
|
|
327
|
-
}
|
|
328
|
-
catch (error) {
|
|
329
|
-
console.error('❌ Send Mobile Location Error:', error);
|
|
330
|
-
throw error;
|
|
331
|
-
}
|
|
315
|
+
const response = await request
|
|
316
|
+
.post('devices/location/mobile', { json: payload })
|
|
317
|
+
.json();
|
|
318
|
+
return response;
|
|
332
319
|
};
|
|
333
320
|
const authenticateExternalUser = async (userData) => {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
return response;
|
|
339
|
-
}
|
|
340
|
-
catch (error) {
|
|
341
|
-
console.error('❌ External User Authentication Error:', error);
|
|
342
|
-
throw error;
|
|
343
|
-
}
|
|
321
|
+
const response = await request
|
|
322
|
+
.post('auth/external', { json: userData })
|
|
323
|
+
.json();
|
|
324
|
+
return response;
|
|
344
325
|
};
|
|
345
326
|
const refreshSessionToken = async (currentToken) => {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
};
|
|
364
|
-
}
|
|
365
|
-
catch (error) {
|
|
366
|
-
console.error('❌ Token Refresh Error:', error);
|
|
367
|
-
throw error;
|
|
368
|
-
}
|
|
327
|
+
// Create temporary request with current token
|
|
328
|
+
const refreshRequest = ky.create({
|
|
329
|
+
prefixUrl: options.url,
|
|
330
|
+
headers: {
|
|
331
|
+
'Content-Type': 'application/json',
|
|
332
|
+
Authorization: `Bearer ${currentToken}`,
|
|
333
|
+
'x-client': options.requestedWith,
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
const response = await refreshRequest.post('auth/external/refresh').json();
|
|
337
|
+
return {
|
|
338
|
+
success: response.success,
|
|
339
|
+
sessionToken: response.sessionToken,
|
|
340
|
+
accessibleSerials: response.accessibleSerials,
|
|
341
|
+
serialsCount: response.serialsCount,
|
|
342
|
+
timestamp: response.timestamp,
|
|
343
|
+
};
|
|
369
344
|
};
|
|
370
345
|
const createSharingLink = async (shareRequest) => {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
return response;
|
|
385
|
-
}
|
|
386
|
-
catch (error) {
|
|
387
|
-
console.error('❌ Create Sharing Link Error:', error);
|
|
388
|
-
throw error;
|
|
389
|
-
}
|
|
346
|
+
const requestWithAuth = ky.create({
|
|
347
|
+
prefixUrl: options.url,
|
|
348
|
+
headers: {
|
|
349
|
+
'Content-Type': 'application/json',
|
|
350
|
+
Authorization: `Bearer ${options.apiKey}`,
|
|
351
|
+
'supabase-auth-token': options.supabaseToken || '',
|
|
352
|
+
'x-client': options.requestedWith,
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
const response = await requestWithAuth
|
|
356
|
+
.post('sharing/create', { json: shareRequest })
|
|
357
|
+
.json();
|
|
358
|
+
return response;
|
|
390
359
|
};
|
|
391
360
|
const previewSharingLink = async (token) => {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
return response;
|
|
405
|
-
}
|
|
406
|
-
catch (error) {
|
|
407
|
-
console.error('❌ Preview Sharing Link Error:', error);
|
|
408
|
-
throw error;
|
|
409
|
-
}
|
|
361
|
+
const requestWithAuth = ky.create({
|
|
362
|
+
prefixUrl: options.url,
|
|
363
|
+
headers: {
|
|
364
|
+
Authorization: `Bearer ${options.apiKey}`,
|
|
365
|
+
'supabase-auth-token': options.supabaseToken || '',
|
|
366
|
+
'x-client': options.requestedWith,
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
const response = await requestWithAuth
|
|
370
|
+
.get(`sharing/accept/${token}`)
|
|
371
|
+
.json();
|
|
372
|
+
return response;
|
|
410
373
|
};
|
|
411
374
|
const acceptSharingLink = async (token, acceptRequest) => {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
return response;
|
|
426
|
-
}
|
|
427
|
-
catch (error) {
|
|
428
|
-
console.error('❌ Accept Sharing Link Error:', error);
|
|
429
|
-
throw error;
|
|
430
|
-
}
|
|
375
|
+
const requestWithAuth = ky.create({
|
|
376
|
+
prefixUrl: options.url,
|
|
377
|
+
headers: {
|
|
378
|
+
'Content-Type': 'application/json',
|
|
379
|
+
Authorization: `Bearer ${options.apiKey}`,
|
|
380
|
+
'supabase-auth-token': options.supabaseToken || '',
|
|
381
|
+
'x-client': options.requestedWith,
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
const response = await requestWithAuth
|
|
385
|
+
.post(`sharing/accept/${token}`, { json: acceptRequest })
|
|
386
|
+
.json();
|
|
387
|
+
return response;
|
|
431
388
|
};
|
|
432
389
|
return {
|
|
433
390
|
createDevice,
|