Skip to content

Commit

Permalink
feat: create new custom api role policies endpoints (#46)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: create new custom api role policies endpoints
  • Loading branch information
ellanan authored Jan 21, 2025
1 parent d9be56b commit 716b938
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/endpoints/custom-api-role-policies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import CRUDExtend from '../extends/crud'

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

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

this.endpoint = 'permissions'
}

CreateCustomApiRolePolicy(body) {
return this.request.send(
`${this.endpoint}/custom-api-role-policies`,
'POST',
body
)
}

UpdateCustomApiRolePolicy(policyId, body) {
return this.request.send(
`${this.endpoint}/custom-api-role-policies/${policyId}`,
'PUT',
body
)
}

GetCustomApiRolePolicies({ customApiId }) {
const { limit, offset, sort } = this

return this.request.send(
buildURL(`${this.endpoint}/custom-api-role-policies?filter=eq(custom_api_id,${customApiId})`, {
limit,
offset,
sort
}),
'GET'
)
}

GetBuiltInRoles() {
return this.request.send(
`${this.endpoint}/built-in-roles`,
'GET'
)
}

DeleteCustomApiRolePolicy(policyId) {
return this.request.send(
`${this.endpoint}/custom-api-role-policies/${policyId}`,
'DELETE'
)
}
}

export default CustomApiRolePoliciesEndpoint
3 changes: 3 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { SubscriptionProrationPoliciesEndpoint } from './types/subscription-pror
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'

export * from './types/config'
export * from './types/storage'
Expand Down Expand Up @@ -141,6 +142,7 @@ export * from './types/subscription-offerings'
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/subscription-subscribers'
export * from './types/subscription-jobs'
export * from './types/subscription-schedules'
Expand Down Expand Up @@ -214,6 +216,7 @@ export class ElasticPath {
OneTimePasswordTokenRequest: OneTimePasswordTokenRequestEndpoint
Subscriptions: SubscriptionsEndpoint
RulePromotions: RulePromotionsEndpoint
CustomApiRolePolicies: CustomApiRolePoliciesEndpoint
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 @@ -71,6 +71,7 @@ import {
import CatalogsEndpoint from './endpoints/catalogs'
import ShopperCatalogEndpoint from './endpoints/catalog'
import CustomApisEndpoint from './endpoints/custom-apis'
import CustomApiRolePoliciesEndpoint from './endpoints/custom-api-role-policies'

export default class ElasticPath {
constructor(config) {
Expand Down Expand Up @@ -146,6 +147,7 @@ export default class ElasticPath {
this.SubscriptionJobs = new SubscriptionJobsEndpoint(config)
this.SubscriptionSchedules = new SubscriptionSchedulesEndpoint(config)
this.CustomApis = new CustomApisEndpoint(config)
this.CustomApiRolePolicies = new CustomApiRolePoliciesEndpoint(config)
this.SubscriptionDunningRules = new SubscriptionDunningRulesEndpoint(config)
this.SubscriptionProrationPolicies =
new SubscriptionProrationPoliciesEndpoint(config)
Expand Down
99 changes: 99 additions & 0 deletions src/types/custom-api-role-policies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { Resource } from './core'

export interface BuiltInRolePolicy {
id: string
type: 'built_in_role'
links: {
self: string
}
name: string
cm_user_assignable: boolean
}

export interface CustomApiRolePolicyBase {
data: {
type: 'custom_api_role_policy'
create: boolean
list: boolean
read: boolean
update: boolean
delete: boolean
}
}

export interface CustomApiRolePolicyRequestBody {
type: 'custom_api_role_policy'
create: boolean
list: boolean
read: boolean
update: boolean
delete: boolean
relationships: {
custom_api: {
data: {
type: 'custom_api'
id: string
}
}
role: {
data: {
type: 'built_in_role'
id: string
}
}
}
}

export interface CustomApiRolePolicy {
id: string
type: 'custom_api_role_policy'
relationships: {
custom_api: {
data: {
type: 'custom_api'
id: string
}
}
role: {
data: {
type: 'built_in_role'
id: string
}
}
}
links: {
self: string
}
meta: {
timestamps: {
created_at: string
updated_at: string
}
}
create: boolean
list: boolean
read: boolean
update: boolean
delete: boolean
}

export interface CustomApiRolePoliciesEndpoint {
endpoint: 'permissions'

CreateCustomApiRolePolicy(
body: CustomApiRolePolicyRequestBody
): Promise<Resource<CustomApiRolePolicy>>

UpdateCustomApiRolePolicy(
policyId: string,
body: CustomApiRolePolicyBase
): Promise<Resource<CustomApiRolePolicy>>

GetCustomApiRolePolicies(args: {
customApiId: string
}): Promise<Resource<Array<CustomApiRolePolicy>>>

GetBuiltInRoles(): Promise<Resource<Array<BuiltInRolePolicy>>>

DeleteCustomApiRolePolicy(policyId: string): Promise<void>
}

0 comments on commit 716b938

Please sign in to comment.