Skip to content

Commit

Permalink
NOISSUE - Sync Users service with Magistrala core (#79)
Browse files Browse the repository at this point in the history
* update useres client

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

* fix comments and params

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

* update issuetoken example

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

* modify issue token function

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

* rename password back to secret in credentials

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

---------

Signed-off-by: Musilah <[email protected]>
  • Loading branch information
Musilah authored Nov 5, 2024
1 parent b888d96 commit e754d29
Show file tree
Hide file tree
Showing 14 changed files with 280 additions and 95 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-forks-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@absmach/magistrala-sdk": minor
---

update users client to match Magistrala with new fields and functions
5 changes: 5 additions & 0 deletions .changeset/five-planes-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@absmach/magistrala-sdk": patch
---

update createToken example
5 changes: 5 additions & 0 deletions .changeset/serious-toys-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@absmach/magistrala-sdk": patch
---

rename password back to secret in credentials
5 changes: 5 additions & 0 deletions .changeset/twelve-pants-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@absmach/magistrala-sdk": patch
---

modify issue token function to use identity instead of username
44 changes: 35 additions & 9 deletions examples/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ const token = '<token>'

mySdk.users
.Create({
name: '<name>',
first_name: '<firstName>',
last_name: '<lastName>',
email: '<email>',
credentials: {
identity: '<useremail>',
username: '<username>',
secret: '<password>'
}
})
Expand Down Expand Up @@ -46,7 +48,7 @@ mySdk.users.UserProfile(
})

mySdk.users.CreateToken(
{ identity: '<userEmail>', secret: '<password>', domain_id: '<domainId>' }
{ identity: '<username | email>', secret: '<password>' }
)
.then((response: any) => {
console.log('response: ', response)
Expand All @@ -56,7 +58,6 @@ mySdk.users.CreateToken(
})

mySdk.users.RefreshToken(
{ identity: '<userId>' },
'<refreshToken>'
)
.then((response: any) => {
Expand All @@ -67,7 +68,7 @@ mySdk.users.RefreshToken(
})

mySdk.users.Update(
{ id: '<userId>', name: '<userName>' },
{ id: '<userId>', first_name: '<firstName>', last_name: '<lastName>' },
token
)
.then((response: any) => {
Expand All @@ -77,8 +78,30 @@ mySdk.users.Update(
console.log(error)
})

mySdk.users.UpdateUserIdentity(
{ id: '<userId>', credentials: { identity: '<userIdentity>' } },
mySdk.users.UpdateEmail(
{ id: '<userId>', email: '<email>' },
token
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.users.UpdateUsername(
{ id: '<userId>', credentials: { username: '<username>' } },
token
)
.then((response: any) => {
console.log('response: ', response)
})
.catch((error) => {
console.log(error)
})

mySdk.users.UpdateProfilePicture(
{ id: '<userId>', profile_picture: '<profilePicture>' },
token
)
.then((response: any) => {
Expand All @@ -100,7 +123,7 @@ mySdk.users.UpdateUserTags(
})

mySdk.users.UpdateUserRole(
{ id: '<userId>', role: '<userRole>' },
{ id: '<userId>', role: '<role>' },
token
)
.then((response: any) => {
Expand Down Expand Up @@ -155,6 +178,7 @@ mySdk.users.UpdateUserPassword(
})

mySdk.users.ListUserChannels(
'<domainId>',
'<userId>',
{ offset: 0, limit: 10 },
token
Expand All @@ -167,6 +191,7 @@ mySdk.users.ListUserChannels(
})

mySdk.users.ListUserThings(
'<domainId>',
'<userId>',
{ offset: 0, limit: 10 },
token
Expand All @@ -179,6 +204,7 @@ mySdk.users.ListUserThings(
})

mySdk.users.ListUserGroups(
'<domainId>',
'<userId>',
{ offset: 0, limit: 10 },
token
Expand Down Expand Up @@ -224,7 +250,7 @@ mySdk.users.DeleteUser(
})

mySdk.users.SearchUsers(
{ name: '<userName>', id: '<userId>' },
{ username: '<username>' },
token
)
.then((response: any) => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 14 additions & 5 deletions src/defs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
export interface UserBasicInfo {
id?: string
name?: string
first_name?: string
last_name?: string
email?: string
credentials?: credentials
status?: Status
profile_picture?: string
}

export interface User extends UserBasicInfo {
Expand All @@ -22,14 +25,19 @@ export interface UsersPage {
}

export interface credentials {
username?: string
secret?: string
}

export interface thingcredentials {
identity?: string
secret?: string
}

export interface ThingBasicInfo {
id?: string
name?: string
credentials?: credentials
credentials?: thingcredentials
status?: Status
}

Expand Down Expand Up @@ -106,7 +114,6 @@ export interface ChannelsPage {
export interface Login {
identity?: string
secret?: string
domain_id?: string
}

export interface Token {
Expand Down Expand Up @@ -181,8 +188,10 @@ export interface PageMetadata {
order?: string
direction?: string
level?: number
identity?: string
name?: string
email?: string
username?: string
first_name?: string
last_name?: string
type?: string
metadata?: Record<string, any>
status?: string
Expand Down
1 change: 1 addition & 0 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type {
Relation,
GroupRelation,
credentials,
thingcredentials,
UserBasicInfo,
DomainBasicInfo,
Permissions,
Expand Down
Loading

0 comments on commit e754d29

Please sign in to comment.