Socket
Socket
Sign inDemoInstall

remote.it

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remote.it - npm Package Compare versions

Comparing version 0.42.2-alpha.0 to 0.43.1

26

lib/remote.it.d.ts

@@ -1,2 +0,2 @@

import { AxiosError } from 'axios'
import { AxiosError, Method } from 'axios'
export default function setup(

@@ -71,6 +71,16 @@ config?: IConfig

list(): Promise<IContact[]>
create(contact: IContact): Promise<IContact>
create(contact: IContactPoster): Promise<IContact>
update(contact: IContactPoster): Promise<IContact>
invite(contact: IContact): Promise<IContact>
destroy(contactID: string): Promise<any>
_format(c: IRawContact): IContact
_formatUpdate(c: {
companyname: string
email: string
firstname: string
lastname: string
id: string
language: string
status: string
}): IContact
}

@@ -99,3 +109,3 @@ products: {

request(
method: string,
method: Method,
url: string,

@@ -111,3 +121,3 @@ data?: {},

processData(resp?: any): any
processError(error: AxiosError): never
processError(error: AxiosError<any>): never
accessKey?: string | undefined

@@ -401,2 +411,10 @@ apiURL?: string | undefined

}
export interface IContactPoster {
companyname?: string
email: string
firstname?: string
lastname?: string
language?: string
id?: string
}
export interface IContact {

@@ -403,0 +421,0 @@ accountCreated: boolean

92

lib/remote.it.js

@@ -84,3 +84,2 @@ "use strict";

var utils_1 = require("./utils");
var auth_1 = __importDefault(require("@aws-amplify/auth"));
var defaults = {

@@ -690,17 +689,16 @@ apiURL: 'https://api.remot3.it/apv/v27',

return [2 /*return*/, r3
.post('/developer/customer/', {
email: contact.email,
firstname: contact.firstName,
lastname: contact.lastName,
language: contact.language,
companyname: contact.companyName,
})
.then(function (_a) {
var id = _a.id;
return id;
})];
.post('/developer/customer/', contact)
.then(function (resp) { return r3.contacts._formatUpdate(resp); })];
});
});
},
// .then(({ contact }) => r3.contacts._format(customer))
update: function (contact) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, r3
.post('/developer/customer/', contact)
.then(function (updatedContact) { return r3.contacts._formatUpdate(updatedContact); })];
});
});
},
invite: function (contact) {

@@ -740,2 +738,18 @@ return __awaiter(this, void 0, void 0, function () {

},
_formatUpdate: function (c) {
var nowInt = Date.now();
return {
accountCreated: false,
companyName: c.companyname !== undefined && c.companyname !== '-'
? c.companyname
: '',
createdAt: new Date(nowInt),
email: c.email,
firstName: c.firstname !== undefined && c.firstname !== '-' ? c.firstname : '',
id: c.id,
language: c.language || 'en',
lastName: c.lastname !== undefined && c.lastname !== '-' ? c.lastname : '',
updatedAt: new Date(nowInt),
};
},
}, products: {

@@ -916,42 +930,16 @@ list: function () {

return __awaiter(this, void 0, void 0, function () {
var currentSession, token, error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, auth_1.default.currentSession()];
case 1:
currentSession = _a.sent();
token = 'Bearer ' + currentSession.getAccessToken().getJwtToken();
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:
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*/];
}
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)];
});

@@ -958,0 +946,0 @@ });

{
"name": "remote.it",
"version": "0.42.2-alpha.0",
"version": "0.43.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,3 @@ ],

"dependencies": {
"@aws-amplify/auth": "1.3.3",
"axios": "0.18.0",
"axios": "0.19.0",
"luxon": "1.13.2"

@@ -83,3 +82,3 @@ },

"homepage": "https://github.com/remoteit/remote.it.js#readme",
"gitHead": "b9d89f622bdda332c8ec931c699f21377c4d49da"
"gitHead": "cae3f322fcf94df3eefe1a9cc229c6023b196d30"
}

@@ -1,4 +0,3 @@

import axios, { AxiosError, AxiosResponse } from 'axios'
import axios, { AxiosError, AxiosResponse, Method } from 'axios'
import { groupBy, parseLegacyDate, pickBy, toNumber } from './utils'
import Auth from '@aws-amplify/auth'

