Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release Resin-SDK v7.0.0 #420

Merged
23 commits merged into from Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8ad02b8
*BREAKING*: Remove application.online_devices and application.device_…
pimterry Sep 28, 2017
0e704c9
*BREAKING*: Remove device.application_name and device.dashboard_url
pimterry Sep 28, 2017
d809e82
*BREAKING*: Don't expand relationships by default. Pass { expand: '..…
pimterry Sep 28, 2017
b7e9445
Update yarn.lock
pimterry Sep 29, 2017
89afe7b
Make device.move throw ResinInvalidDeviceType for incompatible device…
pimterry Sep 29, 2017
4391099
*BREAKING*: Don't allow creating applications with discontinued devic…
pimterry Sep 21, 2017
c1b1497
*BREAKING*: Rename getAppWithOwner to getAppByOwner
pimterry Oct 2, 2017
beae7c5
Merge pull request #398 from resin-io/358-discontinued-device-types
pimterry Sep 25, 2017
84ad402
*BREAKING*: Remove (already deprecated) models.application.getApiKey()
pimterry Oct 2, 2017
9f7b234
Merge pull request #407 from resin-io/breaking-improvements
pimterry Oct 2, 2017
a340c22
Change device registration to use a provisioning key
pimterry Oct 2, 2017
116762c
*BREAKING*: Stop actively supporting node 4.
pimterry Oct 10, 2017
37151cb
Merge pull request #410 from resin-io/remove-generate-api-key
pimterry Oct 4, 2017
3240147
Merge pull request #417 from resin-io/deprecate-node-4
pimterry Oct 11, 2017
10166ee
Ignore all .env files
pimterry Sep 26, 2017
0059047
*BREAKING*: Tie the SDK to a specific API version (removing `apiVersion`
pimterry Oct 11, 2017
7974dc2
*BREAKING*: Upgrade to API v3. Main change is that all relationships …
pimterry Sep 28, 2017
d6f99f3
Merge pull request #418 from resin-io/api-v3
pimterry Oct 12, 2017
c0e9e7c
Fix device interacting methods broken by non-automatic relationships
pimterry Oct 12, 2017
8e74381
Make device.update options optional
pimterry Oct 12, 2017
b949de6
Fix breaking bugs in device.enable/disableTcpPing
pimterry Oct 12, 2017
ea7e818
*BREAKING*: Remove device.ensureSupervisorCompatibility - use semver …
pimterry Oct 12, 2017
b446b46
v7.0.0
Oct 12, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -25,7 +25,7 @@ node_modules


.DS_Store
.env
.env*
.vscode

# Ignore all build output
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -14,8 +14,6 @@ matrix:
- '6'
env:
- 'CAN_DEPLOY=true'
- node_js:
- '4'
before_install:
- npm -g install npm@4
script:
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).

## v7.0.0 - 2017-10-12

* *BREAKING*: Remove device.ensureSupervisorCompatibility - use semver directly instead #420 [Tim Perry]
* Fix breaking bugs in device.enable/disableTcpPing #420 [Tim Perry]
* Make device.update options optional #420 [Tim Perry]
* *BREAKING*: Upgrade to API v3. Main change is that all relationships & result properties now include verbs (e.g. device.application is now device.belongs_to__application). #420 [Tim Perry]
* *BREAKING*: Tie the SDK to a specific API version (removing `apiVersion` option) #420 [Tim Perry]
* *BREAKING*: Stop actively supporting node 4. #420 [Tim Perry]
* Change device registration to use a provisioning key #420 [Tim Perry]
* *BREAKING*: Remove (already deprecated) models.application.getApiKey() #420 [Tim Perry]
* *BREAKING*: Rename getAppWithOwner to getAppByOwner #420 [Tim Perry]
* *BREAKING*: Don't allow creating applications with discontinued device types #420 [Tim Perry]
* Make device.move throw ResinInvalidDeviceType for incompatible device types (not just Error) #420 [Tim Perry]
* *BREAKING*: Don't expand relationships by default. Pass { expand: '...' } options to opt in instead. #420 [Tim Perry]
* *BREAKING*: Remove device.application_name and device.dashboard_url #420 [Tim Perry]
* *BREAKING*: Remove application.online_devices and application.device_length #420 [Tim Perry]

