skikrumb-api 2.1.2 → 2.1.4
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.d.ts +1 -0
- package/dist/index.js +74 -107
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export declare const skiKrumb: (options?: {
|
|
|
33
33
|
readApiKeys: () => Promise<apiKeys>;
|
|
34
34
|
readDeviceDailyDistance: (deviceSerialNumber: string) => Promise<unknown>;
|
|
35
35
|
readDeviceData: (deviceSerialNumber: string, limit?: number) => Promise<unknown>;
|
|
36
|
+
readDataForDevices: (query: QueryDevice) => Promise<Device[]>;
|
|
36
37
|
readGateways: () => Promise<Gateways>;
|
|
37
38
|
readShippingRates: (rateRequest: RateRequest) => Promise<Rates>;
|
|
38
39
|
sendMobileLocation: (payload: {
|
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() {
|
|
@@ -286,6 +279,15 @@ export const skiKrumb = (options = {
|
|
|
286
279
|
throw error;
|
|
287
280
|
}
|
|
288
281
|
};
|
|
282
|
+
const readDataForDevices = async (query) => {
|
|
283
|
+
if (!query.serial_numbers)
|
|
284
|
+
throw new Error('Serial number is required');
|
|
285
|
+
return request
|
|
286
|
+
.get('devices/data', {
|
|
287
|
+
searchParams: new URLSearchParams({ ...query }),
|
|
288
|
+
})
|
|
289
|
+
.json();
|
|
290
|
+
};
|
|
289
291
|
const readGateways = async () => {
|
|
290
292
|
try {
|
|
291
293
|
const response = await request.get('gateways').json();
|
|
@@ -319,115 +321,79 @@ export const skiKrumb = (options = {
|
|
|
319
321
|
}
|
|
320
322
|
};
|
|
321
323
|
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
|
-
}
|
|
324
|
+
const response = await request
|
|
325
|
+
.post('devices/location/mobile', { json: payload })
|
|
326
|
+
.json();
|
|
327
|
+
return response;
|
|
332
328
|
};
|
|
333
329
|
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
|
-
}
|
|
330
|
+
const response = await request
|
|
331
|
+
.post('auth/external', { json: userData })
|
|
332
|
+
.json();
|
|
333
|
+
return response;
|
|
344
334
|
};
|
|
345
335
|
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
|
-
}
|
|
336
|
+
// Create temporary request with current token
|
|
337
|
+
const refreshRequest = ky.create({
|
|
338
|
+
prefixUrl: options.url,
|
|
339
|
+
headers: {
|
|
340
|
+
'Content-Type': 'application/json',
|
|
341
|
+
Authorization: `Bearer ${currentToken}`,
|
|
342
|
+
'x-client': options.requestedWith,
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
const response = await refreshRequest.post('auth/external/refresh').json();
|
|
346
|
+
return {
|
|
347
|
+
success: response.success,
|
|
348
|
+
sessionToken: response.sessionToken,
|
|
349
|
+
accessibleSerials: response.accessibleSerials,
|
|
350
|
+
serialsCount: response.serialsCount,
|
|
351
|
+
timestamp: response.timestamp,
|
|
352
|
+
};
|
|
369
353
|
};
|
|
370
354
|
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
|
-
}
|
|
355
|
+
const requestWithAuth = ky.create({
|
|
356
|
+
prefixUrl: options.url,
|
|
357
|
+
headers: {
|
|
358
|
+
'Content-Type': 'application/json',
|
|
359
|
+
Authorization: `Bearer ${options.apiKey}`,
|
|
360
|
+
'supabase-auth-token': options.supabaseToken || '',
|
|
361
|
+
'x-client': options.requestedWith,
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
const response = await requestWithAuth
|
|
365
|
+
.post('sharing/create', { json: shareRequest })
|
|
366
|
+
.json();
|
|
367
|
+
return response;
|
|
390
368
|
};
|
|
391
369
|
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
|
-
}
|
|
370
|
+
const requestWithAuth = ky.create({
|
|
371
|
+
prefixUrl: options.url,
|
|
372
|
+
headers: {
|
|
373
|
+
Authorization: `Bearer ${options.apiKey}`,
|
|
374
|
+
'supabase-auth-token': options.supabaseToken || '',
|
|
375
|
+
'x-client': options.requestedWith,
|
|
376
|
+
},
|
|
377
|
+
});
|
|
378
|
+
const response = await requestWithAuth
|
|
379
|
+
.get(`sharing/accept/${token}`)
|
|
380
|
+
.json();
|
|
381
|
+
return response;
|
|
410
382
|
};
|
|
411
383
|
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
|
-
}
|
|
384
|
+
const requestWithAuth = ky.create({
|
|
385
|
+
prefixUrl: options.url,
|
|
386
|
+
headers: {
|
|
387
|
+
'Content-Type': 'application/json',
|
|
388
|
+
Authorization: `Bearer ${options.apiKey}`,
|
|
389
|
+
'supabase-auth-token': options.supabaseToken || '',
|
|
390
|
+
'x-client': options.requestedWith,
|
|
391
|
+
},
|
|
392
|
+
});
|
|
393
|
+
const response = await requestWithAuth
|
|
394
|
+
.post(`sharing/accept/${token}`, { json: acceptRequest })
|
|
395
|
+
.json();
|
|
396
|
+
return response;
|
|
431
397
|
};
|
|
432
398
|
return {
|
|
433
399
|
createDevice,
|
|
@@ -435,6 +401,7 @@ export const skiKrumb = (options = {
|
|
|
435
401
|
readApiKeys,
|
|
436
402
|
readDeviceDailyDistance,
|
|
437
403
|
readDeviceData,
|
|
404
|
+
readDataForDevices,
|
|
438
405
|
readGateways,
|
|
439
406
|
readShippingRates,
|
|
440
407
|
sendMobileLocation,
|