skikrumb-api 1.3.9 → 1.4.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/dist/index.d.ts +3 -1
- package/dist/index.js +59 -47
- package/dist/models.d.ts +42 -0
- package/package.json +2 -2
- package/readme.md +1 -1
- package/tsconfig.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { apiKeys, Device, Gateways, QueryDevice } from './models';
|
|
1
|
+
import { apiKeys, Device, Gateways, QueryDevice, RateRequest, Rates } from './models';
|
|
2
2
|
export declare const skiKrumb: (options?: {
|
|
3
3
|
apiKey: string;
|
|
4
4
|
supabaseToken: string;
|
|
@@ -18,6 +18,7 @@ export declare const skiKrumb: (options?: {
|
|
|
18
18
|
state?: string;
|
|
19
19
|
}) => Promise<any>;
|
|
20
20
|
createSubscription: (customerId: string, priceId: string, cartId: string, productId: string, registrations: Array<string>) => Promise<any>;
|
|
21
|
+
updatePaymentIntent: (cartId: string, intentId: string) => Promise<any>;
|
|
21
22
|
updateSubscription: (subscriptionId: string, quantity: number, registrations: Array<string>) => Promise<any>;
|
|
22
23
|
cancelSubscription: (subscriptionId: string) => Promise<any>;
|
|
23
24
|
readApiKeys: () => Promise<apiKeys[]>;
|
|
@@ -25,4 +26,5 @@ export declare const skiKrumb: (options?: {
|
|
|
25
26
|
readDeviceDailyDistance: (serialNumber: string, query: QueryDevice) => Promise<Device[]>;
|
|
26
27
|
readDeviceData: (serialNumber: string, query: QueryDevice) => Promise<Device>;
|
|
27
28
|
readGateways: () => Promise<Gateways>;
|
|
29
|
+
readShippingRates: (payload: RateRequest) => Promise<Rates[]>;
|
|
28
30
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
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
1
|
import ky from 'ky';
|
|
11
2
|
export const skiKrumb = (options = {
|
|
12
3
|
apiKey: '',
|
|
@@ -28,10 +19,10 @@ export const skiKrumb = (options = {
|
|
|
28
19
|
],
|
|
29
20
|
},
|
|
30
21
|
});
|
|
31
|
-
const createDevice = (deveui, serialNumber) =>
|
|
22
|
+
const createDevice = async (deveui, serialNumber) => {
|
|
32
23
|
if (!deveui || !serialNumber)
|
|
33
24
|
throw new Error('Must pass Lora MAC (deveui) and Serial Number');
|
|
34
|
-
return
|
|
25
|
+
return await api
|
|
35
26
|
.post(`${options.url}/devices`, {
|
|
36
27
|
headers: {
|
|
37
28
|
'content-type': 'application/json',
|
|
@@ -39,8 +30,8 @@ export const skiKrumb = (options = {
|
|
|
39
30
|
json: { deveui: deveui, serial_number: serialNumber },
|
|
40
31
|
})
|
|
41
32
|
.json();
|
|
42
|
-
}
|
|
43
|
-
const createDeviceDownlink = (userId, deveui, type = 'beep') =>
|
|
33
|
+
};
|
|
34
|
+
const createDeviceDownlink = async (userId, deveui, type = 'beep') => {
|
|
44
35
|
if (!userId || !deveui || !type)
|
|
45
36
|
throw new Error('Must pass userId, Lora MAC (deveui) and message type');
|
|
46
37
|
let message = 'DAgAC04zKE9EPTEwKQ0K';
|
|
@@ -49,7 +40,7 @@ export const skiKrumb = (options = {
|
|
|
49
40
|
message = 'DBECAAAAAAAAAAAB';
|
|
50
41
|
break;
|
|
51
42
|
}
|
|
52
|
-
return
|
|
43
|
+
return await api
|
|
53
44
|
.post(`${options.url}/devices/downlink`, {
|
|
54
45
|
headers: {
|
|
55
46
|
'content-type': 'application/json',
|
|
@@ -66,11 +57,11 @@ export const skiKrumb = (options = {
|
|
|
66
57
|
},
|
|
67
58
|
})
|
|
68
59
|
.json();
|
|
69
|
-
}
|
|
70
|
-
const sendMobileLocation = (payload) =>
|
|
60
|
+
};
|
|
61
|
+
const sendMobileLocation = async (payload) => {
|
|
71
62
|
if (!payload)
|
|
72
63
|
throw new Error('Payload is required');
|
|
73
|
-
return
|
|
64
|
+
return await api
|
|
74
65
|
.post(`${options.url}/devices/location/mobile`, {
|
|
75
66
|
headers: {
|
|
76
67
|
'content-type': 'application/json',
|
|
@@ -78,8 +69,8 @@ export const skiKrumb = (options = {
|
|
|
78
69
|
json: payload,
|
|
79
70
|
})
|
|
80
71
|
.json();
|
|
81
|
-
}
|
|
82
|
-
const createPaymentIntent = (form) =>
|
|
72
|
+
};
|
|
73
|
+
const createPaymentIntent = async (form) => {
|
|
83
74
|
if (!form)
|
|
84
75
|
throw new Error('Form values not posted.');
|
|
85
76
|
return api
|
|
@@ -87,13 +78,22 @@ export const skiKrumb = (options = {
|
|
|
87
78
|
body: form,
|
|
88
79
|
})
|
|
89
80
|
.json();
|
|
90
|
-
}
|
|
91
|
-
const getPaymentIntent = (clientSecret) =>
|
|
81
|
+
};
|
|
82
|
+
const getPaymentIntent = async (clientSecret) => {
|
|
92
83
|
if (!clientSecret)
|
|
93
84
|
throw new Error('Client secret is required');
|
|
94
85
|
return api.get(`${options.url}/payments/intent/${clientSecret}`).json();
|
|
95
|
-
}
|
|
96
|
-
const
|
|
86
|
+
};
|
|
87
|
+
const updatePaymentIntent = async (cartId, intentId) => {
|
|
88
|
+
if (!cartId || !intentId)
|
|
89
|
+
throw new Error('Cart Id and IntentId are required');
|
|
90
|
+
return api.patch(`${options.url}/payments/intent/${intentId}`, {
|
|
91
|
+
json: {
|
|
92
|
+
cartId: cartId,
|
|
93
|
+
}
|
|
94
|
+
}).json();
|
|
95
|
+
};
|
|
96
|
+
const createPrePurchaseIntent = async (form) => {
|
|
97
97
|
if (!form)
|
|
98
98
|
throw new Error('Form values not posted.');
|
|
99
99
|
return api
|
|
@@ -101,8 +101,8 @@ export const skiKrumb = (options = {
|
|
|
101
101
|
body: form,
|
|
102
102
|
})
|
|
103
103
|
.json();
|
|
104
|
-
}
|
|
105
|
-
const updateCustomerAddress = (customerId, email, shipping) =>
|
|
104
|
+
};
|
|
105
|
+
const updateCustomerAddress = async (customerId, email, shipping) => {
|
|
106
106
|
if (!customerId || !email || !shipping) {
|
|
107
107
|
throw new Error('Customer ID, email, and shipping details are required');
|
|
108
108
|
}
|
|
@@ -111,8 +111,8 @@ export const skiKrumb = (options = {
|
|
|
111
111
|
json: { customerId, email, shipping },
|
|
112
112
|
})
|
|
113
113
|
.json();
|
|
114
|
-
}
|
|
115
|
-
const getTaxCalculation = (amount, reference, quantity, address) =>
|
|
114
|
+
};
|
|
115
|
+
const getTaxCalculation = async (amount, reference, quantity, address) => {
|
|
116
116
|
if (!amount || !reference || !quantity || !address) {
|
|
117
117
|
throw new Error('Amount, reference, quantity, and address are required');
|
|
118
118
|
}
|
|
@@ -121,8 +121,8 @@ export const skiKrumb = (options = {
|
|
|
121
121
|
json: { amount, reference, quantity, address },
|
|
122
122
|
})
|
|
123
123
|
.json();
|
|
124
|
-
}
|
|
125
|
-
const createSubscription = (customerId, priceId, cartId, productId, registrations) =>
|
|
124
|
+
};
|
|
125
|
+
const createSubscription = async (customerId, priceId, cartId, productId, registrations) => {
|
|
126
126
|
if (!customerId || !priceId || !cartId || !productId || !registrations) {
|
|
127
127
|
throw new Error('Customer ID, price Id, cart ID, product ID, and registrations are required');
|
|
128
128
|
}
|
|
@@ -138,8 +138,8 @@ export const skiKrumb = (options = {
|
|
|
138
138
|
},
|
|
139
139
|
})
|
|
140
140
|
.json();
|
|
141
|
-
}
|
|
142
|
-
const updateSubscription = (subscriptionId, quantity, registrations) =>
|
|
141
|
+
};
|
|
142
|
+
const updateSubscription = async (subscriptionId, quantity, registrations) => {
|
|
143
143
|
if (!subscriptionId) {
|
|
144
144
|
throw new Error('Subscription ID is required');
|
|
145
145
|
}
|
|
@@ -152,48 +152,58 @@ export const skiKrumb = (options = {
|
|
|
152
152
|
},
|
|
153
153
|
})
|
|
154
154
|
.json();
|
|
155
|
-
}
|
|
156
|
-
const cancelSubscription = (subscriptionId) =>
|
|
155
|
+
};
|
|
156
|
+
const cancelSubscription = async (subscriptionId) => {
|
|
157
157
|
if (!subscriptionId) {
|
|
158
158
|
throw new Error('Subscription ID is required');
|
|
159
159
|
}
|
|
160
160
|
return api
|
|
161
161
|
.delete(`${options.url}/payments/subscription/${subscriptionId}`)
|
|
162
162
|
.json();
|
|
163
|
-
}
|
|
164
|
-
const readDeviceData = (serialNumber, query) =>
|
|
163
|
+
};
|
|
164
|
+
const readDeviceData = async (serialNumber, query) => {
|
|
165
165
|
if (!serialNumber)
|
|
166
166
|
throw new Error('Serial number is required');
|
|
167
167
|
return api
|
|
168
168
|
.get(`${options.url}/devices/data/${serialNumber}`, {
|
|
169
|
-
searchParams: new URLSearchParams(
|
|
169
|
+
searchParams: new URLSearchParams({ ...query }),
|
|
170
170
|
})
|
|
171
171
|
.json();
|
|
172
|
-
}
|
|
173
|
-
const readGateways = () =>
|
|
172
|
+
};
|
|
173
|
+
const readGateways = async () => {
|
|
174
174
|
return api.get(`${options.url}/gateways`).json();
|
|
175
|
-
}
|
|
176
|
-
const readDeviceDailyDistance = (serialNumber, query) =>
|
|
175
|
+
};
|
|
176
|
+
const readDeviceDailyDistance = async (serialNumber, query) => {
|
|
177
177
|
if (!serialNumber)
|
|
178
178
|
throw new Error('Serial number is required');
|
|
179
179
|
return api
|
|
180
180
|
.get(`${options.url}/devices/${serialNumber}/distance`, {
|
|
181
|
-
searchParams: new URLSearchParams(
|
|
181
|
+
searchParams: new URLSearchParams({ ...query }),
|
|
182
182
|
})
|
|
183
183
|
.json();
|
|
184
|
-
}
|
|
185
|
-
const readDataForDevices = (query) =>
|
|
184
|
+
};
|
|
185
|
+
const readDataForDevices = async (query) => {
|
|
186
186
|
if (!query.serial_numbers)
|
|
187
187
|
throw new Error('Serial number is required');
|
|
188
188
|
return api
|
|
189
189
|
.get(`${options.url}/devices/data`, {
|
|
190
|
-
searchParams: new URLSearchParams(
|
|
190
|
+
searchParams: new URLSearchParams({ ...query }),
|
|
191
191
|
})
|
|
192
192
|
.json();
|
|
193
|
-
}
|
|
194
|
-
const readApiKeys = () =>
|
|
193
|
+
};
|
|
194
|
+
const readApiKeys = async () => {
|
|
195
195
|
return api.get(`${options.url}/keys`).json();
|
|
196
|
-
}
|
|
196
|
+
};
|
|
197
|
+
const readShippingRates = async (payload) => {
|
|
198
|
+
return await api
|
|
199
|
+
.post(`${options.url}/payments/shipping-rates`, {
|
|
200
|
+
headers: {
|
|
201
|
+
'content-type': 'application/json',
|
|
202
|
+
},
|
|
203
|
+
json: payload,
|
|
204
|
+
})
|
|
205
|
+
.json();
|
|
206
|
+
};
|
|
197
207
|
return {
|
|
198
208
|
createDevice,
|
|
199
209
|
createDeviceDownlink,
|
|
@@ -204,6 +214,7 @@ export const skiKrumb = (options = {
|
|
|
204
214
|
updateCustomerAddress,
|
|
205
215
|
getTaxCalculation,
|
|
206
216
|
createSubscription,
|
|
217
|
+
updatePaymentIntent,
|
|
207
218
|
updateSubscription,
|
|
208
219
|
cancelSubscription,
|
|
209
220
|
readApiKeys,
|
|
@@ -211,5 +222,6 @@ export const skiKrumb = (options = {
|
|
|
211
222
|
readDeviceDailyDistance,
|
|
212
223
|
readDeviceData,
|
|
213
224
|
readGateways,
|
|
225
|
+
readShippingRates
|
|
214
226
|
};
|
|
215
227
|
};
|
package/dist/models.d.ts
CHANGED
|
@@ -55,3 +55,45 @@ export interface QueryDevice {
|
|
|
55
55
|
page?: string;
|
|
56
56
|
timeZone?: string;
|
|
57
57
|
}
|
|
58
|
+
export interface Amount {
|
|
59
|
+
value: string;
|
|
60
|
+
currency: string;
|
|
61
|
+
}
|
|
62
|
+
export interface Surcharge {
|
|
63
|
+
type: string;
|
|
64
|
+
amount: Amount;
|
|
65
|
+
}
|
|
66
|
+
export interface Tax {
|
|
67
|
+
type: string;
|
|
68
|
+
amount: Amount;
|
|
69
|
+
}
|
|
70
|
+
export interface ValidUntil {
|
|
71
|
+
year: number;
|
|
72
|
+
month: number;
|
|
73
|
+
day: number;
|
|
74
|
+
}
|
|
75
|
+
export interface Rates {
|
|
76
|
+
service_id: string;
|
|
77
|
+
valid_until: ValidUntil;
|
|
78
|
+
total: Amount;
|
|
79
|
+
base: Amount;
|
|
80
|
+
surcharges: Surcharge[];
|
|
81
|
+
taxes: Tax[];
|
|
82
|
+
transit_time_days: number;
|
|
83
|
+
transit_time_not_available: boolean;
|
|
84
|
+
carrier_name: string;
|
|
85
|
+
service_name: string;
|
|
86
|
+
}
|
|
87
|
+
export interface Address {
|
|
88
|
+
city: string;
|
|
89
|
+
country: string;
|
|
90
|
+
line1: string;
|
|
91
|
+
postal_code: string;
|
|
92
|
+
state: string;
|
|
93
|
+
}
|
|
94
|
+
export interface RateRequest {
|
|
95
|
+
name: string;
|
|
96
|
+
address: Address;
|
|
97
|
+
email_addresses: string[];
|
|
98
|
+
quantity: number;
|
|
99
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skikrumb-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Wrapper for the skiKrumb API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
"prettier-plugin-organize-attributes": "^1.0.0"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"ky": "^
|
|
21
|
+
"ky": "^1.7.5"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/readme.md
CHANGED