Skip to content

Commit

Permalink
update addusersdoamins
Browse files Browse the repository at this point in the history
Signed-off-by: Musilah <[email protected]>
  • Loading branch information
Musilah committed Mar 28, 2024
1 parent 26622f0 commit 42f0368
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"rules": {
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-throw-literal": "off",
"no-useless-catch": "off"
"no-useless-catch": "off",
"no-unused-vars": "off"
}
}
20 changes: 11 additions & 9 deletions examples/domainsExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mySdk.domains
mySdk.domains.UpdateDomain(
{ name: '<domainName>', id: '<domainID>' },
'<token>'
)
)
.then((response: any) => {
console.log('response: ', response)
})
Expand All @@ -42,7 +42,7 @@ mySdk.domains.Domain(

mySdk.domains.DomainPermissions(
'<domainID>',
'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiJmMjQ4ZDA1Ny0yODNjLTQzZjQtOGJhMS0xM2ZmYzU1MTRjMDciLCJleHAiOjE3MTE0NzE4MDMsImlhdCI6MTcxMTQ2ODIwMywiaXNzIjoibWFnaXN0cmFsYS5hdXRoIiwic3ViIjoiNzA1YmMzYzYtN2Y5My00MWQ2LWJjNGMtMGE4N2Y4NWU0OTczIiwidHlwZSI6MCwidXNlciI6IjcwNWJjM2M2LTdmOTMtNDFkNi1iYzRjLTBhODdmODVlNDk3MyJ9.Gjhos0VCZiDoIYKsTF6iQAxUlU8CKUz2e6l007_ICI_X9_0t2LTG0G15qbQXsqZKzo4gAPgyuW8BYJKD7SlhuA'
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
Expand All @@ -53,7 +53,7 @@ mySdk.domains.DomainPermissions(

mySdk.domains.Domains(
{ offset: 0, limit: 10 },
'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiJmMjQ4ZDA1Ny0yODNjLTQzZjQtOGJhMS0xM2ZmYzU1MTRjMDciLCJleHAiOjE3MTE0NzE4MDMsImlhdCI6MTcxMTQ2ODIwMywiaXNzIjoibWFnaXN0cmFsYS5hdXRoIiwic3ViIjoiNzA1YmMzYzYtN2Y5My00MWQ2LWJjNGMtMGE4N2Y4NWU0OTczIiwidHlwZSI6MCwidXNlciI6IjcwNWJjM2M2LTdmOTMtNDFkNi1iYzRjLTBhODdmODVlNDk3MyJ9.Gjhos0VCZiDoIYKsTF6iQAxUlU8CKUz2e6l007_ICI_X9_0t2LTG0G15qbQXsqZKzo4gAPgyuW8BYJKD7SlhuA'
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
Expand All @@ -65,7 +65,7 @@ mySdk.domains.Domains(
mySdk.domains.ListUserDomains(
'<userID>',
{ offset: 0, limit: 10 },
'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiJmMjQ4ZDA1Ny0yODNjLTQzZjQtOGJhMS0xM2ZmYzU1MTRjMDciLCJleHAiOjE3MTE0NzE4MDMsImlhdCI6MTcxMTQ2ODIwMywiaXNzIjoibWFnaXN0cmFsYS5hdXRoIiwic3ViIjoiNzA1YmMzYzYtN2Y5My00MWQ2LWJjNGMtMGE4N2Y4NWU0OTczIiwidHlwZSI6MCwidXNlciI6IjcwNWJjM2M2LTdmOTMtNDFkNi1iYzRjLTBhODdmODVlNDk3MyJ9.Gjhos0VCZiDoIYKsTF6iQAxUlU8CKUz2e6l007_ICI_X9_0t2LTG0G15qbQXsqZKzo4gAPgyuW8BYJKD7SlhuA'
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
Expand All @@ -76,7 +76,7 @@ mySdk.domains.ListUserDomains(

mySdk.domains.EnableDomain(
'<domainID>',
'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiJmMjQ4ZDA1Ny0yODNjLTQzZjQtOGJhMS0xM2ZmYzU1MTRjMDciLCJleHAiOjE3MTE0NzE4MDMsImlhdCI6MTcxMTQ2ODIwMywiaXNzIjoibWFnaXN0cmFsYS5hdXRoIiwic3ViIjoiNzA1YmMzYzYtN2Y5My00MWQ2LWJjNGMtMGE4N2Y4NWU0OTczIiwidHlwZSI6MCwidXNlciI6IjcwNWJjM2M2LTdmOTMtNDFkNi1iYzRjLTBhODdmODVlNDk3MyJ9.Gjhos0VCZiDoIYKsTF6iQAxUlU8CKUz2e6l007_ICI_X9_0t2LTG0G15qbQXsqZKzo4gAPgyuW8BYJKD7SlhuA'
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
Expand All @@ -87,7 +87,7 @@ mySdk.domains.EnableDomain(

mySdk.domains.DisableDomain(
'<domainID>',
'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiJmMjQ4ZDA1Ny0yODNjLTQzZjQtOGJhMS0xM2ZmYzU1MTRjMDciLCJleHAiOjE3MTE0NzE4MDMsImlhdCI6MTcxMTQ2ODIwMywiaXNzIjoibWFnaXN0cmFsYS5hdXRoIiwic3ViIjoiNzA1YmMzYzYtN2Y5My00MWQ2LWJjNGMtMGE4N2Y4NWU0OTczIiwidHlwZSI6MCwidXNlciI6IjcwNWJjM2M2LTdmOTMtNDFkNi1iYzRjLTBhODdmODVlNDk3MyJ9.Gjhos0VCZiDoIYKsTF6iQAxUlU8CKUz2e6l007_ICI_X9_0t2LTG0G15qbQXsqZKzo4gAPgyuW8BYJKD7SlhuA'
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
Expand All @@ -98,8 +98,9 @@ mySdk.domains.DisableDomain(

mySdk.domains.AddUsertoDomain(
'<domainID>',
{ userIDs: ['<userID>', '<userID>'], relation: '<role>' },
'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJkb21haW4iOiJmMjQ4ZDA1Ny0yODNjLTQzZjQtOGJhMS0xM2ZmYzU1MTRjMDciLCJleHAiOjE3MTE0NzE4MDMsImlhdCI6MTcxMTQ2ODIwMywiaXNzIjoibWFnaXN0cmFsYS5hdXRoIiwic3ViIjoiNzA1YmMzYzYtN2Y5My00MWQ2LWJjNGMtMGE4N2Y4NWU0OTczIiwidHlwZSI6MCwidXNlciI6IjcwNWJjM2M2LTdmOTMtNDFkNi1iYzRjLTBhODdmODVlNDk3MyJ9.Gjhos0VCZiDoIYKsTF6iQAxUlU8CKUz2e6l007_ICI_X9_0t2LTG0G15qbQXsqZKzo4gAPgyuW8BYJKD7SlhuA'
['<userID>', '<userID>'],
'<role>',
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
Expand All @@ -110,7 +111,8 @@ mySdk.domains.AddUsertoDomain(

mySdk.domains.RemoveUserfromDomain(
'<domainID>',
{ userIDs: ['<userID>', '<userID>'], relation: '<role>' },
['<userID>', '<userID>'],
'<role>',
'<token>'
)
.then((response: any) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/usersExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mySdk.users.UserProfile(
})

mySdk.users.CreateToken(
{ identity: '[email protected]', secret: '12345678' }
{ identity: '[email protected]', secret: '12345678', domain_id: '<domainID>' }
)
.then((response: any) => {
console.log('response: ', response)
Expand Down
27 changes: 12 additions & 15 deletions src/domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ interface PageRes {
limit: number
}

interface UserRelationRequest {
userIDs: string[]
relation: string
}

export default class Domains {
// Domains API client

Expand All @@ -43,7 +38,7 @@ export default class Domains {
this.domainError = new Errors()
}

public async CreateDomain (domain: Domain, token: string): Promise<Domain> {
public async CreateDomain (domain: Domain, token: string): Promise<Domain | undefined> {
// CreateDomain creates a new domain.
const options: RequestInit = {
method: 'POST',
Expand All @@ -70,7 +65,7 @@ export default class Domains {
}
}

public async UpdateDomain (domain: Domain, token: string): Promise<Domain> {
public async UpdateDomain (domain: Domain, token: string): Promise<Domain | undefined> {
// UpdateDomain updates an existing domain.
const options: RequestInit = {
method: 'PATCH',
Expand All @@ -97,7 +92,7 @@ export default class Domains {
}
}

public async Domain (domainID: string, token: string): Promise<Domain> {
public async Domain (domainID: string, token: string): Promise<Domain | undefined> {
// Domain retrieves domain with provided ID.
const options: RequestInit = {
method: 'GET',
Expand All @@ -123,7 +118,7 @@ export default class Domains {
}
}

public async DomainPermissions (domainID: string, token: string): Promise<Domain> {
public async DomainPermissions (domainID: string, token: string): Promise<Domain | undefined> {
// DomainPermissions retrieves domain permissions with provided ID.
/**
* @method DomainPermissions - retrieves domain permissions with provided ID.
Expand Down Expand Up @@ -158,11 +153,11 @@ export default class Domains {
}
}

public async Domains (query_params: QueryParams, token: string): Promise<DomainsInterface> {
public async Domains (queryParams: QueryParams, token: string): Promise<DomainsInterface | undefined> {
// Domains retrieves all domains.

const stringParams: Record<string, string> = Object.fromEntries(
Object.entries(query_params).map(([key, value]) => [key, String(value)])
Object.entries(queryParams).map(([key, value]) => [key, String(value)])
)
const options: RequestInit = {
method: 'GET',
Expand All @@ -188,11 +183,11 @@ export default class Domains {
}
}

public async ListUserDomains (userID: string, query_params: QueryParams, token: string): Promise<DomainsInterface> {
public async ListUserDomains (userID: string, queryParams: QueryParams, token: string): Promise<DomainsInterface | undefined> {
// ListUserDomains retrieves all domains for a user.

const stringParams: Record<string, string> = Object.fromEntries(
Object.entries(query_params).map(([key, value]) => [key, String(value)])
Object.entries(queryParams).map(([key, value]) => [key, String(value)])
)
const options: RequestInit = {
method: 'GET',
Expand Down Expand Up @@ -268,8 +263,9 @@ export default class Domains {
}
}

public async AddUsertoDomain (domainID: string, req: UserRelationRequest, token: string): Promise<any> {
public async AddUsertoDomain (domainID: string, userIDs: string[], relation: string, token: string): Promise<string | undefined> {
// AddUsertoDomain adds user to domain.
const req = { user_ids: userIDs, relation }
const options: RequestInit = {
method: 'POST',
headers: {
Expand All @@ -294,8 +290,9 @@ export default class Domains {
}
}

public async RemoveUserfromDomain (domainID: string, req: UserRelationRequest, token: string): Promise<any> {
public async RemoveUserfromDomain (domainID: string, userIDs: string[], relation: string, token: string): Promise<any> {
// RemoveUserfromDomain removes user from domain.
const req = { user_ids: userIDs, relation }
const options: RequestInit = {
method: 'POST',
headers: {
Expand Down

0 comments on commit 42f0368

Please sign in to comment.