balena-sdk 16.9.1 → 16.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/DOCUMENTATION.md +1 -1
- package/README.md +0 -1
- package/es2015/balena-browser.js +145 -118
- package/es2015/balena-browser.min.js +1 -1
- package/es2015/index.d.ts +6 -5
- package/es2015/index.js +3 -3
- package/es2015/pine.d.ts +22 -0
- package/es2015/pine.js +68 -0
- package/es2015/util/sdk-version.js +1 -1
- package/es2018/balena-browser.js +150 -118
- package/es2018/balena-browser.min.js +1 -1
- package/es2018/index.d.ts +6 -5
- package/es2018/index.js +3 -3
- package/es2018/pine.d.ts +22 -0
- package/es2018/pine.js +73 -0
- package/es2018/util/sdk-version.js +1 -1
- package/package.json +6 -4
- package/typings/pinejs-client-core.d.ts +1 -0
- package/typings/balena-pine.d.ts +0 -9
package/es2018/index.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/// <reference types="memoizee" />
|
|
2
|
-
import type { Pine
|
|
2
|
+
import type { Pine } from './pine';
|
|
3
3
|
import type { BalenaRequest, Interceptor } from 'balena-request';
|
|
4
|
-
|
|
5
|
-
export declare type Pine = PineBase<ResourceTypeMap>;
|
|
6
|
-
export declare type PineStrict = PineStrictBase<ResourceTypeMap>;
|
|
4
|
+
export type { Pine, PineStrict } from './pine';
|
|
7
5
|
export * from './types/models';
|
|
8
6
|
export * from './types/jwt';
|
|
9
7
|
export * from './types/contract';
|
|
@@ -404,7 +402,10 @@ declare const sdkTemplate: {
|
|
|
404
402
|
getAllByService: (parentParam: string | number, options?: import("../typings/pinejs-client-core").ODataOptions<import("./types/models").ServiceEnvironmentVariable> | undefined) => Promise<import("./types/models").ServiceEnvironmentVariable[]>;
|
|
405
403
|
getAllByApplication(slugOrId: string | number, options?: import("../typings/pinejs-client-core").ODataOptions<import("./types/models").ServiceEnvironmentVariable>): Promise<import("./types/models").ServiceEnvironmentVariable[]>;
|
|
406
404
|
get: (parentParam: string | number, key: string) => Promise<string | undefined>;
|
|
407
|
-
set: (parentParam: string | number, key: string, value: string) => Promise<void>;
|
|
405
|
+
set: (parentParam: string | number, key: string, value: string) => Promise<void>; /**
|
|
406
|
+
* @namespace settings
|
|
407
|
+
* @memberof balena
|
|
408
|
+
*/
|
|
408
409
|
remove: (parentParam: string | number, key: string) => Promise<void>;
|
|
409
410
|
};
|
|
410
411
|
};
|
package/es2018/index.js
CHANGED
|
@@ -84,7 +84,7 @@ const getSdk = function ($opts) {
|
|
|
84
84
|
const { getRequest } = require('balena-request');
|
|
85
85
|
const BalenaAuth = require('balena-auth')
|
|
86
86
|
.default;
|
|
87
|
-
const {
|
|
87
|
+
const { createPinejsClient } = require('./pine');
|
|
88
88
|
const errors = require('balena-errors');
|
|
89
89
|
const { PubSub } = require('./util/pubsub');
|
|
90
90
|
/**
|
|
@@ -126,7 +126,7 @@ const getSdk = function ($opts) {
|
|
|
126
126
|
}
|
|
127
127
|
const auth = new BalenaAuth(opts);
|
|
128
128
|
const request = getRequest({ ...opts, auth });
|
|
129
|
-
const pine =
|
|
129
|
+
const pine = createPinejsClient({}, { ...opts, auth, request });
|
|
130
130
|
const pubsub = new PubSub();
|
|
131
131
|
const sdk = {};
|
|
132
132
|
const deps = {
|
|
@@ -244,7 +244,7 @@ const getSdk = function ($opts) {
|
|
|
244
244
|
* @memberof balena
|
|
245
245
|
*
|
|
246
246
|
* @description
|
|
247
|
-
* The
|
|
247
|
+
* The pinejs-client instance used internally. This should not be necessary
|
|
248
248
|
* in normal usage, but can be useful if you want to directly make pine
|
|
249
249
|
* queries to the api for some resource that isn't directly supported
|
|
250
250
|
* in the SDK.
|
package/es2018/pine.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AnyObject, Params } from 'pinejs-client-core';
|
|
2
|
+
import type * as PineClient from '../typings/pinejs-client-core';
|
|
3
|
+
import type { ResourceTypeMap } from './types/models';
|
|
4
|
+
interface BackendParams {
|
|
5
|
+
apiUrl: string;
|
|
6
|
+
apiVersion: string;
|
|
7
|
+
apiKey?: string;
|
|
8
|
+
request: {
|
|
9
|
+
send: (options: AnyObject) => Promise<{
|
|
10
|
+
body: any;
|
|
11
|
+
}>;
|
|
12
|
+
};
|
|
13
|
+
auth: import('balena-auth').default;
|
|
14
|
+
}
|
|
15
|
+
export declare type Pine = PineClient.Pine<ResourceTypeMap>;
|
|
16
|
+
/**
|
|
17
|
+
* A variant that makes $select mandatory, helping to create
|
|
18
|
+
* requests that explicitly fetch only what your code needs.
|
|
19
|
+
*/
|
|
20
|
+
export declare type PineStrict = PineClient.PineStrict<ResourceTypeMap>;
|
|
21
|
+
export declare const createPinejsClient: (params: Params, backendParams: BackendParams) => Pine;
|
|
22
|
+
export {};
|
package/es2018/pine.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPinejsClient = void 0;
|
|
4
|
+
const url = require("url");
|
|
5
|
+
const errors = require("balena-errors");
|
|
6
|
+
const pinejs_client_core_1 = require("pinejs-client-core");
|
|
7
|
+
/**
|
|
8
|
+
* @class
|
|
9
|
+
* @classdesc A PineJS Client subclass to communicate with balena.
|
|
10
|
+
* @private
|
|
11
|
+
*
|
|
12
|
+
* @description
|
|
13
|
+
* This subclass makes use of the [balena-request](https://github.com/balena-io-modules/balena-request) project.
|
|
14
|
+
*/
|
|
15
|
+
class PinejsClient extends pinejs_client_core_1.PinejsClientCore {
|
|
16
|
+
constructor(params, backendParams) {
|
|
17
|
+
super({
|
|
18
|
+
...params,
|
|
19
|
+
apiPrefix: url.resolve(backendParams.apiUrl, `/${backendParams.apiVersion}/`),
|
|
20
|
+
});
|
|
21
|
+
this.backendParams = backendParams;
|
|
22
|
+
this.backendParams = backendParams;
|
|
23
|
+
this.API_URL = backendParams.apiUrl;
|
|
24
|
+
this.API_VERSION = backendParams.apiVersion;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @summary Perform a network request to balena.
|
|
28
|
+
* @method
|
|
29
|
+
* @private
|
|
30
|
+
*
|
|
31
|
+
* @param {Object} options - request options
|
|
32
|
+
* @returns {Promise<*>} response body
|
|
33
|
+
*
|
|
34
|
+
* @todo Implement caching support.
|
|
35
|
+
*/
|
|
36
|
+
async _request(options) {
|
|
37
|
+
const { apiKey, apiUrl, auth, request } = this.backendParams;
|
|
38
|
+
const hasKey = await auth.hasKey();
|
|
39
|
+
const authenticated = hasKey || (apiKey != null && apiKey.length > 0);
|
|
40
|
+
options = {
|
|
41
|
+
apiKey,
|
|
42
|
+
baseUrl: apiUrl,
|
|
43
|
+
sendToken: authenticated && !options.anonymous,
|
|
44
|
+
...options,
|
|
45
|
+
};
|
|
46
|
+
try {
|
|
47
|
+
const { body } = await request.send(options);
|
|
48
|
+
return body;
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if (err.statusCode !== 401) {
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
// Always return the API error when the anonymous flag is used.
|
|
55
|
+
if (options.anonymous) {
|
|
56
|
+
throw err;
|
|
57
|
+
}
|
|
58
|
+
// We want to allow unauthenticated users to make requests
|
|
59
|
+
// to public resources, but still reject with a NotLoggedIn
|
|
60
|
+
// error if the response ends up being a 401.
|
|
61
|
+
if (!authenticated) {
|
|
62
|
+
throw new errors.BalenaNotLoggedIn();
|
|
63
|
+
}
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const createPinejsClient = (...args) => {
|
|
69
|
+
const pine = new PinejsClient(...args);
|
|
70
|
+
// @ts-expect-error
|
|
71
|
+
return pine;
|
|
72
|
+
};
|
|
73
|
+
exports.createPinejsClient = createPinejsClient;
|
|
@@ -6,5 +6,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
// being embedded in the dist of the consumer project
|
|
7
7
|
// which we want to avoid, both b/c of the dist size increase &
|
|
8
8
|
// the security concerns of including the versions of the dependencies
|
|
9
|
-
const sdkVersion = '16.9.
|
|
9
|
+
const sdkVersion = '16.9.2';
|
|
10
10
|
exports.default = sdkVersion;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "balena-sdk",
|
|
3
|
-
"version": "16.9.
|
|
3
|
+
"version": "16.9.2",
|
|
4
4
|
"description": "The Balena JavaScript SDK",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"test": "npm run build && npm run test:all",
|
|
37
37
|
"test:all": "npm run test:ts-compatibility && npm run test:dev && npm run test:ts-js && npm run test:typings && npm run test:node && npm run test:browser",
|
|
38
38
|
"test:node": "gulp test",
|
|
39
|
-
"test:browser": "karma start",
|
|
39
|
+
"test:browser": "mockttp -c karma start",
|
|
40
40
|
"test:dev": "tsc --noEmit --project ./tsconfig.dev.json",
|
|
41
41
|
"test:ts-js": "tsc --noEmit --project ./tsconfig.js.json",
|
|
42
42
|
"test:ts-compatibility": "npx typescript@~4.5.2 --noEmit --project ./tsconfig.dist.json",
|
|
@@ -83,10 +83,12 @@
|
|
|
83
83
|
"lint-staged": "^10.5.4",
|
|
84
84
|
"mocha": "^3.5.3",
|
|
85
85
|
"mocha.parallel": "^0.15.6",
|
|
86
|
+
"mockttp": "^0.9.1",
|
|
86
87
|
"rimraf": "^3.0.2",
|
|
87
88
|
"rindle": "^1.3.6",
|
|
88
89
|
"sinon": "^12.0.1",
|
|
89
90
|
"superagent": "^3.8.3",
|
|
91
|
+
"temp": "^0.8.4",
|
|
90
92
|
"tmp": "^0.0.31",
|
|
91
93
|
"ts-node": "^7.0.1",
|
|
92
94
|
"ts-toolbelt": "^6.15.5",
|
|
@@ -106,7 +108,6 @@
|
|
|
106
108
|
"balena-auth": "^4.1.0",
|
|
107
109
|
"balena-errors": "^4.7.1",
|
|
108
110
|
"balena-hup-action-utils": "~4.1.0",
|
|
109
|
-
"balena-pine": "^12.4.0",
|
|
110
111
|
"balena-register-device": "^7.1.0",
|
|
111
112
|
"balena-request": "^11.5.0",
|
|
112
113
|
"balena-semver": "^2.3.0",
|
|
@@ -115,9 +116,10 @@
|
|
|
115
116
|
"memoizee": "^0.4.15",
|
|
116
117
|
"moment": "^2.29.1",
|
|
117
118
|
"ndjson": "^2.0.0",
|
|
119
|
+
"pinejs-client-core": "^6.9.6",
|
|
118
120
|
"tslib": "^2.1.0"
|
|
119
121
|
},
|
|
120
122
|
"versionist": {
|
|
121
|
-
"publishedAt": "2021-12-
|
|
123
|
+
"publishedAt": "2021-12-28T17:20:53.079Z"
|
|
122
124
|
}
|
|
123
125
|
}
|
|
@@ -455,6 +455,7 @@ export interface SubscribeParamsWithId<T> extends ParamsObjWithId<T> {
|
|
|
455
455
|
}
|
|
456
456
|
|
|
457
457
|
export interface Pine<ResourceTypeMap extends {} = {}> {
|
|
458
|
+
apiPrefix: string;
|
|
458
459
|
delete<T>(params: ParamsObjWithId<T> | ParamsObjWithFilter<T>): Promise<'OK'>;
|
|
459
460
|
// Fully typed result overloads
|
|
460
461
|
get<
|
package/typings/balena-pine.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type * as PineClient from './pinejs-client-core';
|
|
2
|
-
|
|
3
|
-
export type Pine<ResourceTypeMap> = PineClient.Pine<ResourceTypeMap>;
|
|
4
|
-
/**
|
|
5
|
-
* A variant that makes $select mandatory, helping to create
|
|
6
|
-
* requests that explicitly fetch only what your code needs.
|
|
7
|
-
*/
|
|
8
|
-
export type PineStrict<ResourceTypeMap> =
|
|
9
|
-
PineClient.PineStrict<ResourceTypeMap>;
|