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

Major v21 #1505

Draft
wants to merge 29 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c60d036
Drop deprecated method `application.generateApiKey` necessary to prov…
myarmolinsky Nov 26, 2024
1bbfc96
Drop deprecated property `pubnub` from `Config`
myarmolinsky Nov 26, 2024
8b9b1d2
Drop deprecated property `instructions` from `DeviceType`
myarmolinsky Nov 26, 2024
00a138b
Drop deprecated property `supports_blink` from `DeviceType`
myarmolinsky Nov 26, 2024
ee35a3e
Drop deprecated method `device.getApplicationInfo`
myarmolinsky Nov 27, 2024
f3e751c
Drop deprecated method `device.getOsUpdateStatus`
myarmolinsky Nov 27, 2024
9026bbc
Drop deprecated property `isRecommended` from `OsVersion`
myarmolinsky Nov 27, 2024
cec6fc4
Drop deprecated property `logo_url` from `DeviceType`
myarmolinsky Nov 27, 2024
9a2295d
Drop all deprecated properties from `JWTUser`
myarmolinsky Nov 27, 2024
0f5b4d2
Drop deprecated property `supports_gateway_mode` from `ApplicationType`
myarmolinsky Nov 27, 2024
9b24ba5
Drop deprecated property `release_version` from `Release`
myarmolinsky Nov 27, 2024
7b654d4
Drop deprecated property `contains__image` from `Release`
myarmolinsky Nov 27, 2024
b3dfa8a
Drop deprecated method `device.startApplication`
myarmolinsky Nov 27, 2024
e8cd125
Drop deprecated method `device.stopApplication`
myarmolinsky Nov 27, 2024
d22ce09
Drop deprecated property `image` from `ImageInstall`
myarmolinsky Nov 27, 2024
ea80ea6
Drop support for OS versions <= 2.14.0
myarmolinsky Nov 27, 2024
109f152
Drop `Unknown pine option` errors in favor of TS and pinejs-client th…
myarmolinsky Nov 27, 2024
878122f
`image.get`: No longer pass base options
myarmolinsky Nov 27, 2024
cfa4f82
`mergePineOptions`: Drop `replace$select` parameter
myarmolinsky Nov 27, 2024
e4f8a94
`startOsUpdate`: Set `runDetached` to `true` by default
myarmolinsky Nov 27, 2024
aaaf7dd
`ConfigVarSchema`: Update typing to use `JSONSchema7` instead of `JSO…
myarmolinsky Nov 27, 2024
819ae1a
Update minimum required node version to 20.12.0
myarmolinsky Nov 27, 2024
e5a195d
`apiKey.create`: Change parameters to an object and require `expiryDate`
myarmolinsky Nov 27, 2024
bdfdc2b
Stop silencing Not Found errors for devices, applications, and organi…
myarmolinsky Nov 27, 2024
4bb08ba
`application.generateProvisioningKey`: Change parameters to an object…
myarmolinsky Dec 3, 2024
97c512e
`application.generateProvisioningKey`: Switch to v2 endpoint
myarmolinsky Dec 16, 2024
adc65c2
Drop `os.getLastModified` as it has not worked for a while and is unused
myarmolinsky Dec 3, 2024
b66896a
Drop deprecated method `organization-membership.create` in favor of `…
myarmolinsky Dec 10, 2024
495e3df
`application-membership.create`: Update description to reflect that t…
myarmolinsky Dec 10, 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
250 changes: 24 additions & 226 deletions DOCUMENTATION.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"author": "Balena Ltd. <[email protected]>",
"license": "Apache-2.0",
"engines": {
"node": ">=18.0"
"node": "^20.12.0 || >= 22.0.0"
},
"devDependencies": {
"@balena/env-parsing": "^1.2.0",
Expand Down Expand Up @@ -119,7 +119,7 @@
"dependencies": {
"@balena/es-version": "^1.0.0",
"@types/json-schema": "^7.0.9",
"@types/node": "^18.19.50",
"@types/node": "^20.17.8",
"abortcontroller-polyfill": "^1.7.1",
"balena-auth": "^6.0.1",
"balena-errors": "^4.9.0",
Expand Down
35 changes: 22 additions & 13 deletions src/models/api-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,49 @@ const getApiKeysModel = function (
*
* @description This method registers a new api key for the current user with the name given.
*
* @param {String} name - the API key name
* @param {String} [description=null] - the API key description
* @param {Object} createApiKeyParams - an object containing the parameters for the creation of an API key
* @param {String} createApiKeyParams.name - the API key name
* @param {String} createApiKeyParams.expiryDate - the API key expiry date
* @param {String} [createApiKeyParams.description=null] - the API key description
*
* @fulfil {String} - API key
* @returns {Promise}
*
* @example
* balena.models.apiKey.create(apiKeyName).then(function(apiKey) {
* balena.models.apiKey.create({name: apiKeyName, expiryDate: 2030-10-12}).then(function(apiKey) {
* console.log(apiKey);
* });
*
* @example
* balena.models.apiKey.create(apiKeyName, apiKeyDescription).then(function(apiKey) {
* balena.models.apiKey.create({name: apiKeyName, expiryDate: 2030-10-12, description: apiKeyDescription}).then(function(apiKey) {
* console.log(apiKey);
* });
*/
async create(
name: string,
description: string | null = null,
expiryDate: string | null = null,
): Promise<string> {
async create({
name,
expiryDate,
description = null,
}: {
name: string;
expiryDate: string | null;
description?: string | null;
}): Promise<string> {
if (typeof expiryDate === 'undefined') {
throw new Error(
'An expiry date must be provided as either an ISO string or null',
);
}
const apiKeyBody: {
name: string;
expiryDate: string | null;
description?: string | null;
expiryDate?: string | null;
} = {
name,
expiryDate,
};
if (typeof description === 'string' && !!description) {
apiKeyBody.description = description;
}
if (typeof expiryDate === 'string' && !!expiryDate) {
apiKeyBody.expiryDate = expiryDate;
}
try {
const { body } = await request.send({
method: 'POST',
Expand Down
18 changes: 16 additions & 2 deletions src/models/application-membership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const getApplicationMembershipModel = function (
* @function
* @memberof balena.models.application.membership
*
* @description This method adds a user to an application by their username.
* @description This method adds a user to an application by their username if they are a member of the organization.
myarmolinsky marked this conversation as resolved.
Show resolved Hide resolved
*
* @param {Object} options - membership creation parameters
* @param {String|Number} options.application - application handle (string), or id (number)
Expand All @@ -248,9 +248,23 @@ const getApplicationMembershipModel = function (
PinePostResult<ApplicationMembership>
> {
const [{ id }, roleId] = await Promise.all([
getApplication(application, { $select: 'id' }),
getApplication(application, {
$select: 'id',
$expand: {
organization: {
$select: 'id',
$filter: { organization_membership: { user: { username } } },
},
},
}),
roleName ? getRoleId(roleName) : undefined,
]);
// If the user does not have an organization membership, they cannot be added to an application
if (!id) {
throw new Error(
'It is necessary that each user (Auth) that is member of an application that has an organization, is member of the organization',
);
}
type ApplicationMembershipBase = Omit<ApplicationMembership, 'user'>;
type ApplicationMembershipPostBody = ApplicationMembershipBase & {
username: string;
Expand Down
Loading
Loading