Skip to content

Commit

Permalink
NOISSUE - Add Domains Service (#8)
Browse files Browse the repository at this point in the history
* add domains

Signed-off-by: Musilah <[email protected]>

* add eslinter for domains

Signed-off-by: Musilah <[email protected]>

* update addusersdoamins

Signed-off-by: Musilah <[email protected]>

* remove undefined type

Signed-off-by: Musilah <[email protected]>

* add throw error

Signed-off-by: Musilah <[email protected]>

* fix response to addusers to domains

Signed-off-by: Musilah <[email protected]>

* add listDomainsUsers fx

Signed-off-by: Musilah <[email protected]>

* add relation type

Signed-off-by: Musilah <[email protected]>

---------

Signed-off-by: Musilah <[email protected]>
  • Loading branch information
Musilah authored Apr 4, 2024
1 parent 0f24bc5 commit 6e937e0
Show file tree
Hide file tree
Showing 7 changed files with 588 additions and 5 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"
}
}
136 changes: 136 additions & 0 deletions examples/domains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import SDK from '../src/sdk'

const defaultUrl = 'http://localhost'

const mySdk = new SDK({
domainsUrl: defaultUrl + ':8189',
usersUrl: defaultUrl + ':9002'
})

mySdk.domains
.CreateDomain(
{ name: '<domainName>' },
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.domains.UpdateDomain(
{ name: '<domainName>', id: '<domainID>' },
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.domains.Domain(
'<domainID>',
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.domains.DomainPermissions(
'<domainID>',
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.domains.Domains(
{ offset: 0, limit: 10 },
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.domains.ListUserDomains(
'<userID>',
{ offset: 0, limit: 10 },
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.domains.ListDomainUsers(
'<domainID>',
{ offset: 0, limit: 10 },
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.domains.EnableDomain(
'<domainID>',
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.domains.DisableDomain(
'<domainID>',
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.domains.AddUsertoDomain(
'<domainID>',
['<userID>', '<userID>'],
'administrator',
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.domains.RemoveUserfromDomain(
'<domainID>',
['<userID>', '<userID>'],
'administrator',
'<token>'
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})
2 changes: 1 addition & 1 deletion examples/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mySdk.users.UserProfile(
})

mySdk.users.CreateToken(
{ identity: '<identity>', secret: '<password>' }
{ identity: '<identity>', secret: '<password>', domain_id: '<domainID>' }
)
.then((response: any) => {
console.log('response: ', response)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"files": [
"dist",
"sdk.js",
"mainflux",
"src",
"LICENSE"
],
"scripts": {
Expand Down
31 changes: 29 additions & 2 deletions src/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface User {
role?: string
status?: 'enabled' | 'disabled'
metadata?: Record<string, any>
updatedBy?: string
updated_by?: string
}

export interface UsersPage {
Expand Down Expand Up @@ -82,6 +82,9 @@ export interface Response {
status: number
message?: string
}

export type Relation = 'administrator' | 'editor' | 'viewer' | 'member'

export interface QueryParams {
total?: number
offset?: number
Expand All @@ -106,9 +109,33 @@ export interface QueryParams {
topic?: string
contact?: string
state?: string
list_perms?: string
list_perms?: boolean
invited_by?: string
user_id?: string
domain_id?: string
relation?: string
}

export interface Domain {
name?: string
id?: string
alias?: string
metadata?: Record<string, any>
tags?: string[]
status?: 'enabled' | 'disabled'
permission?: string
permissions?: string[]
created_by?: string
updated_by?: string
created_at?: Date
updated_at?: Date
}

export interface DomainsPage {
domains: Domain[]
page: PageRes
}

export interface Permissions {
permissions: string[]
}
Loading

0 comments on commit 6e937e0

Please sign in to comment.