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
54cf8aa
Drop deprecated method `application.generateApiKey` necessary to prov…
myarmolinsky Nov 26, 2024
9f141a0
Drop deprecated property `pubnub` from `Config`
myarmolinsky Nov 26, 2024
80137c7
Drop deprecated property `instructions` from `DeviceType`
myarmolinsky Nov 26, 2024
0b30c4b
Drop deprecated property `supports_blink` from `DeviceType`
myarmolinsky Nov 26, 2024
e9c0f8b
Drop deprecated method `device.getApplicationInfo`
myarmolinsky Nov 27, 2024
8c47416
Drop deprecated method `device.getOsUpdateStatus`
myarmolinsky Nov 27, 2024
3b79367
Drop deprecated property `isRecommended` from `OsVersion`
myarmolinsky Nov 27, 2024
e5bd42f
Drop deprecated property `logo_url` from `DeviceType`
myarmolinsky Nov 27, 2024
1f594e8
Drop all deprecated properties from `JWTUser`
myarmolinsky Nov 27, 2024
c22e96d
Drop deprecated property `supports_gateway_mode` from `ApplicationType`
myarmolinsky Nov 27, 2024
1f4b93f
Drop deprecated property `release_version` from `Release`
myarmolinsky Nov 27, 2024
d633d90
Drop deprecated property `contains__image` from `Release`
myarmolinsky Nov 27, 2024
8c2067b
Drop deprecated method `device.startApplication`
myarmolinsky Nov 27, 2024
ad093d0
Drop deprecated method `device.stopApplication`
myarmolinsky Nov 27, 2024
1678575
Drop deprecated property `image` from `ImageInstall`
myarmolinsky Nov 27, 2024
527bdf8
Drop support for OS versions <= 2.14.0
myarmolinsky Nov 27, 2024
98c318e
Drop `Unknown pine option` errors in favor of TS and pinejs-client th…
myarmolinsky Nov 27, 2024
6e4f10e
`image.get`: No longer pass base options
myarmolinsky Nov 27, 2024
41001b5
`mergePineOptions`: Drop `replace$select` parameter
myarmolinsky Nov 27, 2024
2adc139
`startOsUpdate`: Set `runDetached` to `true` by default
myarmolinsky Nov 27, 2024
b67f9dd
`ConfigVarSchema`: Update typing to use `JSONSchema7` instead of `JSO…
myarmolinsky Nov 27, 2024
553887b
Update minimum required node version to 20.12.0
myarmolinsky Nov 27, 2024
4dc0bc3
`apiKey.create`: Change parameters to an object and require `expiryDate`
myarmolinsky Nov 27, 2024
49fdbea
Stop silencing Not Found errors for devices, applications, and organi…
myarmolinsky Nov 27, 2024
d4a5440
`application.generateProvisioningKey`: Change parameters to an object…
myarmolinsky Dec 3, 2024
a0a55a9
`application.generateProvisioningKey`: Switch to v2 endpoint
myarmolinsky Dec 16, 2024
ab8057a
Drop `os.getLastModified` as it has not worked for a while and is unused
myarmolinsky Dec 3, 2024
446dda8
Drop deprecated method `organization-membership.create` in favor of `…
myarmolinsky Dec 10, 2024
fe132ed
`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