@@ -532,14 +531,12 @@ const defaults = {

},
async create(contact: IContact): Promise<IContact> {
async create(contact: IContactPoster): Promise<IContact> {
return r3
.post('/developer/customer/', {
email: contact.email,
firstname: contact.firstName,
lastname: contact.lastName,
language: contact.language,
companyname: contact.companyName,
})
.then(({ id }) => id)
.post('/developer/customer/', contact)
.then(resp => r3.contacts._formatUpdate(resp))
},
// .then(({ contact }) => r3.contacts._format(customer))
async update(contact: IContactPoster): Promise<IContact> {
return r3
.post('/developer/customer/', contact)
.then(updatedContact => r3.contacts._formatUpdate(updatedContact))
},
async invite(contact: IContact): Promise<IContact> {

@@ -571,2 +568,29 @@ return r3

},
_formatUpdate(c: {
companyname: string
email: string
firstname: string
lastname: string
id: string
language: string
status: string
}): IContact {
const nowInt = Date.now()
return {
accountCreated: false,
companyName:
c.companyname !== undefined && c.companyname !== '-'
? c.companyname
: '',
createdAt: new Date(nowInt),
email: c.email,
firstName:
c.firstname !== undefined && c.firstname !== '-' ? c.firstname : '',
id: c.id,
language: c.language || 'en',
lastName:
c.lastname !== undefined && c.lastname !== '-' ? c.lastname : '',
updatedAt: new Date(nowInt),
}
},
},

@@ -697,43 +721,19 @@ products: {

async request(method: string, url: string, data = {}, extraHeaders = {}) {
try {
let currentSession = await Auth.currentSession()
let token = 'Bearer ' + currentSession.getAccessToken().getJwtToken()
return r3.axios
.request({
url,
method,
data,
headers: {
...extraHeaders,
...pickBy({
Authorization: token,
developerKey: r3.developerKey,
}),
},
})
.then(r3.processData, r3.processError)
} catch (error) {
//console.error(error)
//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)
}
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)
},

@@ -1105,3 +1105,10 @@ async get(url: string, data = {}) {

}
export interface IContactPoster {
companyname?: string
email: string
firstname?: string
lastname?: string
language?: string
id?: string
}
export interface IContact {

@@ -1108,0 +1115,0 @@ accountCreated: boolean

@@ -6,2 +6,3 @@ import setup, {

R3FromData,
IContactPoster,
} from '../src/remote.it'

@@ -265,4 +266,4 @@ import * as mockData from './data'

name: 'device',
expires: new Date('June 19, 2019 17:05:13'),
lastTransaction: new Date('October 19, 2018 16:56:26'),
expires: new Date('June 19, 2019 19:05:13 GMT-05:00'),
lastTransaction: new Date('October 19, 2018 18:56:26 GMT-05:00'),
quantity: 2,

@@ -303,4 +304,8 @@ price: 200,

})
describe('r3.contacts', () => {
beforeAll(() => {
// Lock Time
const now = Date.now()
let dateNowSpy = jest.spyOn(Date, 'now').mockImplementation(() => now)
})
describe('.list', () => {

@@ -339,2 +344,74 @@ test('should return a list of customers', async () => {

})
describe('.create', () => {
test('should return a created contact', async () => {
const createDate = new Date(Date.now())
const newCustomerParams = {
email: 'hello@world.com',
firstname: 'first',
lastname: 'last',
}
const newCustomerResponse = {
email: newCustomerParams.email,
companyname: '_',
firstname: newCustomerParams.firstname,
lastname: newCustomerParams.lastname,
id: '12345151',
status: 'true',
}
jest.spyOn(r3, 'post').mockResolvedValueOnce(newCustomerResponse)
const newContact = await r3.contacts.create(newCustomerParams)
expect(r3.post).toBeCalledWith(
'/developer/customer/',
newCustomerParams
)
expect(newContact).toEqual({
accountCreated: false,
companyName: '_',
createdAt: createDate,
email: newCustomerResponse.email,
firstName: newCustomerResponse.firstname,
id: newCustomerResponse.id,
language: 'en',
lastName: newCustomerResponse.lastname,
updatedAt: createDate,
})
})
})
describe('.update', () => {
test('should return a formatted updated contact', async () => {
const createDate = new Date(Date.now())
const customerParams = {
email: 'hello@world.com',
firstname: 'first',
lastname: 'last',
id: '12345',
language: 'fr',
companyname: 'New Company',
}
const customerResponse = {
email: customerParams.email,
companyname: customerParams.companyname,
firstname: customerParams.firstname,
lastname: customerParams.lastname,
id: customerParams.id,
language: customerParams.language,
status: 'true',
}
jest.spyOn(r3, 'post').mockResolvedValueOnce(customerResponse)
const newContact = await r3.contacts.create(customerParams)
expect(r3.post).toBeCalledWith('/developer/customer/', customerParams)
expect(newContact).toEqual({
accountCreated: false,
companyName: customerResponse.companyname,
createdAt: createDate,
email: customerResponse.email,
firstName: customerResponse.firstname,
id: customerResponse.id,
language: customerResponse.language,
lastName: customerResponse.lastname,
updatedAt: createDate,
})
})
})
})

@@ -341,0 +418,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc