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

Update to the v7 model #1420

Merged
merged 28 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
43b58f0
package.json: Rename the lint:fix npm script to lint-fix
thgreasi Jul 20, 2024
5a1791a
[BREAKING]: Update the es2015 build target & output folder to es2017
thgreasi Jun 20, 2024
0bba30a
Bump minimum supported Typescript version to v5.5.2
thgreasi Jul 8, 2024
15366a6
[BREAKING]: Stop actively supporting TypeScript versions older than t…
thgreasi Jul 20, 2024
0ae7db2
Update pinejs-client-core to 6.15.0
thgreasi Jul 8, 2024
7af2b8a
Drop the no longer needed __metadata property handling
thgreasi Jun 20, 2024
bc5d286
Drop the unused OsVersionsByDeviceType type
thgreasi Jun 20, 2024
98fb9ae
[BREAKING]: application.create: Drop the applicationType & parent par…
thgreasi Jun 20, 2024
6d45fba
[BREAKING]: Drop the os.getSupervisorReleaseByDeviceType method
thgreasi Jun 20, 2024
477e2c6
Add the os.getSupervisorReleasesForCpuArchitecture() method
thgreasi Jun 20, 2024
4cdf1b4
[BREAKING]: Drop the application.getAppByOwner method
thgreasi Jun 20, 2024
d8cf966
[BREAKING]: Update all API queries to use the v7 model
thgreasi Jul 20, 2024
2f4474b
v7 model: Drop the gateway_download resource
thgreasi Jul 20, 2024
085362d
v7 model: Drop the device state & status_sort_index sdk-only property…
thgreasi Jul 20, 2024
6557e2a
v7 model: Drop the device.vpn_address property
thgreasi Jul 20, 2024
33c9a23
v7 model: Drop the device.is_managed_by__device, manages__device prop…
thgreasi Jul 20, 2024
3934ae2
v7 model: Replace device.should_be_managed_by__supervisor_release wit…
thgreasi Jul 20, 2024
be246f9
v7 model: Drop the supervisor_release resource
thgreasi Jul 20, 2024
95f3246
v7 model: Add the device.should_be_operated_by__release property
thgreasi Jul 20, 2024
2aac675
v7 model: Replace the device.should_be_running__release with is_pinne…
thgreasi Jul 20, 2024
4f89e4e
v7 model: Replace the release.should_be_running_on__device with is_pi…
thgreasi Jul 20, 2024
f307204
v7 model: Change user, application & device actor, to return a deferr…
thgreasi Jul 20, 2024
39585b6
v7 model: Replace device.overall_status offline & idle with disconnec…
thgreasi Jul 20, 2024
3dbd301
v7 model: Change image.image_size to string | null
thgreasi Aug 28, 2024
bd08111
tests: Add missing $selects to make the queries faster
thgreasi Jul 21, 2024
1b31fcb
Lint & type fixes & improvements
thgreasi Jul 18, 2024
03f564b
Regenerate the DOCUMENTATION.md
thgreasi Jul 20, 2024
402d514
tests: Simplify the release.createFromUrl() test cleanup
thgreasi Aug 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ node_modules
.idea

# Ignore all build output
es2015
es2018
es20*

