Skip to content

Commit

Permalink
move host url from sdk param
Browse files Browse the repository at this point in the history
Signed-off-by: ianmuchyri <ianmuchiri8@gmail.com>
  • Loading branch information
ianmuchyri committed Aug 28, 2024
1 parent 7197ff4 commit 7925b8a
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .changeset/breezy-feet-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@absmach/magistrala-sdk": patch
---

move host url from sdk param to specific function param. This enables flexibility of the UI to allow for multitenancy
2 changes: 1 addition & 1 deletion examples/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ mySdk.users.ListUserGroups(
})

mySdk.users.ResetPasswordRequest(
'<email>'
'<email>', '<hostUrl>'
)
.then((response: any) => {
console.log('response: ', response)
Expand Down
53 changes: 29 additions & 24 deletions package-lock.json

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

4 changes: 1 addition & 3 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export interface SDKConfig {
usersUrl?: string
domainsUrl?: string
thingsUrl?: string
hostUrl?: string
certsUrl?: string
readersUrl?: string
httpAdapterUrl?: string
Expand All @@ -81,15 +80,14 @@ class SDK {
usersUrl = defaultUrl,
domainsUrl = defaultUrl,
thingsUrl = defaultUrl,
hostUrl = defaultUrl,
certsUrl = defaultUrl,
readersUrl = defaultUrl,
httpAdapterUrl = defaultUrl,
invitationsUrl = defaultUrl,
bootstrapUrl = defaultUrl,
journalUrl = defaultUrl
}: SDKConfig = {}) {
this.users = new Users({ usersUrl, thingsUrl, hostUrl })
this.users = new Users({ usersUrl, thingsUrl })
this.domains = new Domains({ domainsUrl, usersUrl })
this.things = new Things({ thingsUrl, usersUrl })
this.certs = new Certs(certsUrl)
Expand Down
12 changes: 3 additions & 9 deletions src/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,18 @@ export default class Users {
*/
private readonly usersUrl: URL
private readonly thingsUrl?: URL
private readonly hostUrl: URL
private readonly contentType: string
private readonly usersEndpoint: string
private readonly searchEndpoint: string
private readonly userError: Errors

public constructor ({ usersUrl, thingsUrl, hostUrl }: { usersUrl: string, thingsUrl?: string, hostUrl?: string }) {
public constructor ({ usersUrl, thingsUrl }: { usersUrl: string, thingsUrl?: string }) {
this.usersUrl = new URL(usersUrl)
if (thingsUrl !== undefined) {
this.thingsUrl = new URL(thingsUrl)
} else {
this.thingsUrl = new URL('')
}
if (hostUrl !== undefined) {
this.hostUrl = new URL(hostUrl)
} else {
this.hostUrl = new URL('')
}
this.contentType = 'application/json'
this.usersEndpoint = 'users'
this.searchEndpoint = 'search'
Expand Down Expand Up @@ -748,7 +742,7 @@ export default class Users {
}
}

public async ResetPasswordRequest (email: string): Promise<Response> {
public async ResetPasswordRequest (email: string, hostUrl: string): Promise<Response> {
// Sends a request to reset a password
/**
* @method ResetPasswordRequest - Sends a request
Expand All @@ -760,7 +754,7 @@ export default class Users {
method: 'POST',
headers: {
'Content-Type': this.contentType,
Referer: this.hostUrl.toString()
Referer: hostUrl
},
body: JSON.stringify({ email })
}
Expand Down
3 changes: 2 additions & 1 deletion tests/users.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe('Users', () => {
const confPass = '12345678'
const oldSecret = '12345678'
const newSecret = '87654321'
const hostUrl: string = 'http://localhost'

beforeEach(() => {
fetchMock.resetMocks()
Expand Down Expand Up @@ -224,7 +225,7 @@ describe('Users', () => {
}
fetchMock.mockResponseOnce(JSON.stringify(resetPasswordRequestResponse))

const response = await sdk.users.ResetPasswordRequest(email)
const response = await sdk.users.ResetPasswordRequest(email, hostUrl)
expect(response).toEqual(resetPasswordRequestResponse)
})

Expand Down

0 comments on commit 7925b8a

Please sign in to comment.