Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NOISSUE - Add Domains Service #8

Merged
merged 8 commits into from
Apr 4, 2024
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
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
Loading