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
21 changes: 15 additions & 6 deletions src/endpoints/custom-api-role-policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class CustomApiRolePoliciesEndpoint extends CRUDExtend {

CreateCustomApiRolePolicy(body) {
return this.request.send(
`${this.endpoint}/custom-api-role-policies`,
'POST',
`${this.endpoint}/custom-api-role-policies`,
'POST',
body
)
}
Expand All @@ -25,11 +25,13 @@ class CustomApiRolePoliciesEndpoint extends CRUDExtend {
)
}

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

return this.request.send(
buildURL(`${this.endpoint}/custom-api-role-policies?filter=eq(custom_api_id,${customApiId})`, {
buildURL(`${this.endpoint}/custom-api-role-policies`, {
filter: { eq: { custom_api_id: customApiId } },
...(include === 'role' && { include }),
limit,
offset,
sort
Expand All @@ -38,9 +40,16 @@ class CustomApiRolePoliciesEndpoint extends CRUDExtend {
)
}

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

GetStandardShopperRoles() {
return this.request.send(
`${this.endpoint}/standard-shopper-roles`,
'GET'
)
}
Expand Down
70 changes: 34 additions & 36 deletions src/types/custom-api-role-policies.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { Resource } from './core'
import { Resource, ResourceList } from './core'

export interface BuiltInRolePolicy {
export interface StandardUserRole {
id: string
type: 'built_in_role'
links: {
self: string
}
type: 'standard_user_role'
links: { self: string }
name: string
}

export interface StandardShopperRole {
id: string
type: 'standard_shopper_role'
links: { self: string }
name: string
cm_user_assignable: boolean
}

export type StandardRole = StandardUserRole | StandardShopperRole
export type StandardRoleType = StandardRole['type']

export type IncludedRole = Omit<StandardRole, 'links'>

export interface CustomApiRolePolicyBase {
data: {
type: 'custom_api_role_policy'
Expand All @@ -29,41 +38,19 @@ export interface CustomApiRolePolicyRequestBody {
update: boolean
delete: boolean
relationships: {
custom_api: {
data: {
type: 'custom_api'
id: string
}
}
role: {
data: {
type: 'built_in_role'
id: string
}
}
custom_api: { data: { type: 'custom_api'; id: string } }
role: { data: { type: StandardRoleType; 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
custom_api: { data: { type: 'custom_api'; id: string } }
role: { data: { type: StandardRoleType; id: string } }
}
links: { self: string }
meta: {
timestamps: {
created_at: string
Expand All @@ -77,6 +64,14 @@ export interface CustomApiRolePolicy {
delete: boolean
}

export interface CustomApiRolePoliciesIncluded {
role: IncludedRole[]
}

export interface CustomApiRolePoliciesResponse extends ResourceList<CustomApiRolePolicy> {
included?: CustomApiRolePoliciesIncluded
}

export interface CustomApiRolePoliciesEndpoint {
endpoint: 'permissions'

Expand All @@ -91,9 +86,12 @@ export interface CustomApiRolePoliciesEndpoint {

GetCustomApiRolePolicies(args: {
customApiId: string
}): Promise<Resource<Array<CustomApiRolePolicy>>>
include?: 'role'
}): Promise<CustomApiRolePoliciesResponse>

GetStandardUserRoles(): Promise<ResourceList<StandardUserRole>>

GetBuiltInRoles(): Promise<Resource<Array<BuiltInRolePolicy>>>
GetStandardShopperRoles(): Promise<ResourceList<StandardShopperRole>>

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