Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
81 changes: 81 additions & 0 deletions src/endpoints/custom-user-roles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import CRUDExtend from '../extends/crud'

import { buildURL } from '../utils/helpers'

function withQuotedName(filter) {
const name = filter && filter.eq ? filter.eq.name : undefined
if (name === undefined || name === null) return filter

return {
...filter,
eq: {
...filter.eq,
name: `"${encodeURIComponent(String(name).replace(/"/g, '\\"'))}"`
}
}
}

class CustomUserRolesEndpoint extends CRUDExtend {
constructor(endpoint) {
super(endpoint)

this.endpoint = 'permissions'
}

GetCustomUserRoles({ limit, offset, filter, sort } = {}) {
return this.request.send(
buildURL(`${this.endpoint}/custom-user-roles`, {
limit: limit !== undefined ? limit : this.limit,
offset: offset !== undefined ? offset : this.offset,
filter: withQuotedName(filter !== undefined ? filter : this.filter),
sort: sort !== undefined ? sort : this.sort
}),
'GET',
undefined,
undefined,
this
)
}

GetCustomUserRole(roleId) {
return this.request.send(
`${this.endpoint}/custom-user-roles/${roleId}`,
'GET',
undefined,
undefined,
this
)
}

CreateCustomUserRole(body) {
return this.request.send(
`${this.endpoint}/custom-user-roles`,
'POST',
body,
undefined,
this
)
}

UpdateCustomUserRole(roleId, body) {
return this.request.send(
`${this.endpoint}/custom-user-roles/${roleId}`,
'PUT',
body,
undefined,
this
)
}

DeleteCustomUserRole(roleId) {
return this.request.send(
`${this.endpoint}/custom-user-roles/${roleId}`,
'DELETE',
undefined,
undefined,
this
)
}
}

export default CustomUserRolesEndpoint
3 changes: 3 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { SubscriptionInvoicesEndpoint } from './types/subscription-invoices'
import { CustomRelationshipsEndpoint } from './types/custom-relationships'
import { MultiLocationInventoriesEndpoint } from './types/multi-location-inventories'
import { CustomApiRolePoliciesEndpoint } from './types/custom-api-role-policies'
import { CustomUserRolesEndpoint } from './types/custom-user-roles'
import { AccountTagsEndpoint } from './types/account-tags'

export * from './types/config'
Expand Down Expand Up @@ -144,6 +145,7 @@ export * from './types/one-time-password-token-request'
export * from './types/subscriptions'
export * from './types/rule-promotions'
export * from './types/custom-api-role-policies'
export * from './types/custom-user-roles'
export * from './types/subscription-subscribers'
export * from './types/subscription-jobs'
export * from './types/subscription-schedules'
Expand Down Expand Up @@ -219,6 +221,7 @@ export class ElasticPath {
Subscriptions: SubscriptionsEndpoint
RulePromotions: RulePromotionsEndpoint
CustomApiRolePolicies: CustomApiRolePoliciesEndpoint
CustomUserRoles: CustomUserRolesEndpoint
SubscriptionSubscribers: SubscriptionSubscribersEndpoint
SubscriptionJobs: SubscriptionJobsEndpoint
SubscriptionSchedules: SubscriptionSchedulesEndpoint
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import CatalogsEndpoint from './endpoints/catalogs'
import ShopperCatalogEndpoint from './endpoints/catalog'
import CustomApisEndpoint from './endpoints/custom-apis'
import CustomApiRolePoliciesEndpoint from './endpoints/custom-api-role-policies'
import CustomUserRolesEndpoint from './endpoints/custom-user-roles'

export default class ElasticPath {
constructor(config) {
Expand Down Expand Up @@ -149,6 +150,7 @@ export default class ElasticPath {
this.SubscriptionSchedules = new SubscriptionSchedulesEndpoint(config)
this.CustomApis = new CustomApisEndpoint(config)
this.CustomApiRolePolicies = new CustomApiRolePoliciesEndpoint(config)
this.CustomUserRoles = new CustomUserRolesEndpoint(config)
this.SubscriptionDunningRules = new SubscriptionDunningRulesEndpoint(config)
this.SubscriptionProrationPolicies =
new SubscriptionProrationPoliciesEndpoint(config)
Expand Down
106 changes: 106 additions & 0 deletions src/types/custom-user-roles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { Resource, ResourcePage } from './core'

export type AccessLevel = 'none' | 'view' | 'manage'

/**
* The permission groups a custom user role grants access to.
*
* Every group is required on create. Composer, Legacy Catalogs, Metrics,
* Custom Actions and Team accept a narrower set of levels than the rest —
* Custom Actions and Team only ever 'none' for a custom user role, though
* standard user roles may hold higher levels for them.
*/
export type AccessLevels = {
accounts: AccessLevel
application_keys: AccessLevel
authentication: AccessLevel
catalog_releases: AccessLevel
catalog_search: AccessLevel
catalogs: AccessLevel
composer: 'none' | 'manage'
content_and_pages: AccessLevel
currencies: AccessLevel
custom_actions: 'none'
custom_apis: AccessLevel
flows: AccessLevel
inventories: AccessLevel
legacy_catalogs: 'none' | 'manage'
metrics: 'none' | 'view'
orders: AccessLevel
payment_gateways: AccessLevel
personal_data: AccessLevel
price_books: AccessLevel
products: AccessLevel
promotions: AccessLevel
settings: AccessLevel
subscription_billing: AccessLevel
subscription_jobs: AccessLevel
subscription_offerings: AccessLevel
subscription_subscribers: AccessLevel
team: 'none'
webhooks: AccessLevel
}

export interface CustomUserRole {
id: string
type: 'custom_user_role'
name: string
description?: string
access_levels: AccessLevels
links: { self: string }
meta: {
timestamps: {
created_at: string
updated_at: string
}
owner: string
}
}

// Create rejects a missing or null description; an empty string is accepted.
// Every permission group is required, so access_levels must be complete.
export interface CreateCustomUserRoleBody {
type: 'custom_user_role'
name: string
description: string
access_levels: AccessLevels
}

// Update merges into the stored role, so any subset may be sent. Omitted
// permission groups keep their current level.
export interface UpdateCustomUserRoleBody {
type: 'custom_user_role'
name?: string
description?: string
access_levels?: Partial<AccessLevels>
}

export interface CustomUserRoleFilter {
eq?: {
name?: string
}
}

export interface CustomUserRolesEndpoint {
endpoint: 'permissions'

GetCustomUserRoles(args?: {
limit?: number
offset?: number
filter?: CustomUserRoleFilter
sort?: string
}): Promise<ResourcePage<CustomUserRole>>

GetCustomUserRole(roleId: string): Promise<Resource<CustomUserRole>>

CreateCustomUserRole(
body: CreateCustomUserRoleBody
): Promise<Resource<CustomUserRole>>

UpdateCustomUserRole(
roleId: string,
body: UpdateCustomUserRoleBody
): Promise<Resource<CustomUserRole>>

DeleteCustomUserRole(roleId: string): Promise<void>
}
1 change: 1 addition & 0 deletions test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require('./unit/account-authentication-settings')
require('./unit/account-membership-settings')
require('./unit/account-memberships')
require('./unit/application-keys')
require('./unit/custom-user-roles')
require('./unit/one-time-password-token-request')

// Utilities
Expand Down
Loading
Loading