Skip to content

Commit 716b938

Browse files
authored
feat: create new custom api role policies endpoints (#46)
BREAKING CHANGE: create new custom api role policies endpoints
1 parent d9be56b commit 716b938

File tree

4 files changed

+160
-0
lines changed

4 files changed

+160
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import CRUDExtend from '../extends/crud'
2+
3+
import { buildURL } from '../utils/helpers'
4+
5+
class CustomApiRolePoliciesEndpoint extends CRUDExtend {
6+
constructor(endpoint) {
7+
super(endpoint)
8+
9+
this.endpoint = 'permissions'
10+
}
11+
12+
CreateCustomApiRolePolicy(body) {
13+
return this.request.send(
14+
`${this.endpoint}/custom-api-role-policies`,
15+
'POST',
16+
body
17+
)
18+
}
19+
20+
UpdateCustomApiRolePolicy(policyId, body) {
21+
return this.request.send(
22+
`${this.endpoint}/custom-api-role-policies/${policyId}`,
23+
'PUT',
24+
body
25+
)
26+
}
27+
28+
GetCustomApiRolePolicies({ customApiId }) {
29+
const { limit, offset, sort } = this
30+
31+
return this.request.send(
32+
buildURL(`${this.endpoint}/custom-api-role-policies?filter=eq(custom_api_id,${customApiId})`, {
33+
limit,
34+
offset,
35+
sort
36+
}),
37+
'GET'
38+
)
39+
}
40+
41+
GetBuiltInRoles() {
42+
return this.request.send(
43+
`${this.endpoint}/built-in-roles`,
44+
'GET'
45+
)
46+
}
47+
48+
DeleteCustomApiRolePolicy(policyId) {
49+
return this.request.send(
50+
`${this.endpoint}/custom-api-role-policies/${policyId}`,
51+
'DELETE'
52+
)
53+
}
54+
}
55+
56+
export default CustomApiRolePoliciesEndpoint

src/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ import { SubscriptionProrationPoliciesEndpoint } from './types/subscription-pror
7070
import { SubscriptionInvoicesEndpoint } from './types/subscription-invoices'
7171
import { CustomRelationshipsEndpoint } from './types/custom-relationships'
7272
import { MultiLocationInventoriesEndpoint } from './types/multi-location-inventories'
73+
import { CustomApiRolePoliciesEndpoint } from './types/custom-api-role-policies'
7374

7475
export * from './types/config'
7576
export * from './types/storage'
@@ -141,6 +142,7 @@ export * from './types/subscription-offerings'
141142
export * from './types/one-time-password-token-request'
142143
export * from './types/subscriptions'
143144
export * from './types/rule-promotions'
145+
export * from './types/custom-api-role-policies'
144146
export * from './types/subscription-subscribers'
145147
export * from './types/subscription-jobs'
146148
export * from './types/subscription-schedules'
@@ -214,6 +216,7 @@ export class ElasticPath {
214216
OneTimePasswordTokenRequest: OneTimePasswordTokenRequestEndpoint
215217
Subscriptions: SubscriptionsEndpoint
216218
RulePromotions: RulePromotionsEndpoint
219+
CustomApiRolePolicies: CustomApiRolePoliciesEndpoint
217220
SubscriptionSubscribers: SubscriptionSubscribersEndpoint
218221
SubscriptionJobs: SubscriptionJobsEndpoint
219222
SubscriptionSchedules: SubscriptionSchedulesEndpoint

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ import {
7171
import CatalogsEndpoint from './endpoints/catalogs'
7272
import ShopperCatalogEndpoint from './endpoints/catalog'
7373
import CustomApisEndpoint from './endpoints/custom-apis'
74+
import CustomApiRolePoliciesEndpoint from './endpoints/custom-api-role-policies'
7475

7576
export default class ElasticPath {
7677
constructor(config) {
@@ -146,6 +147,7 @@ export default class ElasticPath {
146147
this.SubscriptionJobs = new SubscriptionJobsEndpoint(config)
147148
this.SubscriptionSchedules = new SubscriptionSchedulesEndpoint(config)
148149
this.CustomApis = new CustomApisEndpoint(config)
150+
this.CustomApiRolePolicies = new CustomApiRolePoliciesEndpoint(config)
149151
this.SubscriptionDunningRules = new SubscriptionDunningRulesEndpoint(config)
150152
this.SubscriptionProrationPolicies =
151153
new SubscriptionProrationPoliciesEndpoint(config)

src/types/custom-api-role-policies.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { Resource } from './core'
2+
3+
export interface BuiltInRolePolicy {
4+
id: string
5+
type: 'built_in_role'
6+
links: {
7+
self: string
8+
}
9+
name: string
10+
cm_user_assignable: boolean
11+
}
12+
13+
export interface CustomApiRolePolicyBase {
14+
data: {
15+
type: 'custom_api_role_policy'
16+
create: boolean
17+
list: boolean
18+
read: boolean
19+
update: boolean
20+
delete: boolean
21+
}
22+
}
23+
24+
export interface CustomApiRolePolicyRequestBody {
25+
type: 'custom_api_role_policy'
26+
create: boolean
27+
list: boolean
28+
read: boolean
29+
update: boolean
30+
delete: boolean
31+
relationships: {
32+
custom_api: {
33+
data: {
34+
type: 'custom_api'
35+
id: string
36+
}
37+
}
38+
role: {
39+
data: {
40+
type: 'built_in_role'
41+
id: string
42+
}
43+
}
44+
}
45+
}
46+
47+
export interface CustomApiRolePolicy {
48+
id: string
49+
type: 'custom_api_role_policy'
50+
relationships: {
51+
custom_api: {
52+
data: {
53+
type: 'custom_api'
54+
id: string
55+
}
56+
}
57+
role: {
58+
data: {
59+
type: 'built_in_role'
60+
id: string
61+
}
62+
}
63+
}
64+
links: {
65+
self: string
66+
}
67+
meta: {
68+
timestamps: {
69+
created_at: string
70+
updated_at: string
71+
}
72+
}
73+
create: boolean
74+
list: boolean
75+
read: boolean
76+
update: boolean
77+
delete: boolean
78+
}
79+
80+
export interface CustomApiRolePoliciesEndpoint {
81+
endpoint: 'permissions'
82+
83+
CreateCustomApiRolePolicy(
84+
body: CustomApiRolePolicyRequestBody
85+
): Promise<Resource<CustomApiRolePolicy>>
86+
87+
UpdateCustomApiRolePolicy(
88+
policyId: string,
89+
body: CustomApiRolePolicyBase
90+
): Promise<Resource<CustomApiRolePolicy>>
91+
92+
GetCustomApiRolePolicies(args: {
93+
customApiId: string
94+
}): Promise<Resource<Array<CustomApiRolePolicy>>>
95+
96+
GetBuiltInRoles(): Promise<Resource<Array<BuiltInRolePolicy>>>
97+
98+
DeleteCustomApiRolePolicy(policyId: string): Promise<void>
99+
}

0 commit comments

Comments
 (0)