From 7925b8aece9532195856756ec6a56e381318c516 Mon Sep 17 00:00:00 2001 From: ianmuchyri Date: Wed, 28 Aug 2024 16:21:48 +0300 Subject: [PATCH] move host url from sdk param Signed-off-by: ianmuchyri --- .changeset/breezy-feet-kiss.md | 5 ++++ examples/users.ts | 2 +- package-lock.json | 53 +++++++++++++++++++--------------- src/sdk.ts | 4 +-- src/users.ts | 12 ++------ tests/users.test.ts | 3 +- 6 files changed, 41 insertions(+), 38 deletions(-) create mode 100644 .changeset/breezy-feet-kiss.md diff --git a/.changeset/breezy-feet-kiss.md b/.changeset/breezy-feet-kiss.md new file mode 100644 index 00000000..0cb0d687 --- /dev/null +++ b/.changeset/breezy-feet-kiss.md @@ -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 diff --git a/examples/users.ts b/examples/users.ts index dd0d77b3..92b77429 100644 --- a/examples/users.ts +++ b/examples/users.ts @@ -191,7 +191,7 @@ mySdk.users.ListUserGroups( }) mySdk.users.ResetPasswordRequest( - '' + '', '' ) .then((response: any) => { console.log('response: ', response) diff --git a/package-lock.json b/package-lock.json index 372ba10c..1c82c1a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@absmach/magistrala-sdk", - "version": "0.4.3", + "version": "0.6.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@absmach/magistrala-sdk", - "version": "0.4.3", + "version": "0.6.0", "license": "Apache-2.0", "dependencies": { "@changesets/cli": "^2.27.6", @@ -3346,11 +3346,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "license": "MIT", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -4978,9 +4979,10 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -5724,6 +5726,7 @@ "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "license": "MIT", "engines": { "node": ">=0.12.0" } @@ -7014,11 +7017,12 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", + "license": "MIT", "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -8570,6 +8574,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "license": "MIT", "dependencies": { "is-number": "^7.0.0" }, @@ -11703,11 +11708,11 @@ } }, "braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "requires": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" } }, "browserslist": { @@ -12867,9 +12872,9 @@ } }, "fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "requires": { "to-regex-range": "^5.0.1" } @@ -14380,11 +14385,11 @@ "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==" }, "micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "requires": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" } }, diff --git a/src/sdk.ts b/src/sdk.ts index d93fd42a..88317583 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -56,7 +56,6 @@ export interface SDKConfig { usersUrl?: string domainsUrl?: string thingsUrl?: string - hostUrl?: string certsUrl?: string readersUrl?: string httpAdapterUrl?: string @@ -81,7 +80,6 @@ class SDK { usersUrl = defaultUrl, domainsUrl = defaultUrl, thingsUrl = defaultUrl, - hostUrl = defaultUrl, certsUrl = defaultUrl, readersUrl = defaultUrl, httpAdapterUrl = defaultUrl, @@ -89,7 +87,7 @@ class SDK { 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) diff --git a/src/users.ts b/src/users.ts index 295e697f..56769527 100644 --- a/src/users.ts +++ b/src/users.ts @@ -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' @@ -748,7 +742,7 @@ export default class Users { } } - public async ResetPasswordRequest (email: string): Promise { + public async ResetPasswordRequest (email: string, hostUrl: string): Promise { // Sends a request to reset a password /** * @method ResetPasswordRequest - Sends a request @@ -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 }) } diff --git a/tests/users.test.ts b/tests/users.test.ts index baacc056..5188cd4c 100644 --- a/tests/users.test.ts +++ b/tests/users.test.ts @@ -100,6 +100,7 @@ describe('Users', () => { const confPass = '12345678' const oldSecret = '12345678' const newSecret = '87654321' + const hostUrl: string = 'http://localhost' beforeEach(() => { fetchMock.resetMocks() @@ -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) })