# Ignore package-lock.json, since our end users will
package-lock.json
75 changes: 35 additions & 40 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ const sdk = fromSharedOptions();
* [.getDirectlyAccessible(slugOrUuidOrId, [options])](#balena.models.application.getDirectlyAccessible) ⇒ <code>Promise</code>
* [.getWithDeviceServiceDetails(slugOrUuidOrId, [options])](#balena.models.application.getWithDeviceServiceDetails) ⇒ <code>Promise</code>
* [.getAppByName(appName, [options], [context])](#balena.models.application.getAppByName) ⇒ <code>Promise</code>
* ~~[.getAppByOwner(appName, owner, [options])](#balena.models.application.getAppByOwner) ⇒ <code>Promise</code>~~
* [.has(slugOrUuidOrId)](#balena.models.application.has) ⇒ <code>Promise</code>
* [.hasAny()](#balena.models.application.hasAny) ⇒ <code>Promise</code>
* [.create(options)](#balena.models.application.create) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -370,7 +369,7 @@ const sdk = fromSharedOptions();
* [.isSupportedOsUpdate(deviceType, currentVersion, targetVersion)](#balena.models.os.isSupportedOsUpdate) ⇒ <code>Promise</code>
* [.getSupportedOsUpdateVersions(deviceType, currentVersion, [options])](#balena.models.os.getSupportedOsUpdateVersions) ⇒ <code>Promise</code>
* [.isArchitectureCompatibleWith(osArchitecture, applicationArchitecture)](#balena.models.os.isArchitectureCompatibleWith) ⇒ <code>Boolean</code>
* [.getSupervisorImageForDeviceType(deviceTypeId, version)](#balena.models.os.getSupervisorImageForDeviceType) ⇒ <code>Promise.&lt;String&gt;</code>
* [.getSupervisorReleasesForCpuArchitecture(cpuArchitectureSlugOrId, [options])](#balena.models.os.getSupervisorReleasesForCpuArchitecture) ⇒ <code>Promise.&lt;String&gt;</code>
* [.config](#balena.models.config) : <code>object</code>
* [.getAll()](#balena.models.config.getAll) ⇒ <code>Promise</code>
* ~~[.getDeviceTypes()](#balena.models.config.getDeviceTypes) ⇒ <code>Promise</code>~~
Expand Down Expand Up @@ -615,7 +614,6 @@ balena.models.device.get(123).catch(function (error) {
* [.getDirectlyAccessible(slugOrUuidOrId, [options])](#balena.models.application.getDirectlyAccessible) ⇒ <code>Promise</code>
* [.getWithDeviceServiceDetails(slugOrUuidOrId, [options])](#balena.models.application.getWithDeviceServiceDetails) ⇒ <code>Promise</code>
* [.getAppByName(appName, [options], [context])](#balena.models.application.getAppByName) ⇒ <code>Promise</code>
* ~~[.getAppByOwner(appName, owner, [options])](#balena.models.application.getAppByOwner) ⇒ <code>Promise</code>~~
* [.has(slugOrUuidOrId)](#balena.models.application.has) ⇒ <code>Promise</code>
* [.hasAny()](#balena.models.application.hasAny) ⇒ <code>Promise</code>
* [.create(options)](#balena.models.application.create) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -778,7 +776,7 @@ balena.models.device.get(123).catch(function (error) {
* [.isSupportedOsUpdate(deviceType, currentVersion, targetVersion)](#balena.models.os.isSupportedOsUpdate) ⇒ <code>Promise</code>
* [.getSupportedOsUpdateVersions(deviceType, currentVersion, [options])](#balena.models.os.getSupportedOsUpdateVersions) ⇒ <code>Promise</code>
* [.isArchitectureCompatibleWith(osArchitecture, applicationArchitecture)](#balena.models.os.isArchitectureCompatibleWith) ⇒ <code>Boolean</code>
* [.getSupervisorImageForDeviceType(deviceTypeId, version)](#balena.models.os.getSupervisorImageForDeviceType) ⇒ <code>Promise.&lt;String&gt;</code>
* [.getSupervisorReleasesForCpuArchitecture(cpuArchitectureSlugOrId, [options])](#balena.models.os.getSupervisorReleasesForCpuArchitecture) ⇒ <code>Promise.&lt;String&gt;</code>
* [.config](#balena.models.config) : <code>object</code>
* [.getAll()](#balena.models.config.getAll) ⇒ <code>Promise</code>
* ~~[.getDeviceTypes()](#balena.models.config.getDeviceTypes) ⇒ <code>Promise</code>~~
Expand Down Expand Up @@ -871,7 +869,6 @@ balena.models.device.get(123).catch(function (error) {
* [.getDirectlyAccessible(slugOrUuidOrId, [options])](#balena.models.application.getDirectlyAccessible) ⇒ <code>Promise</code>
* [.getWithDeviceServiceDetails(slugOrUuidOrId, [options])](#balena.models.application.getWithDeviceServiceDetails) ⇒ <code>Promise</code>
* [.getAppByName(appName, [options], [context])](#balena.models.application.getAppByName) ⇒ <code>Promise</code>
* ~~[.getAppByOwner(appName, owner, [options])](#balena.models.application.getAppByOwner) ⇒ <code>Promise</code>~~
* [.has(slugOrUuidOrId)](#balena.models.application.has) ⇒ <code>Promise</code>
* [.hasAny()](#balena.models.application.hasAny) ⇒ <code>Promise</code>
* [.create(options)](#balena.models.application.create) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -1758,28 +1755,6 @@ balena.models.application.getAppByName('MyApp').then(function(application) {
console.log(application);
});
```
<a name="balena.models.application.getAppByOwner"></a>

##### ~~application.getAppByOwner(appName, owner, [options]) ⇒ <code>Promise</code>~~
***Deprecated***

**Kind**: static method of [<code>application</code>](#balena.models.application)
**Summary**: Get a single application using the appname and the handle of the owning organization
**Access**: public
**Fulfil**: <code>Object</code> - application

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| appName | <code>String</code> | | application name |
| owner | <code>String</code> | | The handle of the owning organization |
| [options] | <code>Object</code> | <code>{}</code> | extra pine options to use |

**Example**
```js
balena.models.application.getAppByOwner('myorganization/myapp', 'MyOrg').then(function(application) {
console.log(application);
});
```
<a name="balena.models.application.has"></a>

##### application.has(slugOrUuidOrId) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -1830,10 +1805,8 @@ balena.models.application.hasAny().then(function(hasAny) {
| options | <code>Object</code> | application creation parameters |
| options.name | <code>String</code> | application name |
| [options.uuid] | <code>String</code> | application uuid |
| [options.applicationType] | <code>String</code> | application type slug e.g. microservices |
| [options.applicationClass] | <code>String</code> | application class: 'app' | 'fleet' | 'block' |
| options.deviceType | <code>String</code> | device type slug |
| [options.parent] | <code>Number</code> \| <code>String</code> | parent application name or id |
| options.organization | <code>String</code> \| <code>Number</code> | handle (string) or id (number) of the organization that the application will belong to or null |

**Example**
Expand Down Expand Up @@ -5286,7 +5259,7 @@ balena.models.organization.remove(123);
* [.isSupportedOsUpdate(deviceType, currentVersion, targetVersion)](#balena.models.os.isSupportedOsUpdate) ⇒ <code>Promise</code>
* [.getSupportedOsUpdateVersions(deviceType, currentVersion, [options])](#balena.models.os.getSupportedOsUpdateVersions) ⇒ <code>Promise</code>
* [.isArchitectureCompatibleWith(osArchitecture, applicationArchitecture)](#balena.models.os.isArchitectureCompatibleWith) ⇒ <code>Boolean</code>
* [.getSupervisorImageForDeviceType(deviceTypeId, version)](#balena.models.os.getSupervisorImageForDeviceType) ⇒ <code>Promise.&lt;String&gt;</code>
* [.getSupervisorReleasesForCpuArchitecture(cpuArchitectureSlugOrId, [options])](#balena.models.os.getSupervisorReleasesForCpuArchitecture) ⇒ <code>Promise.&lt;String&gt;</code>

<a name="balena.models.os.getAvailableOsVersions"></a>

Expand Down Expand Up @@ -5539,23 +5512,45 @@ console.log(result1);
const result2 = balena.models.os.isArchitectureCompatibleWith('armv7hf', 'amd64');
console.log(result2);
```
<a name="balena.models.os.getSupervisorImageForDeviceType"></a>
<a name="balena.models.os.getSupervisorReleasesForCpuArchitecture"></a>

##### os.getSupervisorImageForDeviceType(deviceTypeId, version) ⇒ <code>Promise.&lt;String&gt;</code>
##### os.getSupervisorReleasesForCpuArchitecture(cpuArchitectureSlugOrId, [options]) ⇒ <code>Promise.&lt;String&gt;</code>
**Kind**: static method of [<code>os</code>](#balena.models.os)
**Summary**: Returns image name for a specific supervisor version for a Device Type
**Returns**: <code>Promise.&lt;String&gt;</code> - - Docker image name for the Supervisor version and arch
**Summary**: Returns the Releases of the supervisor for the CPU Architecture
**Returns**: <code>Promise.&lt;String&gt;</code> - - An array of Release objects that can be used to manage a device as supervisors.
**Access**: public

| Param | Type | Description |
| --- | --- | --- |
| deviceTypeId | <code>Number</code> | The Id for the Device Type |
| version | <code>String</code> | The semver version string for the supervisor |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| cpuArchitectureSlugOrId | <code>String</code> \| <code>Number</code> | | The slug (string) or id (number) for the CPU Architecture |
| [options] | <code>Object</code> | <code>{}</code> | extra pine options to use |

**Example**
```js
const result = balena.models.os.getSupervisorImageForDT(60, 'v12.11.0').then(result => console.log(result))
// 60 would be raspberrypi4-64 on balena-cloud
const results = balena.models.os.getSupervisorReleasesForCpuArchitecture('aarch64');

const [result] = balena.models.os.getSupervisorReleasesForCpuArchitecture(
'aarch64',
{ $filter: { raw_version: '12.11.0' } },
);

const [result] = balena.models.os.getSupervisorReleasesForCpuArchitecture(
'aarch64',
{
$select: ['id', 'raw_version', 'known_issue_list', 'created_at', 'contract'],
$expand: {
release_image: {
$select: 'id',
$expand: {
image: {
$select: 'is_stored_at__image_location',
},
},
},
},
$filter: { raw_version: '12.11.0' }
},
);
```
<a name="balena.models.config"></a>

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The following features are node-only:
- OS image streaming download (`balena.models.os.download`),
- balena settings client (`balena.settings`).

In Node you can simply `require('balena-sdk')`, but in the browser things are more complicated. The balena SDK provides a bundled single file for browsers, which allows you to include a single file with all dependencies included, available as [balena-browser.min.js](https://unpkg.com/balena-sdk/es2015/balena-browser.min.js). This uses the [UMD format](https://github.com/umdjs/umd), and will register itself as either a CommonJS or AMD module called `balena-sdk` if possible, or create a `balenaSdk` global if not. You can also use the `es2018` version if desired.
In Node you can simply `require('balena-sdk')`, but in the browser things are more complicated. The balena SDK provides a bundled single file for browsers, which allows you to include a single file with all dependencies included, available as [balena-browser.min.js](https://unpkg.com/balena-sdk/es2017/balena-browser.min.js). This uses the [UMD format](https://github.com/umdjs/umd), and will register itself as either a CommonJS or AMD module called `balena-sdk` if possible, or create a `balenaSdk` global if not. You can also use the `es2018` version if desired.

### Bundling for browsers

Expand Down Expand Up @@ -171,7 +171,7 @@ Before submitting a PR, please make sure that you
* ran the lint script on the modified files

```
$ npm run lint:fix
$ npm run lint-fix
```

* include tests and that they pass
Expand Down
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const packageJSON = require('./package.json');

const cliOptions = minimist(process.argv.slice(2), {
string: 'buildDir', // eslint-disable-line id-denylist
default: { buildDir: 'es2015' },
default: { buildDir: 'es2017' },
});

const OPTIONS = {
Expand Down
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: Drop this file once TS supports `export as namespace` in plain .ts files
// See: https://github.com/microsoft/TypeScript/issues/10907
export * from './es2015';
export * from './es2017';
// As generated by browserify
export as namespace balenaSdk;
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var esVersion = require('@balena/es-version').get(['es2015', 'es2018']);
var sdkBuild = require('./' + esVersion);
/* eslint-disable @typescript-eslint/no-var-requires */
const esVersion = require('@balena/es-version').get(['es2017', 'es2018']);
const sdkBuild = require('./' + esVersion);
module.exports = sdkBuild;
// The following explicit assignments enable named imports in mjs files.
module.exports.getSdk = sdkBuild.getSdk;
Expand Down
5 changes: 3 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const _ = require('lodash');
const getKarmaConfig = require('balena-config-karma');
const packageJSON = require('./package.json');

const BROWSER_BUNDLE = 'es2015/balena-browser.min.js';
const BROWSER_BUNDLE = 'es2017/balena-browser.min.js';

module.exports = function (config) {
require('dotenv').config();
Expand Down Expand Up @@ -63,7 +64,7 @@ module.exports = function (config) {
// do not pre-process the browser build
karmaConfig.preprocessors = _.omitBy(
karmaConfig.preprocessors,
(_value, key) => key.startsWith('es2015/') || key.startsWith('es2018/'),
(_value, key) => key.startsWith('es2017/') || key.startsWith('es2018/'),
);
karmaConfig.client = {
mocha: {
Expand Down
4 changes: 2 additions & 2 deletions mjs_tests/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ describe('mjs imports', function () {
describe(`${titlePart} imports`, function () {
it('should include all exported methods', async function () {
const sdkExports = await loader();
const es2015Build = await import('../es2015/index.js');
Object.keys(es2015Build)
const es2017Build = await import('../es2017/index.js');
Object.keys(es2017Build)
.filter(
(exportedKey) =>
exportedKey !== 'default' && !exportedKey.startsWith('__'),
Expand Down
25 changes: 12 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"main": "index.js",
"types": "index.d.ts",
"browser": {
"index.js": "./es2015/index.js",
"es2015/util/settings-client.js": "./es2015/util/settings-client.browser.js",
"index.js": "./es2017/index.js",
"es2017/util/settings-client.js": "./es2017/util/settings-client.browser.js",
"es2018/util/settings-client.js": "./es2018/util/settings-client.browser.js",
"handlebars": "handlebars/dist/cjs/handlebars.js"
},
Expand All @@ -16,7 +16,7 @@
"url": "git://github.com/balena-io/balena-sdk.git"
},
"files": [
"es2015/",
"es2017/",
"es2018/",
"typings/",
"index.js",
Expand All @@ -35,25 +35,24 @@
"test": "tests"
},
"scripts": {
"clean": "rimraf es2015 es2018",
"test:fast": "npm run lint:fix; npm run build-es2015:fast && npm run test:node",
"clean": "rimraf es2017 es2018",
"test:fast": "npm run lint-fix; npm run build-es2017:fast && npm run test:node",
"test": "([ \"$GITHUB_WORKFLOW\" = 'Flowzone' ] && [ \"$GITHUB_JOB\" = 'npm_test' ] && echo \"Skipping 'npm test' in flowzone in favor of the custom test action!\") || (npm run build && npm run test:all)",
"test:all": "npm run test:ts-compatibility && npm run test:dev && npm run test:ts-js && npm run test:typings && npm run test:mjs-imports && npm run test:node && npm run test:browser",
"test:all": "npm run test:dev && npm run test:ts-js && npm run test:typings && npm run test:mjs-imports && npm run test:node && npm run test:browser",
"test:node": "gulp test",
"test:browser": "mockttp -c karma start",
"test:dev": "tsc --noEmit --project ./tsconfig.dev.json",
"test:ts-js": "tsc --noEmit --project ./tsconfig.js.json",
"test:ts-compatibility": "npx -p typescript@~5.0.2 tsc --noEmit --project ./tsconfig.dist.json",
"test:typings": "tsc --project ./typing_tests/tsconfig.json",
"test:mjs-imports": "node mjs_tests/index.mjs",
"build-es2015:fast": "rimraf es2015 && tsc --target es2015 --outDir es2015 && gulp inject-version --buildDir es2015",
"build-es2015": "npm run build-es2015:fast && gulp pack-browser --buildDir es2015",
"build-es2017:fast": "rimraf es2017 && tsc --target es2017 --outDir es2017 && gulp inject-version --buildDir es2017",
"build-es2017": "npm run build-es2017:fast && gulp pack-browser --buildDir es2017",
"build-es2018": "rimraf es2018 && tsc --target es2018 --outDir es2018 && gulp inject-version --buildDir es2018 && gulp pack-browser --buildDir es2018",
"build": "npm run lint && npm run build-es2015 && npm run build-es2018 && npm run docs",
"docs": "jsdoc2md --template doc/DOCUMENTATION.hbs --files \"es2015/**/!(balena-browser*.js)\" > DOCUMENTATION.md",
"build": "npm run lint && npm run build-es2017 && npm run build-es2018 && npm run docs",
"docs": "jsdoc2md --template doc/DOCUMENTATION.hbs --files \"es2017/**/!(balena-browser*.js)\" > DOCUMENTATION.md",
"ci": "npm test && catch-uncommitted",
"lint": "balena-lint -e js -e ts typing_tests typings src tests mjs_tests gulpfile.js",
"lint:fix": "balena-lint -e js -e ts --fix typing_tests typings src tests mjs_tests gulpfile.js",
"lint-fix": "balena-lint -e js -e ts --fix typing_tests typings src tests mjs_tests gulpfile.js",
"prepack": "npm run build",
"watch": "npm run build && watch \"npm run lint\" \"src\" \"tests\"",
"prepare": "husky install"
Expand Down Expand Up @@ -136,7 +135,7 @@
"mime": "^3.0.0",
"ndjson": "^2.0.0",
"p-throttle": "^4.1.1",
"pinejs-client-core": "~6.14.0",
"pinejs-client-core": "^6.15.0",
"tslib": "^2.1.0"
},
"versionist": {
Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ export type {
OsTypes,
OsUpdateVersions,
OsVersion,
OsVersionsByDeviceType,
} from './models/os';
export type { OsUpdateActionResult } from './util/device-actions/os-update';
export type { BuilderUrlDeployOptions } from './util/builder';
Expand Down Expand Up @@ -217,7 +216,7 @@ export const getSdk = function ($opts?: SdkOptions) {
isBrowser: typeof window !== 'undefined' && window !== null,
// API version is configurable but only do so if you know what you're doing,
// as the SDK is directly tied to a specific version.
apiVersion: 'v6',
apiVersion: 'v7',
...$opts,
};

Expand Down
4 changes: 2 additions & 2 deletions src/models/api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const getApiKeysModel = function (
mergePineOptions(
{
$filter: {
is_of__actor: actor,
is_of__actor: actor.__id,
},
},
options,
Expand Down Expand Up @@ -227,7 +227,7 @@ const getApiKeysModel = function (
options: mergePineOptions(
{
$filter: {
is_of__actor: actor,
is_of__actor: actor.__id,
},
$orderby: 'name asc',
},
Expand Down
Loading
Loading