diff --git a/src/endpoints/custom-api-role-policies.js b/src/endpoints/custom-api-role-policies.js index b462f62..d1cb76e 100644 --- a/src/endpoints/custom-api-role-policies.js +++ b/src/endpoints/custom-api-role-policies.js @@ -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 ) } @@ -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 @@ -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' ) } diff --git a/src/types/custom-api-role-policies.ts b/src/types/custom-api-role-policies.ts index 07ef1d1..108868b 100644 --- a/src/types/custom-api-role-policies.ts +++ b/src/types/custom-api-role-policies.ts @@ -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 + export interface CustomApiRolePolicyBase { data: { type: 'custom_api_role_policy' @@ -29,18 +38,8 @@ 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 } } } } @@ -48,22 +47,10 @@ 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 @@ -77,6 +64,14 @@ export interface CustomApiRolePolicy { delete: boolean } +export interface CustomApiRolePoliciesIncluded { + role: IncludedRole[] +} + +export interface CustomApiRolePoliciesResponse extends ResourceList { + included?: CustomApiRolePoliciesIncluded +} + export interface CustomApiRolePoliciesEndpoint { endpoint: 'permissions' @@ -91,9 +86,12 @@ export interface CustomApiRolePoliciesEndpoint { GetCustomApiRolePolicies(args: { customApiId: string - }): Promise>> + include?: 'role' + }): Promise + + GetStandardUserRoles(): Promise> - GetBuiltInRoles(): Promise>> + GetStandardShopperRoles(): Promise> DeleteCustomApiRolePolicy(policyId: string): Promise }