Comparing version 0.42.2-alpha.0 to 0.42.2-alpha.1
import { AxiosError } 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> | ||
} | ||
@@ -95,2 +123,8 @@ contacts: { | ||
list(): Promise<IRegistration[]> | ||
setProuct( | ||
bulkID: string, | ||
descriptor: string, | ||
productID: string | ||
): Promise<any> | ||
setName(bulkID: string, name: string): Promise<any> | ||
} | ||
@@ -101,2 +135,7 @@ entities: { | ||
} | ||
utilities: { | ||
serverUrl(): Promise<any> | ||
tinyUrl(orginalUrl: string): Promise<any> | ||
shortCode(orginalUrl: string): Promise<any> | ||
} | ||
request( | ||
@@ -121,2 +160,4 @@ method: string, | ||
successURL?: string | undefined | ||
taskQueue?: string | undefined | ||
jobQueue?: string | undefined | ||
token?: string | undefined | ||
@@ -131,2 +172,4 @@ } | ||
successURL?: string | ||
taskQueue?: string | ||
jobQueue?: string | ||
token?: string | ||
@@ -133,0 +176,0 @@ } |
@@ -84,8 +84,10 @@ "use strict"; | ||
var utils_1 = require("./utils"); | ||
var auth_1 = __importDefault(require("@aws-amplify/auth")); | ||
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 = {}; } | ||
@@ -101,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, { | ||
@@ -145,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: { | ||
@@ -490,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 () { | ||
@@ -496,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', | ||
@@ -513,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 () { | ||
@@ -519,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, | ||
@@ -612,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: { | ||
@@ -680,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: { | ||
@@ -894,2 +956,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: { | ||
@@ -914,2 +999,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; | ||
})]; | ||
}); | ||
}); | ||
}, | ||
}, | ||
@@ -924,11 +1055,10 @@ /*------------------------------------------------------------------------------- | ||
return __awaiter(this, void 0, void 0, function () { | ||
var currentSession, token, error_1; | ||
var token; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
return [4 /*yield*/, auth_1.default.currentSession()]; | ||
if (!(getToken !== undefined)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, getToken()]; | ||
case 1: | ||
currentSession = _a.sent(); | ||
token = 'Bearer ' + currentSession.getAccessToken().getJwtToken(); | ||
token = _a.sent(); | ||
return [2 /*return*/, r3.axios | ||
@@ -945,21 +1075,20 @@ .request({ | ||
.then(r3.processData, r3.processError)]; | ||
case 2: | ||
error_1 = _a.sent(); | ||
//console.error(error) | ||
//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)]; | ||
case 3: return [2 /*return*/]; | ||
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)]; | ||
} | ||
@@ -966,0 +1095,0 @@ }); |
{ | ||
"name": "remote.it", | ||
"version": "0.42.2-alpha.0", | ||
"version": "0.42.2-alpha.1", | ||
"description": "remote.it JavaScript/node client library", | ||
@@ -41,3 +41,3 @@ "main": "lib/remote.it.js", | ||
"path": "lib/*.js", | ||
"limit": "130 kB" | ||
"limit": "30 kB" | ||
} | ||
@@ -47,4 +47,5 @@ ], | ||
"dependencies": { | ||
"@aws-amplify/auth": "1.3.3", | ||
"@types/js-base64": "^2.3.1", | ||
"axios": "0.18.0", | ||
"js-base64": "^2.5.1", | ||
"luxon": "1.13.2" | ||
@@ -83,3 +84,3 @@ }, | ||
"homepage": "https://github.com/remoteit/remote.it.js#readme", | ||
"gitHead": "b9d89f622bdda332c8ec931c699f21377c4d49da" | ||
"gitHead": "04761b2cf1774b80dcf0889034b9355ca47f6b77" | ||
} |
import axios, { AxiosError, AxiosResponse } from 'axios' | ||
import { groupBy, parseLegacyDate, pickBy, toNumber } from './utils' | ||
import Auth from '@aws-amplify/auth' | ||
import { Base64 } from 'js-base64' | ||
@@ -8,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({ | ||
@@ -22,2 +26,4 @@ baseURL: options.apiURL, | ||
developerKey: options.developerKey, | ||
taskQueue: options.taskQueue, | ||
jobQueue: options.jobQueue, | ||
token: options.token, | ||
@@ -27,2 +33,6 @@ }), | ||
//console.error(newGetToken) | ||
const getToken = newGetToken | ||
const r3 = { | ||
@@ -62,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: { | ||
@@ -365,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', | ||
@@ -387,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, | ||
@@ -494,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) | ||
}, | ||
}, | ||
@@ -530,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, | ||
}) | ||
}, | ||
}, | ||
@@ -685,2 +748,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, | ||
}) | ||
}, | ||
}, | ||
@@ -698,2 +780,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 | ||
}) | ||
}, | ||
}, | ||
@@ -706,5 +820,9 @@ /*------------------------------------------------------------------------------- | ||
async request(method: string, url: string, data = {}, extraHeaders = {}) { | ||
try { | ||
let currentSession = await Auth.currentSession() | ||
let token = 'Bearer ' + currentSession.getAccessToken().getJwtToken() | ||
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!() | ||
@@ -725,4 +843,5 @@ return r3.axios | ||
.then(r3.processData, r3.processError) | ||
} catch (error) { | ||
//console.error(error) | ||
} else { | ||
//console.error(err) | ||
//console.error(err.message) | ||
//alert('ERROR: ' + error.message) | ||
@@ -813,2 +932,4 @@ //No AWS Auth, use legacy | ||
successURL?: string | ||
taskQueue?: string | ||
jobQueue?: string | ||
token?: string | ||
@@ -815,0 +936,0 @@ } |
@@ -660,9 +660,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', | ||
@@ -696,6 +694,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( | ||
@@ -705,3 +702,2 @@ '/developer/devices/invitation/transfer/', | ||
actionurl: `${r3.successURL}/invite/accept?type=transfer&id=`, | ||
authhash, | ||
queue_name: 'WeavedTaskQueue', | ||
@@ -708,0 +704,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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
171809
4
17
3924
1
+ 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)
- Removed@aws-amplify/auth@1.3.3
- Removed@aws-amplify/auth@1.3.3(transitive)
- Removed@aws-amplify/cache@1.2.3(transitive)
- Removed@aws-amplify/core@1.3.3(transitive)
- Removedamazon-cognito-identity-js@3.3.3(transitive)
- Removedaws-sdk@2.518.0(transitive)
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@4.9.1(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedcrypto-js@3.3.0(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedevents@1.1.1(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedieee754@1.1.8(transitive)
- Removedisarray@1.0.0(transitive)
- Removedjmespath@0.15.0(transitive)
- Removedjs-cookie@2.2.1(transitive)
- Removedobject-inspect@1.13.2(transitive)
- Removedpunycode@1.3.21.4.1(transitive)
- Removedqs@6.13.0(transitive)
- Removedquerystring@0.2.0(transitive)
- Removedsax@1.2.1(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedurl@0.10.30.11.4(transitive)
- Removeduuid@3.3.2(transitive)
- Removedxml2js@0.4.19(transitive)
- Removedxmlbuilder@9.0.7(transitive)