Comparing version 0.43.1 to 0.43.2
import { AxiosError, Method } from 'axios' | ||
export default function setup( | ||
config?: IConfig | ||
config?: IConfig, | ||
newGetToken?: () => Promise<string> | ||
): { | ||
@@ -15,2 +16,3 @@ axios: import('axios').AxiosInstance | ||
authHashLogin(username: string, authhash: string): Promise<IUser> | ||
userData(username: string): Promise<IUser> | ||
language: { | ||
@@ -55,5 +57,21 @@ get(): Promise<string> | ||
count(): Promise<IDeviceCount> | ||
share(devices: IDevice[], emails: string[], authhash: string): Promise<any> | ||
transfer(devices: IDevice[], email: string, authhash: string): Promise<any> | ||
share(devices: IDevice[], emails: string[]): Promise<any> | ||
transfer(devices: IDevice[], email: string): Promise<any> | ||
group(devices: IRawDevice[], metadata: IRawMetaData): IDevice[] | ||
setCategory( | ||
deviceaddress: string, | ||
catA: string, | ||
catB: string, | ||
catC: string, | ||
catD: string, | ||
catE: string | ||
): Promise<any> | ||
setStatus( | ||
deviceaddress: string, | ||
statusA: string, | ||
statusB: string, | ||
statusC: string, | ||
statusD: string, | ||
statusE: string | ||
): Promise<any> | ||
} | ||
@@ -70,2 +88,12 @@ scripts: { | ||
cancel(jobid: string): Promise<any> | ||
send( | ||
script: string, | ||
file: string, | ||
command: string, | ||
services: string, | ||
expiration: string, | ||
post_func: string, | ||
options: string, | ||
allowUpdates: string | ||
): Promise<any> | ||
} | ||
@@ -105,2 +133,8 @@ contacts: { | ||
list(): Promise<IRegistration[]> | ||
setProuct( | ||
bulkID: string, | ||
descriptor: string, | ||
productID: string | ||
): Promise<any> | ||
setName(bulkID: string, name: string): Promise<any> | ||
} | ||
@@ -111,2 +145,7 @@ entities: { | ||
} | ||
utilities: { | ||
serverUrl(): Promise<any> | ||
tinyUrl(orginalUrl: string): Promise<any> | ||
shortCode(orginalUrl: string): Promise<any> | ||
} | ||
request( | ||
@@ -131,2 +170,4 @@ method: Method, | ||
successURL?: string | undefined | ||
taskQueue?: string | undefined | ||
jobQueue?: string | undefined | ||
token?: string | undefined | ||
@@ -141,2 +182,4 @@ } | ||
successURL?: string | ||
taskQueue?: string | ||
jobQueue?: string | ||
token?: string | ||
@@ -143,0 +186,0 @@ } |
@@ -84,7 +84,10 @@ "use strict"; | ||
var utils_1 = require("./utils"); | ||
var js_base64_1 = require("js-base64"); | ||
var defaults = { | ||
apiURL: 'https://api.remot3.it/apv/v27', | ||
successURL: 'https://app.remote.it', | ||
taskQueue: 'WeavedTaskQueue', | ||
jobQueue: 'WeavedJobQueue', | ||
}; | ||
function setup(config) { | ||
function setup(config, newGetToken) { | ||
if (config === void 0) { config = {}; } | ||
@@ -100,5 +103,9 @@ var options = __assign({}, defaults, config); | ||
developerKey: options.developerKey, | ||
taskQueue: options.taskQueue, | ||
jobQueue: options.jobQueue, | ||
token: options.token, | ||
}), | ||
}); | ||
//console.error(newGetToken) | ||
var getToken = newGetToken; | ||
var r3 = __assign({}, options, { | ||
@@ -144,2 +151,12 @@ // Store the axios instance so we can re-use it and also add | ||
}, | ||
userData: function (username) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, r3 | ||
.post('/user/info/') | ||
.then(function (resp) { return r3.user.process(resp, username); }) | ||
.then(r3.user.updateCredentials)]; | ||
}); | ||
}); | ||
}, | ||
language: { | ||
@@ -489,3 +506,3 @@ get: function () { | ||
// TODO: Define return type | ||
share: function (devices, emails, authhash) { | ||
share: function (devices, emails) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -495,4 +512,3 @@ return __generator(this, function (_a) { | ||
actionurl: r3.successURL + "/invite/accept?type=shareDevices&id=", | ||
authhash: authhash, | ||
queue_name: 'WeavedTaskQueue', | ||
queue_name: r3.taskQueue, | ||
function: 'share_devices', | ||
@@ -512,3 +528,3 @@ label: 'sharing', | ||
// TODO: Define return type | ||
transfer: function (devices, email, authhash) { | ||
transfer: function (devices, email) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -518,4 +534,3 @@ return __generator(this, function (_a) { | ||
actionurl: r3.successURL + "/invite/accept?type=transfer&id=", | ||
authhash: authhash, | ||
queue_name: 'WeavedTaskQueue', | ||
queue_name: r3.taskQueue, | ||
email: email, | ||
@@ -611,2 +626,32 @@ function: 'transfer_devices', | ||
}, | ||
setCategory: function (deviceaddress, catA, catB, catC, catD, catE) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var body; | ||
return __generator(this, function (_a) { | ||
body = { | ||
categoryA: catA, | ||
categoryB: catB, | ||
categoryC: catC, | ||
categoryD: catD, | ||
categoryE: catE, | ||
}; | ||
return [2 /*return*/, r3.post('/device/category/' + deviceaddress, body)]; | ||
}); | ||
}); | ||
}, | ||
setStatus: function (deviceaddress, statusA, statusB, statusC, statusD, statusE) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var body; | ||
return __generator(this, function (_a) { | ||
body = { | ||
statusA: statusA, | ||
statusB: statusB, | ||
statusC: statusC, | ||
statusD: statusD, | ||
statusE: statusE, | ||
}; | ||
return [2 /*return*/, r3.post('/device/status/' + deviceaddress, body)]; | ||
}); | ||
}); | ||
}, | ||
}, scripts: { | ||
@@ -679,2 +724,20 @@ // TODO: Define return type | ||
}, | ||
// TODO: Define return type | ||
send: function (script, file, command, services, expiration, post_func, options, allowUpdates) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, r3.post('/bulk/job', { | ||
queue_name: r3.jobQueue, | ||
script: script, | ||
file: file, | ||
command: js_base64_1.Base64.encode(command), | ||
expiration: expiration, | ||
function: post_func, | ||
options: options, | ||
services: services, | ||
allow_updates: allowUpdates, | ||
})]; | ||
}); | ||
}); | ||
}, | ||
}, contacts: { | ||
@@ -908,2 +971,25 @@ list: function () { | ||
}, | ||
// TODO: Define return type | ||
setProuct: function (bulkID, descriptor, productID) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, r3.post('/bulk/registration/name/', { | ||
bulk_id: bulkID, | ||
productid: productID, | ||
descriptor: descriptor, | ||
})]; | ||
}); | ||
}); | ||
}, | ||
// TODO: Define return type | ||
setName: function (bulkID, name) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, r3.post('/bulk/registration/product/descriptor/', { | ||
bulk_id: bulkID, | ||
name: name, | ||
})]; | ||
}); | ||
}); | ||
}, | ||
}, entities: { | ||
@@ -928,2 +1014,48 @@ find: function (id) { | ||
}, | ||
}, utilities: { | ||
// TODO: Define return type | ||
serverUrl: function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, r3.get('/server/url/').then(function (_a) { | ||
var url = _a.url; | ||
return url; | ||
})]; | ||
}); | ||
}); | ||
}, | ||
// TODO: Define return type | ||
tinyUrl: function (orginalUrl) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, r3 | ||
.post('/tiny/', { | ||
url: orginalUrl, | ||
}) | ||
.then(function (item) { | ||
if (item && item.id) { | ||
return options.apiURL + '/tiny/' + item.id; | ||
} | ||
return orginalUrl; | ||
})]; | ||
}); | ||
}); | ||
}, | ||
// TODO: Define return type | ||
shortCode: function (orginalUrl) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, r3 | ||
.post('/tiny/', { | ||
url: orginalUrl, | ||
}) | ||
.then(function (item) { | ||
if (item && item.id) { | ||
return item.id; | ||
} | ||
return orginalUrl; | ||
})]; | ||
}); | ||
}); | ||
}, | ||
}, | ||
@@ -938,16 +1070,40 @@ /*------------------------------------------------------------------------------- | ||
return __awaiter(this, void 0, void 0, function () { | ||
var token; | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, r3.axios | ||
.request({ | ||
url: url, | ||
method: method, | ||
data: data, | ||
headers: __assign({}, extraHeaders, utils_1.pickBy({ | ||
accessKey: r3.accessKey, | ||
apiKey: r3.apiKey, | ||
developerKey: r3.developerKey, | ||
token: r3.token, | ||
})), | ||
}) | ||
.then(r3.processData, r3.processError)]; | ||
switch (_a.label) { | ||
case 0: | ||
if (!(getToken !== undefined)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, getToken()]; | ||
case 1: | ||
token = _a.sent(); | ||
return [2 /*return*/, r3.axios | ||
.request({ | ||
url: url, | ||
method: method, | ||
data: data, | ||
headers: __assign({}, extraHeaders, utils_1.pickBy({ | ||
Authorization: token, | ||
developerKey: r3.developerKey, | ||
})), | ||
}) | ||
.then(r3.processData, r3.processError)]; | ||
case 2: | ||
//console.error(err) | ||
//console.error(err.message) | ||
//alert('ERROR: ' + error.message) | ||
//No AWS Auth, use legacy | ||
return [2 /*return*/, r3.axios | ||
.request({ | ||
url: url, | ||
method: method, | ||
data: data, | ||
headers: __assign({}, extraHeaders, utils_1.pickBy({ | ||
accessKey: r3.accessKey, | ||
apiKey: r3.apiKey, | ||
developerKey: r3.developerKey, | ||
token: r3.token, | ||
})), | ||
}) | ||
.then(r3.processData, r3.processError)]; | ||
} | ||
}); | ||
@@ -954,0 +1110,0 @@ }); |
{ | ||
"name": "remote.it", | ||
"version": "0.43.1", | ||
"version": "0.43.2", | ||
"description": "remote.it JavaScript/node client library", | ||
@@ -46,3 +46,5 @@ "main": "lib/remote.it.js", | ||
"dependencies": { | ||
"@types/js-base64": "^2.3.1", | ||
"axios": "0.19.0", | ||
"js-base64": "^2.5.1", | ||
"luxon": "1.13.2" | ||
@@ -80,4 +82,3 @@ }, | ||
}, | ||
"homepage": "https://github.com/remoteit/remote.it.js#readme", | ||
"gitHead": "cae3f322fcf94df3eefe1a9cc229c6023b196d30" | ||
"homepage": "https://github.com/remoteit/remote.it.js#readme" | ||
} |
import axios, { AxiosError, AxiosResponse, Method } from 'axios' | ||
import { groupBy, parseLegacyDate, pickBy, toNumber } from './utils' | ||
import { Base64 } from 'js-base64' | ||
@@ -7,7 +8,11 @@ const defaults = { | ||
successURL: 'https://app.remote.it', // 'https://' + window.location.host | ||
taskQueue: 'WeavedTaskQueue', | ||
jobQueue: 'WeavedJobQueue', | ||
} | ||
export default function setup(config: IConfig = {}) { | ||
export default function setup( | ||
config: IConfig = {}, | ||
newGetToken?: () => Promise<string> | ||
) { | ||
const options: IConfig = { ...defaults, ...config } | ||
const instance = axios.create({ | ||
@@ -21,2 +26,4 @@ baseURL: options.apiURL, | ||
developerKey: options.developerKey, | ||
taskQueue: options.taskQueue, | ||
jobQueue: options.jobQueue, | ||
token: options.token, | ||
@@ -26,2 +33,6 @@ }), | ||
//console.error(newGetToken) | ||
const getToken = newGetToken | ||
const r3 = { | ||
@@ -61,2 +72,8 @@ // Take all the configuration data and make it available | ||
}, | ||
async userData(username: string): Promise<IUser> { | ||
return r3 | ||
.post('/user/info/') | ||
.then(resp => r3.user.process(resp, username)) | ||
.then(r3.user.updateCredentials) | ||
}, | ||
language: { | ||
@@ -364,11 +381,6 @@ async get() { | ||
// TODO: Define return type | ||
async share( | ||
devices: IDevice[], | ||
emails: string[], | ||
authhash: string | ||
): Promise<any> { | ||
async share(devices: IDevice[], emails: string[]): Promise<any> { | ||
return r3.post('/developer/devices/share/invitation/', { | ||
actionurl: `${r3.successURL}/invite/accept?type=shareDevices&id=`, | ||
authhash, | ||
queue_name: 'WeavedTaskQueue', | ||
queue_name: r3.taskQueue, | ||
function: 'share_devices', | ||
@@ -386,11 +398,6 @@ label: 'sharing', | ||
// TODO: Define return type | ||
async transfer( | ||
devices: IDevice[], | ||
email: string, | ||
authhash: string | ||
): Promise<any> { | ||
async transfer(devices: IDevice[], email: string): Promise<any> { | ||
return r3.post('/developer/devices/invitation/transfer/', { | ||
actionurl: `${r3.successURL}/invite/accept?type=transfer&id=`, | ||
authhash, | ||
queue_name: 'WeavedTaskQueue', | ||
queue_name: r3.taskQueue, | ||
email, | ||
@@ -493,2 +500,36 @@ function: 'transfer_devices', | ||
}, | ||
async setCategory( | ||
deviceaddress: string, | ||
catA: string, | ||
catB: string, | ||
catC: string, | ||
catD: string, | ||
catE: string | ||
): Promise<any> { | ||
let body = { | ||
categoryA: catA, | ||
categoryB: catB, | ||
categoryC: catC, | ||
categoryD: catD, | ||
categoryE: catE, | ||
} | ||
return r3.post('/device/category/' + deviceaddress, body) | ||
}, | ||
async setStatus( | ||
deviceaddress: string, | ||
statusA: string, | ||
statusB: string, | ||
statusC: string, | ||
statusD: string, | ||
statusE: string | ||
): Promise<any> { | ||
let body = { | ||
statusA: statusA, | ||
statusB: statusB, | ||
statusC: statusC, | ||
statusD: statusD, | ||
statusE: statusE, | ||
} | ||
return r3.post('/device/status/' + deviceaddress, body) | ||
}, | ||
}, | ||
@@ -529,2 +570,25 @@ scripts: { | ||
}, | ||
// TODO: Define return type | ||
async send( | ||
script: string, | ||
file: string, | ||
command: string, | ||
services: string, | ||
expiration: string, | ||
post_func: string, | ||
options: string, | ||
allowUpdates: string | ||
) { | ||
return r3.post('/bulk/job', { | ||
queue_name: r3.jobQueue, | ||
script: script, | ||
file: file, | ||
command: Base64.encode(command), | ||
expiration: expiration, | ||
function: post_func, | ||
options: options, | ||
services: services, | ||
allow_updates: allowUpdates, | ||
}) | ||
}, | ||
}, | ||
@@ -709,2 +773,21 @@ contacts: { | ||
}, | ||
// TODO: Define return type | ||
async setProuct( | ||
bulkID: string, | ||
descriptor: string, | ||
productID: string | ||
): Promise<any> { | ||
return r3.post('/bulk/registration/name/', { | ||
bulk_id: bulkID, | ||
productid: productID, | ||
descriptor: descriptor, | ||
}) | ||
}, | ||
// TODO: Define return type | ||
async setName(bulkID: string, name: string): Promise<any> { | ||
return r3.post('/bulk/registration/product/descriptor/', { | ||
bulk_id: bulkID, | ||
name: name, | ||
}) | ||
}, | ||
}, | ||
@@ -722,2 +805,34 @@ entities: { | ||
}, | ||
utilities: { | ||
// TODO: Define return type | ||
async serverUrl(): Promise<any> { | ||
return r3.get('/server/url/').then(({ url }) => url) | ||
}, | ||
// TODO: Define return type | ||
async tinyUrl(orginalUrl: string): Promise<any> { | ||
return r3 | ||
.post('/tiny/', { | ||
url: orginalUrl, | ||
}) | ||
.then(function(item) { | ||
if (item && item.id) { | ||
return options.apiURL + '/tiny/' + item.id | ||
} | ||
return orginalUrl | ||
}) | ||
}, | ||
// TODO: Define return type | ||
async shortCode(orginalUrl: string): Promise<any> { | ||
return r3 | ||
.post('/tiny/', { | ||
url: orginalUrl, | ||
}) | ||
.then(function(item) { | ||
if (item && item.id) { | ||
return item.id | ||
} | ||
return orginalUrl | ||
}) | ||
}, | ||
}, | ||
@@ -730,18 +845,47 @@ /*------------------------------------------------------------------------------- | ||
async request(method: Method, url: string, data = {}, extraHeaders = {}) { | ||
return r3.axios | ||
.request({ | ||
url, | ||
method, | ||
data, | ||
headers: { | ||
...extraHeaders, | ||
...pickBy({ | ||
accessKey: r3.accessKey, | ||
apiKey: r3.apiKey, | ||
developerKey: r3.developerKey, | ||
token: r3.token, | ||
}), | ||
}, | ||
}) | ||
.then(r3.processData, r3.processError) | ||
if (getToken !== undefined) { | ||
//console.error('getcurrentsession') | ||
//let currentSession = await Auth.currentSession() | ||
//console.error('currentsession') | ||
//console.error(currentSession) | ||
// let token = 'Bearer ' + r3.getToken().getJwtToken() | ||
let token = await getToken!() | ||
return r3.axios | ||
.request({ | ||
url, | ||
method, | ||
data, | ||
headers: { | ||
...extraHeaders, | ||
...pickBy({ | ||
Authorization: token, | ||
developerKey: r3.developerKey, | ||
}), | ||
}, | ||
}) | ||
.then(r3.processData, r3.processError) | ||
} else { | ||
//console.error(err) | ||
//console.error(err.message) | ||
//alert('ERROR: ' + error.message) | ||
//No AWS Auth, use legacy | ||
return r3.axios | ||
.request({ | ||
url, | ||
method, | ||
data, | ||
headers: { | ||
...extraHeaders, | ||
...pickBy({ | ||
accessKey: r3.accessKey, | ||
apiKey: r3.apiKey, | ||
developerKey: r3.developerKey, | ||
token: r3.token, | ||
}), | ||
}, | ||
}) | ||
.then(r3.processData, r3.processError) | ||
} | ||
}, | ||
@@ -812,2 +956,4 @@ async get(url: string, data = {}) { | ||
successURL?: string | ||
taskQueue?: string | ||
jobQueue?: string | ||
token?: string | ||
@@ -814,0 +960,0 @@ } |
@@ -737,9 +737,7 @@ import setup, { | ||
const emails = ['foo@bar.com'] | ||
const authhash = 'abc' | ||
;(r3.axios.request as jest.Mock).mockResolvedValueOnce({ data: {} }) | ||
jest.spyOn(r3, 'post') | ||
await r3.devices.share(devices, emails, authhash) | ||
await r3.devices.share(devices, emails) | ||
expect(r3.post).toBeCalledWith('/developer/devices/share/invitation/', { | ||
actionurl: `${r3.successURL}/invite/accept?type=shareDevices&id=`, | ||
authhash, | ||
queue_name: 'WeavedTaskQueue', | ||
@@ -773,6 +771,5 @@ function: 'share_devices', | ||
const email = 'foo@bar.com' | ||
const authhash = 'abc' | ||
;(r3.axios.request as jest.Mock).mockResolvedValueOnce({ data: {} }) | ||
jest.spyOn(r3, 'post') | ||
await r3.devices.transfer(devices, email, authhash) | ||
await r3.devices.transfer(devices, email) | ||
expect(r3.post).toBeCalledWith( | ||
@@ -782,3 +779,2 @@ '/developer/devices/invitation/transfer/', | ||
actionurl: `${r3.successURL}/invite/accept?type=transfer&id=`, | ||
authhash, | ||
queue_name: 'WeavedTaskQueue', | ||
@@ -785,0 +781,0 @@ function: 'transfer_devices', |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
177345
4
17
4067
+ Added@types/js-base64@^2.3.1
+ Addedjs-base64@^2.5.1
+ Added@types/js-base64@2.3.2(transitive)
+ Addedjs-base64@2.6.4(transitive)