UNPKG

balena-sdk

Version:
156 lines (155 loc) 6.31 kB
import type { ResourceAlternateKey } from '../../typings/pinejs-client-core'; import type { Application, ApplicationMembership, ApplicationMembershipRoles, PineOptions, InjectedDependenciesParam, PinePostResult } from '..'; type ResourceKey = number | ResourceAlternateKey<Pick<ApplicationMembership, 'user' | 'is_member_of__application'>>; export interface ApplicationMembershipCreationOptions { application: string | number; username: string; roleName?: ApplicationMembershipRoles; } declare const getApplicationMembershipModel: (deps: InjectedDependenciesParam, getApplication: (slugOrUuidOrId: string | number, options?: PineOptions<Application>) => Promise<Application>) => { /** * @summary Get a single application membership * @name get * @public * @function * @memberof balena.models.application.membership * * @description * This method returns a single application membership. * * @param {number|Object} membershipId - the id or an object with the unique `user` & `is_member_of__application` numeric pair of the membership * @param {Object} [options={}] - extra pine options to use * @fulfil {Object} - application membership * @returns {Promise} * * @example * balena.models.application.membership.get(5).then(function(memberships) { * console.log(memberships); * }); */ get(membershipId: ResourceKey, options?: PineOptions<ApplicationMembership>): Promise<ApplicationMembership>; /** * @summary Get all memberships by application * @name getAllByApplication * @public * @function * @memberof balena.models.application.membership * * @description * This method returns all application memberships for a specific application. * * @param {String|Number} slugOrUuidOrId - application slug (string), uuid (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object[]} - application memberships * @returns {Promise} * * @example * balena.models.application.membership.getAllByApplication('myorganization/myapp').then(function(memberships) { * console.log(memberships); * }); * * @example * balena.models.application.membership.getAllByApplication(123).then(function(memberships) { * console.log(memberships); * }); */ getAllByApplication(slugOrUuidOrId: number | string, options?: PineOptions<ApplicationMembership>): Promise<ApplicationMembership[]>; /** * @summary Get all memberships by user * @name getAllByUser * @public * @function * @memberof balena.models.application.membership * * @description * This method returns all application memberships for a specific user. * * @param {String|Number} usernameOrId - the user's username (string) or id (number) * @param {Object} [options={}] - extra pine options to use * @fulfil {Object[]} - application memberships * @returns {Promise} * * @example * balena.models.application.membership.getAllByUser('balena_os').then(function(memberships) { * console.log(memberships); * }); * * @example * balena.models.application.membership.getAllByUser(123).then(function(memberships) { * console.log(memberships); * }); */ getAllByUser(usernameOrId: number | string, options?: PineOptions<ApplicationMembership>): Promise<ApplicationMembership[]>; /** * @summary Creates a new membership for an application * @name create * @public * @function * @memberof balena.models.application.membership * * @description This method adds a user to an application by their username if they are a member of the organization. * * @param {Object} options - membership creation parameters * @param {String|Number} options.application - application handle (string), or id (number) * @param {String} options.username - the username of the balena user that will become a member * @param {String} [options.roleName="member"] - the role name to be granted to the membership * * @fulfil {Object} - application membership * @returns {Promise} * * @example * balena.models.application.membership.create({ application: "myApp", username: "user123", roleName: "member" }).then(function(membership) { * console.log(membership); * }); */ create({ application, username, roleName, }: ApplicationMembershipCreationOptions): Promise<PinePostResult<ApplicationMembership>>; /** * @summary Changes the role of an application member * @name changeRole * @public * @function * @memberof balena.models.application.membership * * @description This method changes the role of an application member. * * @param {Number|Object} idOrUniqueKey - the id or an object with the unique `user` & `is_member_of__application` numeric pair of the membership that will be changed * @param {String} roleName - the role name to be granted to the membership * * @returns {Promise} * * @example * balena.models.application.membership.changeRole(123, "member").then(function() { * console.log('OK'); * }); * * @example * balena.models.application.membership.changeRole({ * user: 123, * is_member_of__application: 125, * }, "member").then(function() { * console.log('OK'); * }); */ changeRole(idOrUniqueKey: ResourceKey, roleName: string): Promise<void>; /** * @summary Remove a membership * @name remove * @public * @function * @memberof balena.models.application.membership * * @param {Number|Object} idOrUniqueKey - the id or an object with the unique `user` & `is_member_of__application` numeric pair of the membership that will be removed * @returns {Promise} * * @example * balena.models.application.membership.remove(123); * * @example * balena.models.application.membership.remove({ * user: 123, * is_member_of__application: 125, * }); */ remove(idOrUniqueKey: ResourceKey): Promise<void>; }; export default getApplicationMembershipModel;