## v6.15.0 - 2017-10-12

* Add application.generateProvisioningKey() #419 [Tim Perry]
Expand Down
33 changes: 7 additions & 26 deletions DOCUMENTATION.md
Expand Up @@ -20,7 +20,7 @@ If you feel something is missing, not clear or could be improved, please don't h
* [.application](#resin.models.application) : <code>object</code>
* [.getAll([options])](#resin.models.application.getAll) ⇒ <code>Promise</code>
* [.get(nameOrId, [options])](#resin.models.application.get) ⇒ <code>Promise</code>
* [.getAppWithOwner(appName, owner, [options])](#resin.models.application.getAppWithOwner) ⇒ <code>Promise</code>
* [.getAppByOwner(appName, owner, [options])](#resin.models.application.getAppByOwner) ⇒ <code>Promise</code>
* [.has(nameOrId)](#resin.models.application.has) ⇒ <code>Promise</code>
* [.hasAny()](#resin.models.application.hasAny) ⇒ <code>Promise</code>
* ~~[.getById(id)](#resin.models.application.getById) ⇒ <code>Promise</code>~~
Expand All @@ -32,7 +32,6 @@ If you feel something is missing, not clear or could be improved, please don't h
* [.purge(appId)](#resin.models.application.purge) ⇒ <code>Promise</code>
* [.shutdown(appId, [options])](#resin.models.application.shutdown) ⇒ <code>Promise</code>
* [.reboot(appId, [options])](#resin.models.application.reboot) ⇒ <code>Promise</code>
* ~~[.getApiKey(nameOrId)](#resin.models.application.getApiKey) ⇒ <code>Promise</code>~~
* [.enableDeviceUrls(nameOrId)](#resin.models.application.enableDeviceUrls) ⇒ <code>Promise</code>
* [.disableDeviceUrls(nameOrId)](#resin.models.application.disableDeviceUrls) ⇒ <code>Promise</code>
* [.grantSupportAccess(nameOrId, expiryTimestamp)](#resin.models.application.grantSupportAccess) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -235,7 +234,7 @@ in the SDK.
resin.pine.get({
resource: 'build/$count',
options: {
filter: { application: applicationId }
filter: { belongs_to__application: applicationId }
}
});
```
Expand Down Expand Up @@ -269,7 +268,7 @@ resin.models.device.get(123).catch(function (error) {
* [.application](#resin.models.application) : <code>object</code>
* [.getAll([options])](#resin.models.application.getAll) ⇒ <code>Promise</code>
* [.get(nameOrId, [options])](#resin.models.application.get) ⇒ <code>Promise</code>
* [.getAppWithOwner(appName, owner, [options])](#resin.models.application.getAppWithOwner) ⇒ <code>Promise</code>
* [.getAppByOwner(appName, owner, [options])](#resin.models.application.getAppByOwner) ⇒ <code>Promise</code>
* [.has(nameOrId)](#resin.models.application.has) ⇒ <code>Promise</code>
* [.hasAny()](#resin.models.application.hasAny) ⇒ <code>Promise</code>
* ~~[.getById(id)](#resin.models.application.getById) ⇒ <code>Promise</code>~~
Expand All @@ -281,7 +280,6 @@ resin.models.device.get(123).catch(function (error) {
* [.purge(appId)](#resin.models.application.purge) ⇒ <code>Promise</code>
* [.shutdown(appId, [options])](#resin.models.application.shutdown) ⇒ <code>Promise</code>
* [.reboot(appId, [options])](#resin.models.application.reboot) ⇒ <code>Promise</code>
* ~~[.getApiKey(nameOrId)](#resin.models.application.getApiKey) ⇒ <code>Promise</code>~~
* [.enableDeviceUrls(nameOrId)](#resin.models.application.enableDeviceUrls) ⇒ <code>Promise</code>
* [.disableDeviceUrls(nameOrId)](#resin.models.application.disableDeviceUrls) ⇒ <code>Promise</code>
* [.grantSupportAccess(nameOrId, expiryTimestamp)](#resin.models.application.grantSupportAccess) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -379,7 +377,7 @@ resin.models.device.get(123).catch(function (error) {
* [.application](#resin.models.application) : <code>object</code>
* [.getAll([options])](#resin.models.application.getAll) ⇒ <code>Promise</code>
* [.get(nameOrId, [options])](#resin.models.application.get) ⇒ <code>Promise</code>
* [.getAppWithOwner(appName, owner, [options])](#resin.models.application.getAppWithOwner) ⇒ <code>Promise</code>
* [.getAppByOwner(appName, owner, [options])](#resin.models.application.getAppByOwner) ⇒ <code>Promise</code>
* [.has(nameOrId)](#resin.models.application.has) ⇒ <code>Promise</code>
* [.hasAny()](#resin.models.application.hasAny) ⇒ <code>Promise</code>
* ~~[.getById(id)](#resin.models.application.getById) ⇒ <code>Promise</code>~~
Expand All @@ -391,7 +389,6 @@ resin.models.device.get(123).catch(function (error) {
* [.purge(appId)](#resin.models.application.purge) ⇒ <code>Promise</code>
* [.shutdown(appId, [options])](#resin.models.application.shutdown) ⇒ <code>Promise</code>
* [.reboot(appId, [options])](#resin.models.application.reboot) ⇒ <code>Promise</code>
* ~~[.getApiKey(nameOrId)](#resin.models.application.getApiKey) ⇒ <code>Promise</code>~~
* [.enableDeviceUrls(nameOrId)](#resin.models.application.enableDeviceUrls) ⇒ <code>Promise</code>
* [.disableDeviceUrls(nameOrId)](#resin.models.application.disableDeviceUrls) ⇒ <code>Promise</code>
* [.grantSupportAccess(nameOrId, expiryTimestamp)](#resin.models.application.grantSupportAccess) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -454,9 +451,9 @@ resin.models.application.get('MyApp', function(error, application) {
console.log(application);
});
```
<a name="resin.models.application.getAppWithOwner"></a>
<a name="resin.models.application.getAppByOwner"></a>

##### application.getAppWithOwner(appName, owner, [options]) ⇒ <code>Promise</code>
##### application.getAppByOwner(appName, owner, [options]) ⇒ <code>Promise</code>
**Kind**: static method of <code>[application](#resin.models.application)</code>
**Summary**: Get a single application using the appname and owner's username
**Access**: public
Expand All @@ -470,7 +467,7 @@ resin.models.application.get('MyApp', function(error, application) {

**Example**
```js
resin.models.application.getAppWithOwner('MyApp', 'MyUser').then(function(application) {
resin.models.application.getAppByOwner('MyApp', 'MyUser').then(function(application) {
console.log(application);
});
```
Expand Down Expand Up @@ -768,21 +765,6 @@ resin.models.application.reboot(123, function(error) {
if (error) throw error;
});
```
<a name="resin.models.application.getApiKey"></a>

##### ~~application.getApiKey(nameOrId) ⇒ <code>Promise</code>~~
***Deprecated***

**Kind**: static method of <code>[application](#resin.models.application)</code>
**Summary**: Get an API key for a specific application
**Access**: public
**Fulfil**: <code>String</code> - api key
**See**: [generateApiKey](#resin.models.application.generateApiKey)

| Param | Type | Description |
| --- | --- | --- |
| nameOrId | <code>String</code> \| <code>Number</code> | application name (string) or id (number) |

<a name="resin.models.application.enableDeviceUrls"></a>

##### application.enableDeviceUrls(nameOrId) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -3726,7 +3708,6 @@ startup and before any calls to `fromSharedOptions()` are made.
resin.setSharedOptions({
apiUrl: 'https://api.resin.io/',
imageMakerUrl: 'https://img.resin.io/',
apiVersion: 'v2',
isBrowser: true,
});
```
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -26,7 +26,8 @@ $ npm install --save resin-sdk
Platforms
---------

We currently support NodeJS and the browser.
We currently support NodeJS (6+) and the browser.

The following features are node-only:
- OS image streaming download (`resin.models.os.download`),
- resin settings client (`resin.settings`).
Expand Down Expand Up @@ -63,7 +64,6 @@ var resin = require('resin-sdk')({

Where the factory method accepts the following options:
* `apiUrl`, string, *optional*, is the resin.io API url. Defaults to `https://api.resin.io/`,
* `apiVersion`, string, *optional*, is the version of the API to talk to, like `v2`. Defaults to the current stable version: `v2`,
* `apiKey`, string, *optional*, is the API key to make the requests with,
* `imageMakerUrl`, string, *optional*, is the resin.io image maker url. Defaults to `https://img.resin.io/`,
* `dataDirectory`, string, *optional*, *ignored in the browser*, is the directory where the user settings are stored, normally retrieved like `require('resin-settings-client').get('dataDirectory')`. Defaults to `$HOME/.resin`,
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Expand Up @@ -14,13 +14,13 @@ matrix:
# what combinations to test
environment:
matrix:
- nodejs_version: 6
- nodejs_version: 8
RESINTEST_EMAIL: 'test2+juan@resin.io'
RESINTEST_USERNAME: 'test2_juan'
RESINTEST_USERID: 5616
RESINTEST_REGISTER_EMAIL: 'test2+register+juan@resin.io'
RESINTEST_REGISTER_USERNAME: 'test2_register_juan'
- nodejs_version: 4
- nodejs_version: 6
RESINTEST_EMAIL: 'test3+juan@resin.io'
RESINTEST_USERNAME: 'test3_juan'
RESINTEST_USERID: 8717
Expand Down
65 changes: 23 additions & 42 deletions lib/models/application.coffee
Expand Up @@ -55,8 +55,8 @@ getApplicationModel = (deps, opts) ->
exports._getId = getId

normalizeApplication = (application) ->
if isArray(application.device)
forEach application.device, (device) ->
if isArray(application.owns__device)
forEach application.owns__device, (device) ->
normalizeDeviceOsVersion(device)
return application

Expand Down Expand Up @@ -91,16 +91,11 @@ getApplicationModel = (deps, opts) ->
options:
mergePineOptions
orderby: 'app_name asc'
expand: 'device'
filter:
user: userId
, options

# TODO: It might be worth to do all these handy
# manipulations server side directly.
.map (application) ->
application.online_devices = filter(application.device, is_online: true).length
application.devices_length = application.device?.length or 0
normalizeApplication(application)
return application

Expand Down Expand Up @@ -169,7 +164,7 @@ getApplicationModel = (deps, opts) ->

###*
# @summary Get a single application using the appname and owner's username
# @name getAppWithOwner
# @name getAppByOwner
# @public
# @function
# @memberof resin.models.application
Expand All @@ -181,11 +176,11 @@ getApplicationModel = (deps, opts) ->
# @returns {Promise}
#
# @example
# resin.models.application.getAppWithOwner('MyApp', 'MyUser').then(function(application) {
# resin.models.application.getAppByOwner('MyApp', 'MyUser').then(function(application) {
# console.log(application);
# });
###
exports.getAppWithOwner = (appName, owner, options = {}, callback) ->
exports.getAppByOwner = (appName, owner, options = {}, callback) ->
callback = findCallback(arguments)

appName = appName.toLowerCase()
Expand All @@ -199,15 +194,14 @@ getApplicationModel = (deps, opts) ->
$eq: [
$tolower: $: 'app_name'
appName
]
expand:
],
user:
$filter:
$eq: [
$any:
$alias: 'u',
$expr: $eq: [
$tolower: $: 'username'
owner
]
$select: 'id'
, options
.tap (applications) ->
if isEmpty(applications)
Expand Down Expand Up @@ -349,23 +343,26 @@ getApplicationModel = (deps, opts) ->
else
Promise.resolve()

deviceSlugPromise = deviceModel().getDeviceSlug(deviceType)
.tap (deviceSlug) ->
if not deviceSlug?
deviceManifestPromise = deviceModel().getManifestBySlug(deviceType)
.tap (deviceManifest) ->
if not deviceManifest?
throw new errors.ResinInvalidDeviceType(deviceType)

return Promise.all([ deviceSlugPromise, parentAppPromise ])
.then ([ deviceSlug, parentApplication ]) ->
return Promise.all([ deviceManifestPromise, parentAppPromise ])
.then ([ deviceManifest, parentApplication ]) ->
if deviceManifest.state == 'DISCONTINUED'
throw new errors.ResinDiscontinuedDeviceType(deviceType)

extraOptions = if parentApplication
application: parentApplication.id
depends_on__application: parentApplication.id
else {}

return pine.post
resource: 'application'
body:
assign
app_name: name
device_type: deviceSlug
device_type: deviceManifest.slug
, extraOptions
.asCallback(callback)

Expand Down Expand Up @@ -614,22 +611,6 @@ getApplicationModel = (deps, opts) ->
throw err
.asCallback(callback)

###*
# @summary Get an API key for a specific application
# @name getApiKey
# @public
# @function
# @memberof resin.models.application
#
# @param {String|Number} nameOrId - application name (string) or id (number)
# @fulfil {String} - api key
# @returns {Promise}
#
# @deprecated Use generateApiKey instead
# @see {@link resin.models.application.generateApiKey}
###
exports.getApiKey = exports.generateApiKey

###*
# @summary Enable device urls for all devices that belong to an application
# @name enableDeviceUrls
Expand Down Expand Up @@ -659,7 +640,7 @@ getApplicationModel = (deps, opts) ->
is_web_accessible: true
options:
filter:
application: id
belongs_to__application: id
.asCallback(callback)

###*
Expand Down Expand Up @@ -691,7 +672,7 @@ getApplicationModel = (deps, opts) ->
is_web_accessible: false
options:
filter:
application: id
belongs_to__application: id
.asCallback(callback)

###*
Expand Down Expand Up @@ -724,7 +705,7 @@ getApplicationModel = (deps, opts) ->
return pine.patch
resource: 'application'
id: applicationId
body: support_expiry_date: expiryTimestamp
body: is_accessible_by_support_until__date: expiryTimestamp
.catch(notFoundResponse, treatAsMissingApplication(nameOrId))
.asCallback(callback)

Expand Down Expand Up @@ -754,7 +735,7 @@ getApplicationModel = (deps, opts) ->
return pine.patch
resource: 'application'
id: applicationId
body: support_expiry_date: null
body: is_accessible_by_support_until__date: null
.catch(notFoundResponse, treatAsMissingApplication(nameOrId))
.asCallback(callback)

Expand Down
8 changes: 1 addition & 7 deletions lib/models/build.coffee
Expand Up @@ -98,7 +98,7 @@ getBuildModel = (deps, opts) ->
options:
mergePineOptions
filter:
application: id
belongs_to__application: id
select: [
'id'
'created_at'
Expand All @@ -113,12 +113,6 @@ getBuildModel = (deps, opts) ->
'message'
# 'log' # We *don't* include logs by default, since it's usually huge.
]
expand:
user:
$select: [
'id'
'username'
]
orderby: 'created_at desc'
, options
.asCallback(callback)
Expand Down