skikrumb-api 1.3.1 → 1.3.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/.prettierrc +7 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +60 -37
- package/package.json +4 -2
package/.prettierrc
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { apiKeys, Device, Gateways, QueryDevice } from
|
|
1
|
+
import { apiKeys, Device, Gateways, QueryDevice } from './models';
|
|
2
2
|
export declare const skiKrumb: (options?: {
|
|
3
3
|
apiKey: string;
|
|
4
|
+
supabaseToken: string;
|
|
4
5
|
requestedWith: string | undefined;
|
|
5
6
|
url: string | undefined;
|
|
6
7
|
}) => {
|
package/dist/index.js
CHANGED
|
@@ -10,31 +10,37 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import ky from 'ky';
|
|
11
11
|
export const skiKrumb = (options = {
|
|
12
12
|
apiKey: '',
|
|
13
|
+
supabaseToken: '',
|
|
13
14
|
requestedWith: 'skiKrumb Node & Client API Wrapper',
|
|
14
|
-
url: 'https://api.skikrumb.ca'
|
|
15
|
+
url: 'https://api.skikrumb.ca',
|
|
15
16
|
}) => {
|
|
16
17
|
const api = ky.extend({
|
|
17
18
|
hooks: {
|
|
18
19
|
beforeRequest: [
|
|
19
|
-
request => {
|
|
20
|
+
(request) => {
|
|
20
21
|
request.headers.set('X-Requested-With', `${options.requestedWith}`);
|
|
21
22
|
request.headers.set('Authorization', `Bearer ${options.apiKey}`);
|
|
22
23
|
request.headers.set('Content-Type', `application/json`);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
if (options.supabaseToken) {
|
|
25
|
+
request.headers.set('supabase-auth-token', options.supabaseToken);
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
26
30
|
});
|
|
27
31
|
const createDevice = (deveui, serialNumber) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
32
|
if (!deveui || !serialNumber)
|
|
29
33
|
throw new Error('Must pass Lora MAC (deveui) and Serial Number');
|
|
30
|
-
return yield api
|
|
34
|
+
return yield api
|
|
35
|
+
.post(`${options.url}/devices`, {
|
|
31
36
|
headers: {
|
|
32
|
-
'content-type': 'application/json'
|
|
37
|
+
'content-type': 'application/json',
|
|
33
38
|
},
|
|
34
|
-
json: { deveui: deveui, serial_number: serialNumber }
|
|
35
|
-
})
|
|
39
|
+
json: { deveui: deveui, serial_number: serialNumber },
|
|
40
|
+
})
|
|
41
|
+
.json();
|
|
36
42
|
});
|
|
37
|
-
const createDeviceDownlink = (
|
|
43
|
+
const createDeviceDownlink = (userId, deveui, type = 'beep') => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
44
|
if (!userId || !deveui || !type)
|
|
39
45
|
throw new Error('Must pass userId, Lora MAC (deveui) and message type');
|
|
40
46
|
let message = 'DAgAC04zKE9EPTEwKQ0K';
|
|
@@ -43,42 +49,55 @@ export const skiKrumb = (options = {
|
|
|
43
49
|
message = 'DBECAAAAAAAAAAAB';
|
|
44
50
|
break;
|
|
45
51
|
}
|
|
46
|
-
return yield api
|
|
52
|
+
return yield api
|
|
53
|
+
.post(`${options.url}/devices/downlink`, {
|
|
47
54
|
headers: {
|
|
48
|
-
'content-type': 'application/json'
|
|
55
|
+
'content-type': 'application/json',
|
|
49
56
|
},
|
|
50
57
|
json: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
})
|
|
58
|
+
device: deveui,
|
|
59
|
+
userId: userId,
|
|
60
|
+
data: {
|
|
61
|
+
params: {
|
|
62
|
+
data: message,
|
|
63
|
+
port: 100,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
.json();
|
|
61
69
|
});
|
|
62
70
|
const createPaymentIntent = (form) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
71
|
if (!form)
|
|
64
72
|
throw new Error('Form values not posted.');
|
|
65
|
-
return api
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
return api
|
|
74
|
+
.post(`${options.url}/payments/purchase/intent`, {
|
|
75
|
+
body: form,
|
|
76
|
+
})
|
|
77
|
+
.json();
|
|
78
|
+
});
|
|
79
|
+
const getPaymentIntent = (clientSecret) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
if (!clientSecret)
|
|
81
|
+
throw new Error('Client secret is required');
|
|
82
|
+
return api.get(`${options.url}/payments/intent/${clientSecret}`).json();
|
|
68
83
|
});
|
|
69
84
|
const createPrePurchaseIntent = (form) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
85
|
if (!form)
|
|
71
86
|
throw new Error('Form values not posted.');
|
|
72
|
-
return api
|
|
73
|
-
|
|
74
|
-
|
|
87
|
+
return api
|
|
88
|
+
.post(`${options.url}/payments/pre-purchase/intent`, {
|
|
89
|
+
body: form,
|
|
90
|
+
})
|
|
91
|
+
.json();
|
|
75
92
|
});
|
|
76
93
|
const readDeviceData = (serialNumber, query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
94
|
if (!serialNumber)
|
|
78
95
|
throw new Error('Serial number is required');
|
|
79
|
-
return api
|
|
80
|
-
|
|
81
|
-
|
|
96
|
+
return api
|
|
97
|
+
.get(`${options.url}/devices/data/${serialNumber}`, {
|
|
98
|
+
searchParams: new URLSearchParams(Object.assign({}, query)),
|
|
99
|
+
})
|
|
100
|
+
.json();
|
|
82
101
|
});
|
|
83
102
|
const readGateways = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
103
|
return api.get(`${options.url}/gateways`).json();
|
|
@@ -86,16 +105,20 @@ export const skiKrumb = (options = {
|
|
|
86
105
|
const readDeviceDailyDistance = (serialNumber, query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
106
|
if (!serialNumber)
|
|
88
107
|
throw new Error('Serial number is required');
|
|
89
|
-
return api
|
|
90
|
-
|
|
91
|
-
|
|
108
|
+
return api
|
|
109
|
+
.get(`${options.url}/devices/${serialNumber}/distance`, {
|
|
110
|
+
searchParams: new URLSearchParams(Object.assign({}, query)),
|
|
111
|
+
})
|
|
112
|
+
.json();
|
|
92
113
|
});
|
|
93
114
|
const readDataForDevices = (query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
115
|
if (!query.serial_numbers)
|
|
95
116
|
throw new Error('Serial number is required');
|
|
96
|
-
return api
|
|
97
|
-
|
|
98
|
-
|
|
117
|
+
return api
|
|
118
|
+
.get(`${options.url}/devices/data`, {
|
|
119
|
+
searchParams: new URLSearchParams(Object.assign({}, query)),
|
|
120
|
+
})
|
|
121
|
+
.json();
|
|
99
122
|
});
|
|
100
123
|
const readApiKeys = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
124
|
return api.get(`${options.url}/keys`).json();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skikrumb-api",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "Wrapper for the skiKrumb API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "UNLICENSED",
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"typescript": "^5.
|
|
16
|
+
"typescript": "^5.1.6",
|
|
17
|
+
"prettier": "^3.3.3",
|
|
18
|
+
"prettier-plugin-organize-attributes": "^1.0.0"
|
|
17
19
|
},
|
|
18
20
|
"dependencies": {
|
|
19
21
|
"ky": "^0.33.3"
|