skikrumb-api 1.0.0
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/.idea/modules.xml +8 -0
- package/.idea/skikrumb-api.iml +12 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +73 -0
- package/dist/models.d.ts +37 -0
- package/dist/models.js +1 -0
- package/index.ts +77 -0
- package/models.ts +41 -0
- package/package.json +21 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/skikrumb-api.iml" filepath="$PROJECT_DIR$/.idea/skikrumb-api.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="WEB_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
|
6
|
+
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
|
7
|
+
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
|
8
|
+
</content>
|
|
9
|
+
<orderEntry type="inheritedJdk" />
|
|
10
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
11
|
+
</component>
|
|
12
|
+
</module>
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { apiKeys, Device, QueryDevice } from "./models";
|
|
2
|
+
export declare const skiKrumb: (options?: {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
requestedWith: string;
|
|
5
|
+
url: string;
|
|
6
|
+
}) => {
|
|
7
|
+
createPaymentIntent: (form: any) => Promise<any>;
|
|
8
|
+
createPrePurchaseIntent: (form: any) => Promise<any>;
|
|
9
|
+
readApiKeys: () => Promise<apiKeys[]>;
|
|
10
|
+
readDataForDevices: (query: QueryDevice) => Promise<Device[]>;
|
|
11
|
+
readDeviceDailyDistance: (serialNumber: number, query: QueryDevice) => Promise<Device[]>;
|
|
12
|
+
readDeviceData: (serialNumber: number, query: QueryDevice) => Promise<Device[]>;
|
|
13
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import ky from 'ky';
|
|
11
|
+
export const skiKrumb = (options = {
|
|
12
|
+
apiKey: '',
|
|
13
|
+
requestedWith: 'skiKrumb API Wrapper',
|
|
14
|
+
url: 'https://api.skikrumb.ca'
|
|
15
|
+
}) => {
|
|
16
|
+
const api = ky.extend({
|
|
17
|
+
hooks: {
|
|
18
|
+
beforeRequest: [
|
|
19
|
+
request => {
|
|
20
|
+
request.headers.set('X-Requested-With', `${options.requestedWith}`);
|
|
21
|
+
request.headers.set('Authorization', `Bearer ${options.apiKey}`);
|
|
22
|
+
request.headers.set('Content-Type', `application/json`);
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
const createPaymentIntent = (form) => __awaiter(void 0, void 0, void 0, function* () {
|
|
28
|
+
if (!form)
|
|
29
|
+
throw new Error('Form values not posted.');
|
|
30
|
+
return api.post(`${options.url}/payments/intent`, {
|
|
31
|
+
body: form
|
|
32
|
+
}).json();
|
|
33
|
+
});
|
|
34
|
+
const createPrePurchaseIntent = (form) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
if (!form)
|
|
36
|
+
throw new Error('Form values not posted.');
|
|
37
|
+
return api.post(`${options.url}/payments/pre-purchase/intent`, {
|
|
38
|
+
body: form
|
|
39
|
+
}).json();
|
|
40
|
+
});
|
|
41
|
+
const readDeviceData = (serialNumber, query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
if (!serialNumber)
|
|
43
|
+
throw new Error('Serial number is required');
|
|
44
|
+
return api.get(`${options.url}/devices/data/${serialNumber}`, {
|
|
45
|
+
searchParams: new URLSearchParams(Object.assign({}, query))
|
|
46
|
+
}).json();
|
|
47
|
+
});
|
|
48
|
+
const readDeviceDailyDistance = (serialNumber, query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
if (!serialNumber)
|
|
50
|
+
throw new Error('Serial number is required');
|
|
51
|
+
return api.get(`${options.url}/devices/${serialNumber}/distance`, {
|
|
52
|
+
searchParams: new URLSearchParams(Object.assign({}, query))
|
|
53
|
+
}).json();
|
|
54
|
+
});
|
|
55
|
+
const readDataForDevices = (query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
if (!query.serial_numbers)
|
|
57
|
+
throw new Error('Serial number is required');
|
|
58
|
+
return api.get(`${options.url}/devices/data`, {
|
|
59
|
+
searchParams: new URLSearchParams(Object.assign({}, query))
|
|
60
|
+
}).json();
|
|
61
|
+
});
|
|
62
|
+
const readApiKeys = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
return api.get(`${options.url}/keys`).json();
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
createPaymentIntent,
|
|
67
|
+
createPrePurchaseIntent,
|
|
68
|
+
readApiKeys,
|
|
69
|
+
readDataForDevices,
|
|
70
|
+
readDeviceDailyDistance,
|
|
71
|
+
readDeviceData
|
|
72
|
+
};
|
|
73
|
+
};
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface apiKeys {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
jwt: string;
|
|
6
|
+
claims: any;
|
|
7
|
+
}
|
|
8
|
+
export interface Device {
|
|
9
|
+
serial_number: number;
|
|
10
|
+
created_at: string;
|
|
11
|
+
updated_at: string;
|
|
12
|
+
data?: Data[];
|
|
13
|
+
}
|
|
14
|
+
export interface Data {
|
|
15
|
+
latitude: number;
|
|
16
|
+
longitude: number;
|
|
17
|
+
temperature: number;
|
|
18
|
+
battery: number;
|
|
19
|
+
serial_number: number;
|
|
20
|
+
id: number;
|
|
21
|
+
created_at: string;
|
|
22
|
+
updated_at: string;
|
|
23
|
+
recorded_at: string;
|
|
24
|
+
firmware: string;
|
|
25
|
+
signal_strength: number;
|
|
26
|
+
altitude: number;
|
|
27
|
+
}
|
|
28
|
+
export interface QueryDevice {
|
|
29
|
+
serial_numbers?: string;
|
|
30
|
+
order_by?: string;
|
|
31
|
+
ascending?: string;
|
|
32
|
+
start_date?: string;
|
|
33
|
+
date?: string;
|
|
34
|
+
end_date?: string;
|
|
35
|
+
size?: string;
|
|
36
|
+
page?: string;
|
|
37
|
+
}
|
package/dist/models.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/index.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import ky from 'ky';
|
|
2
|
+
import {apiKeys, Device, QueryDevice} from "./models";
|
|
3
|
+
|
|
4
|
+
export const skiKrumb = (options = {
|
|
5
|
+
apiKey: '',
|
|
6
|
+
requestedWith: 'skiKrumb API Wrapper',
|
|
7
|
+
url: 'https://api.skikrumb.ca'
|
|
8
|
+
}) => {
|
|
9
|
+
const api = ky.extend({
|
|
10
|
+
hooks: {
|
|
11
|
+
beforeRequest: [
|
|
12
|
+
request => {
|
|
13
|
+
request.headers.set('X-Requested-With', `${options.requestedWith}`)
|
|
14
|
+
request.headers.set('Authorization', `Bearer ${options.apiKey}`)
|
|
15
|
+
request.headers.set('Content-Type', `application/json`)
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const createPaymentIntent = async (form: any): Promise<any> => {
|
|
22
|
+
if (!form)
|
|
23
|
+
throw new Error('Form values not posted.')
|
|
24
|
+
|
|
25
|
+
return api.post(`${options.url}/payments/intent`, {
|
|
26
|
+
body: form
|
|
27
|
+
}).json()
|
|
28
|
+
}
|
|
29
|
+
const createPrePurchaseIntent = async (form: any): Promise<any> => {
|
|
30
|
+
if (!form)
|
|
31
|
+
throw new Error('Form values not posted.')
|
|
32
|
+
|
|
33
|
+
return api.post(`${options.url}/payments/pre-purchase/intent`, {
|
|
34
|
+
body: form
|
|
35
|
+
}).json()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const readDeviceData = async (serialNumber: number, query: QueryDevice): Promise<Device[]> => {
|
|
39
|
+
if (!serialNumber)
|
|
40
|
+
throw new Error('Serial number is required')
|
|
41
|
+
|
|
42
|
+
return api.get(`${options.url}/devices/data/${serialNumber}`, {
|
|
43
|
+
searchParams: new URLSearchParams({...query})
|
|
44
|
+
}).json()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const readDeviceDailyDistance = async (serialNumber: number, query: QueryDevice): Promise<Device[]> => {
|
|
48
|
+
if (!serialNumber)
|
|
49
|
+
throw new Error('Serial number is required')
|
|
50
|
+
|
|
51
|
+
return api.get(`${options.url}/devices/${serialNumber}/distance`, {
|
|
52
|
+
searchParams: new URLSearchParams({...query})
|
|
53
|
+
}).json()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const readDataForDevices = async (query: QueryDevice): Promise<Device[]> => {
|
|
57
|
+
if (!query.serial_numbers)
|
|
58
|
+
throw new Error('Serial number is required')
|
|
59
|
+
|
|
60
|
+
return api.get(`${options.url}/devices/data`, {
|
|
61
|
+
searchParams: new URLSearchParams({...query})
|
|
62
|
+
}).json()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const readApiKeys = async (): Promise<apiKeys[]> => {
|
|
66
|
+
return api.get(`${options.url}/keys`).json()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
createPaymentIntent,
|
|
71
|
+
createPrePurchaseIntent,
|
|
72
|
+
readApiKeys,
|
|
73
|
+
readDataForDevices,
|
|
74
|
+
readDeviceDailyDistance,
|
|
75
|
+
readDeviceData
|
|
76
|
+
};
|
|
77
|
+
};
|
package/models.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface apiKeys {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
jwt: string;
|
|
6
|
+
claims: any;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface Device {
|
|
10
|
+
serial_number: number;
|
|
11
|
+
created_at: string;
|
|
12
|
+
updated_at: string;
|
|
13
|
+
data?: Data[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Data {
|
|
17
|
+
latitude: number;
|
|
18
|
+
longitude: number;
|
|
19
|
+
temperature: number;
|
|
20
|
+
battery: number;
|
|
21
|
+
serial_number: number;
|
|
22
|
+
id: number;
|
|
23
|
+
created_at: string;
|
|
24
|
+
updated_at: string;
|
|
25
|
+
recorded_at: string;
|
|
26
|
+
firmware: string;
|
|
27
|
+
signal_strength: number;
|
|
28
|
+
altitude: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface QueryDevice {
|
|
32
|
+
serial_numbers?: string;
|
|
33
|
+
order_by?: string;
|
|
34
|
+
ascending?: string;
|
|
35
|
+
start_date?: string;
|
|
36
|
+
date?: string;
|
|
37
|
+
end_date?: string;
|
|
38
|
+
size?: string;
|
|
39
|
+
page?: string;
|
|
40
|
+
}
|
|
41
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "skikrumb-api",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Wrapper for the skiKrumb API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"prepublish": "npm run build",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [],
|
|
13
|
+
"author": "",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"typescript": "^5.1.6"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"ky": "^0.33.3"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2015",
|
|
4
|
+
"module": "ES2020",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"moduleResolution":"Node"
|
|
11
|
+
},
|
|
12
|
+
"exclude": [
|
|
13
|
+
"node_modules",
|
|
14
|
+
"dist"
|
|
15
|
+
]
|
|
16
|
+
}
|