From d5e247443679474a6afc3e016e69f78731ff3f35 Mon Sep 17 00:00:00 2001 From: SammyOina Date: Mon, 9 Oct 2023 12:45:32 +0300 Subject: [PATCH] prettier Signed-off-by: SammyOina --- .github/ISSUE_TEMPLATE.md | 4 +- .github/PULL_REQUEST_TEMPLATE.md | 3 +- .gitignore | 1 - .prettierignore | 2 + .prettierrc | 1 + dist/main.js | 2900 ++++++++++++++++++++++++++++++ package-lock.json | 22 + package.json | 1 + src/examples/examples.js | 16 +- src/index.js | 4 +- src/mainflux/bootstrap.js | 76 +- src/mainflux/certs.js | 44 +- src/mainflux/channels.js | 47 +- src/mainflux/errors.js | 32 +- src/mainflux/groups.js | 20 +- src/mainflux/messages.js | 47 +- src/mainflux/sdk.js | 2 +- src/mainflux/things.js | 118 +- src/mainflux/users.js | 111 +- tests/bootstraps.test.js | 163 +- tests/certs.test.js | 65 +- tests/channels.test.js | 293 ++- tests/groups.test.js | 353 ++-- tests/messages.test.js | 24 +- tests/things.test.js | 433 ++++- tests/users.test.js | 202 +-- 26 files changed, 4471 insertions(+), 513 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc create mode 100644 dist/main.js diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index db6ff55d..ee838dc3 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -30,11 +30,13 @@ the following locations: 6. Additional information you deem important: **ENHANCEMENT** + 1. Describe the enhancement you are requesting. Enhancements include: + - tests - code refactor - documentation - research - tooling -2. Indicate the importance of this enhancement to you (must-have, should-have, nice-to-have). \ No newline at end of file +2. Indicate the importance of this enhancement to you (must-have, should-have, nice-to-have). diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 70627d5a..764a06ce 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -4,6 +4,7 @@ Please review the [CONTRIBUTING.md](./CONTRIBUTING.md) file for detailed contrib ### What does this do? ### Which issue(s) does this PR fix/relate to? + Put here `Resolves #XXX` to auto-close the issue that your PR fixes (if such) ### List any changes that modify/break current functionality @@ -12,4 +13,4 @@ Put here `Resolves #XXX` to auto-close the issue that your PR fixes (if such) ### Did you document any new/modified functionality? -### Notes \ No newline at end of file +### Notes diff --git a/.gitignore b/.gitignore index 761ac79d..83fd372d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ # See http://help.github.com/ignore-files/ for more about ignoring files. # compiled output -/dist /tmp /out-tsc diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..51e3286f --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +# Ignore artifacts: +node_modules diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000..0967ef42 --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +{} diff --git a/dist/main.js b/dist/main.js new file mode 100644 index 00000000..87a4d12c --- /dev/null +++ b/dist/main.js @@ -0,0 +1,2900 @@ +(() => { + var t = { + 138: (t, e, n) => { + const r = n(864); + t.exports = r; + }, + 793: (t, e, n) => { + const r = n(218); + t.exports = class { + constructor(t) { + (this.bootstraps_url = t), + (this.content_type = "application/json"), + (this.bootstrapsEndpoint = "configs"); + } + Create(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.bootstraps_url}/things/${this.bootstrapsEndpoint}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => "Configuration added") + .catch((t) => t.response.data); + } + Whitelist(t, e) { + const n = { + method: "put", + maxBodyLength: 1 / 0, + url: `${this.bootstraps_url}/things/state/${t.thing_id}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => "Configuration updated") + .catch((t) => t.response.data); + } + Update(t, e) { + const n = { + method: "put", + maxBodyLength: 1 / 0, + url: `${this.bootstraps_url}/things/configs/${t.thing_id}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => "Configuration updated") + .catch((t) => t.response.data); + } + View(t, e) { + const n = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.bootstraps_url}/things/${this.bootstrapsEndpoint}/${t}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + UpdateCerts(t, e, n, s, o) { + const i = { client_cert: e, client_key: n, ca_cert: s }, + a = { + method: "patch", + maxBodyLength: 1 / 0, + url: `${this.bootstraps_url}/configs/certs/${t}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${o}`, + }, + data: JSON.stringify(i), + }; + return r + .request(a) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Remove(t, e) { + const n = { + method: "delete", + maxBodyLength: 1 / 0, + url: `${this.bootstraps_url}/things/${this.bootstrapsEndpoint}/${t}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => "Configuration removed") + .catch((t) => t.response.data); + } + Bootstrap(t, e) { + const n = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.bootstraps_url}/things/bootstrap/${t}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Thing ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + }; + }, + 300: (t, e, n) => { + const r = n(218); + t.exports = class { + constructor(t) { + (this.certs_url = t), + (this.content_type = "application/json"), + (this.certsEndpoint = "certs"); + } + Issue(t, e, n) { + const s = { thing_id: t, ttl: e }, + o = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.certs_url}/${this.certsEndpoint}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + data: JSON.stringify(s), + }; + return r + .request(o) + .then((t) => t.data) + .catch((t) => t.response.data); + } + ViewByThing(t, e) { + const n = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.certs_url}/serials/${t}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + ViewBySerial(t, e) { + const n = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.certs_url}/${this.certsEndpoint}/${t}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Revoke(t, e) { + const n = { + method: "delete", + maxBodyLength: 1 / 0, + url: `${this.certs_url}/${this.certsEndpoint}/${t}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => "DELETED") + .catch((t) => t.response.data); + } + }; + }, + 898: (t, e, n) => { + const r = n(218); + t.exports = class { + constructor(t) { + (this.channels_url = t), + (this.content_type = "application/json"), + (this.channelsEndpoint = "channels"); + } + Create(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.channels_url}/${this.channelsEndpoint}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + CreateBulk(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.channels_url}/${this.channelsEndpoint}/bulk`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Get(t, e) { + const n = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.channels_url}/${this.channelsEndpoint}/${t}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + GetByThing(t, e, n) { + const s = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.channels_url}/${ + this.channelsEndpoint + }/${t}/things?${new URLSearchParams(e).toString()}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + }; + return r + .request(s) + .then((t) => t.data) + .catch((t) => t.response.data); + } + GetAll(t, e) { + const n = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.channels_url}/${ + this.channelsEndpoint + }?${new URLSearchParams(t).toString()}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Update(t, e) { + const n = { + method: "put", + maxBodyLength: 1 / 0, + url: `${this.channels_url}/${this.channelsEndpoint}/${t.id}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Disable(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.channels_url}/${this.channelsEndpoint}/${t.id}/disable`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + }; + }, + 583: (t, e, n) => { + const r = n(218); + t.exports = class { + constructor(t) { + (this.groups_url = t), + (this.content_type = "application/json"), + (this.groupsEndpoint = "groups"); + } + Create(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.groups_url}/${this.groupsEndpoint}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Get(t, e) { + const n = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.groups_url}/${this.groupsEndpoint}/${t}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + GetAll(t, e) { + const n = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.groups_url}/${ + this.groupsEndpoint + }?${new URLSearchParams(t).toString()}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Update(t, e) { + const n = { + method: "put", + maxBodyLength: 1 / 0, + url: `${this.groups_url}/${this.groupsEndpoint}/${t.id}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Children(t, e, n) { + const s = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.groups_url}/${ + this.groupsEndpoint + }/${t}/children?${new URLSearchParams(e).toString()}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + }; + return r + .request(s) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Parents(t, e, n) { + const s = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.groups_url}/${this.groupsEndpoint}/${ + t.id + }/parents?${new URLSearchParams(e).toString()}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + }; + return r + .request(s) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Assign(t, e, n, s) { + const o = { object: t, subject: e, actions: n }, + i = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.groups_url}/policies`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${s}`, + }, + data: JSON.stringify(o), + }; + return r + .request(i) + .then((t) => "Policy created") + .catch((t) => t.response.data); + } + Unassign(t, e, n) { + const s = { object: e, subject: t }, + o = { + method: "delete", + maxBodyLength: 1 / 0, + url: `${this.groups_url}/policies/${t}/${e}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + data: JSON.stringify(s), + }; + return r + .request(o) + .then((t) => "Policy deleted") + .catch((t) => t.response.data); + } + Disable(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.groups_url}/${this.groupsEndpoint}/${t}/disable`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Members(t, e, n) { + const s = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.groups_url}/${ + this.groupsEndpoint + }/${t}/members?${new URLSearchParams(e).toString()}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + }; + return r + .request(s) + .then((t) => t.data) + .catch((t) => t.response.data); + } + }; + }, + 692: (t, e, n) => { + const r = n(218); + t.exports = class { + constructor(t, e) { + (this.readers_url = t), + (this.httpadapter_url = e), + (this.content_type = "application/json"); + } + Send(t, e, n) { + const s = t.split(".", 2), + o = s[0]; + let i = ""; + 2 == s.length && s[1].replace(".", "/", -1); + const a = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.httpadapter_url}/http/channels/${o}/messages/subtopic`, + headers: { + "Content-Type": this.content_type, + Authorization: `Thing ${n}`, + }, + data: new TextEncoder().encode(e), + }; + return r + .request(a) + .then((t) => "Message Sent!") + .catch((t) => t.response.data); + } + Read(t, e) { + const n = t.split(".", 2), + s = n[0]; + let o = ""; + 2 == n.length && (o = n[1].replace(".", "/", -1)); + const i = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.readers_url}/channels/${s}/messages`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + params: { subtopic: o }, + }; + return r + .request(i) + .then((t) => t.data) + .catch((t) => t.response.data); + } + }; + }, + 864: (t, e, n) => { + const r = n(129), + s = n(738), + o = n(583), + i = n(898), + a = n(300), + c = n(793), + h = n(692), + u = "http://localhost"; + class d { + constructor({ + usersUrl: t = u, + thingsUrl: e = u, + groupsUrl: n = u, + channelsUrl: d = u, + certsUrl: l = u, + bootstrapsUrl: p = u, + readersUrl: f = u, + httpadapterUrl: y = u, + } = {}) { + (this.users = new r(t)), + (this.things = new s(e)), + (this.groups = new o(n)), + (this.channels = new i(d)), + (this.certs = new a(l)), + (this.bootstrap = new c(p)), + (this.messages = new h(f, y)); + } + } + void 0 !== t.exports ? (t.exports = d) : (window.SDK = d); + }, + 738: (t, e, n) => { + const r = n(218); + t.exports = class { + constructor(t) { + (this.things_url = t), + (this.content_type = "application/json"), + (this.thingsEndpoint = "things"); + } + Create(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.things_url}/${this.thingsEndpoint}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + CreateBulk(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.things_url}/${this.thingsEndpoint}/bulk`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Get(t, e) { + const n = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.things_url}/${this.thingsEndpoint}/${t}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + GetByChannel(t, e, n) { + const s = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.things_url}/${ + this.thingsEndpoint + }/${t}/channels?${new URLSearchParams(e).toString()}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + }; + return r + .request(s) + .then((t) => t.data) + .catch((t) => t.response.data); + } + GetAll(t, e) { + const n = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.things_url}/${ + this.thingsEndpoint + }?${new URLSearchParams(t).toString()}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Disable(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.things_url}/${this.thingsEndpoint}/${t}/disable`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Update(t, e, n) { + const s = { + method: "patch", + maxBodyLength: 1 / 0, + url: `${this.things_url}/${this.thingsEndpoint}/${t}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + data: JSON.stringify(e), + }; + return r + .request(s) + .then((t) => t.data) + .catch((t) => t.response.data); + } + UpdateThingSecret(t, e, n) { + const s = { + method: "patch", + maxBodyLength: 1 / 0, + url: `${this.things_url}/${this.thingsEndpoint}/${t}/secret`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + data: JSON.stringify(e), + }; + return r + .request(s) + .then((t) => t.data) + .catch((t) => t.response.data); + } + UpdateThingTags(t, e, n) { + const s = { + method: "patch", + maxBodyLength: 1 / 0, + url: `${this.things_url}/${this.thingsEndpoint}/${t}/tags`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + data: JSON.stringify(e), + }; + return r + .request(s) + .then((t) => t.data) + .catch((t) => t.response.data); + } + UpdateThingOwner(t, e, n) { + const s = { + method: "patch", + maxBodyLength: 1 / 0, + url: `${this.things_url}/${this.thingsEndpoint}/${t}/owner`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + data: JSON.stringify(e), + }; + return r + .request(s) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Connect(t, e, n, s) { + const o = { subject: t, object: e, action: n }, + i = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.things_url}/policies`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${s}`, + }, + data: JSON.stringify(o), + }; + return r + .request(i) + .then((t) => "Policy created.") + .catch((t) => t.response.data); + } + Connects(t, e, n, s) { + const o = { subjects: t, objects: e, actions: n }, + i = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.things_url}/connect`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${s}`, + }, + data: JSON.stringify(o), + }; + return r + .request(i) + .then((t) => "Policy created.") + .catch((t) => t.response.data); + } + Disconnect(t, e, n) { + const s = { subjects: t, objects: e }, + o = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.things_url}/disconnect`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + data: JSON.stringify(s), + }; + return r + .request(o) + .then((t) => "Policy deleted.") + .catch((t) => t.response.data); + } + IdentifyThing(t) { + const e = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.things_url}/identify`, + headers: { + "Content-Type": this.content_type, + Authorization: `Thing ${t}`, + }, + }; + return r + .request(e) + .then((t) => t.data) + .catch((t) => t.response.data); + } + AuthoriseThing(t, e, n, s, o) { + const i = { subject: t, object: e, action: n, entity_type: s }, + a = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.things_url}/channels/object/access`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${o}`, + }, + data: JSON.stringify(i), + }; + return r + .request(a) + .then((t) => !0) + .catch((t) => !1); + } + }; + }, + 129: (t, e, n) => { + const r = n(218); + t.exports = class { + constructor(t) { + (this.users_url = t), + (this.content_type = "application/json"), + (this.usersEndpoint = "users"); + } + Create(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.users_url}/${this.usersEndpoint}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Login(t) { + const e = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.users_url}/${this.usersEndpoint}/tokens/issue`, + headers: { "Content-Type": this.content_type }, + data: JSON.stringify(t), + }; + return r + .request(e) + .then((t) => t.data) + .catch((t) => t); + } + RefreshToken(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.users_url}/${this.usersEndpoint}/tokens/refresh`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t); + } + Update(t, e) { + const n = { + method: "patch", + url: `${this.users_url}/${this.usersEndpoint}/${t.id}`, + maxBodyLength: 1 / 0, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + UpdateUserIdentity(t, e) { + const n = { + method: "patch", + url: `${this.users_url}/${this.usersEndpoint}/${t.id}/identity`, + maxBodyLength: 1 / 0, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + UpdateUserTags(t, e) { + const n = { + method: "patch", + url: `${this.users_url}/${this.usersEndpoint}/${t.id}/tags`, + maxBodyLength: 1 / 0, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + UpdateUserOwner(t, e) { + const n = { + method: "patch", + url: `${this.users_url}/${this.usersEndpoint}/${t.id}/owner`, + maxBodyLength: 1 / 0, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + UpdateUserPassword(t, e, n) { + const s = { old_secret: t, new_secret: e }, + o = { + method: "patch", + url: `${this.users_url}/${this.usersEndpoint}/secret`, + maxBodyLength: 1 / 0, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + data: JSON.stringify(s), + }; + return r + .request(o) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Get(t, e) { + const n = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.users_url}/${this.usersEndpoint}/${t}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + GetAll(t, e) { + const n = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.users_url}/${ + this.usersEndpoint + }?${new URLSearchParams(t).toString()}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Disable(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.users_url}/${this.usersEndpoint}/${t.id}/disable`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Enable(t, e) { + const n = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.users_url}/${this.usersEndpoint}/${t.id}/enable`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${e}`, + }, + data: JSON.stringify(t), + }; + return r + .request(n) + .then((t) => t.data) + .catch((t) => t.response.data); + } + Memberships(t, e, n) { + const s = { + method: "get", + maxBodyLength: 1 / 0, + url: `${this.users_url}/${ + this.usersEndpoint + }/${t}/memberships?${new URLSearchParams(e).toString()}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${n}`, + }, + params: e, + }; + return r + .request(s) + .then((t) => t.data) + .catch((t) => t.response.data); + } + AuthoriseUser(t, e, n, s, o) { + const i = { subject: t, object: e, action: n, entity_type: s }, + a = { + method: "post", + maxBodyLength: 1 / 0, + url: `${this.users_url}/authorize`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${o}`, + }, + data: JSON.stringify(i), + }; + return r + .request(a) + .then((t) => !0) + .catch((t) => !1); + } + }; + }, + 218: (t, e, n) => { + "use strict"; + function r(t, e) { + return function () { + return t.apply(e, arguments); + }; + } + const { toString: s } = Object.prototype, + { getPrototypeOf: o } = Object, + i = + ((a = Object.create(null)), + (t) => { + const e = s.call(t); + return a[e] || (a[e] = e.slice(8, -1).toLowerCase()); + }); + var a; + const c = (t) => ((t = t.toLowerCase()), (e) => i(e) === t), + h = (t) => (e) => typeof e === t, + { isArray: u } = Array, + d = h("undefined"), + l = c("ArrayBuffer"), + p = h("string"), + f = h("function"), + y = h("number"), + m = (t) => null !== t && "object" == typeof t, + g = (t) => { + if ("object" !== i(t)) return !1; + const e = o(t); + return !( + (null !== e && + e !== Object.prototype && + null !== Object.getPrototypeOf(e)) || + Symbol.toStringTag in t || + Symbol.iterator in t + ); + }, + b = c("Date"), + $ = c("File"), + E = c("Blob"), + _ = c("FileList"), + w = c("URLSearchParams"); + function S(t, e, { allOwnKeys: n = !1 } = {}) { + if (null == t) return; + let r, s; + if (("object" != typeof t && (t = [t]), u(t))) + for (r = 0, s = t.length; r < s; r++) e.call(null, t[r], r, t); + else { + const s = n ? Object.getOwnPropertyNames(t) : Object.keys(t), + o = s.length; + let i; + for (r = 0; r < o; r++) (i = s[r]), e.call(null, t[i], i, t); + } + } + function B(t, e) { + e = e.toLowerCase(); + const n = Object.keys(t); + let r, + s = n.length; + for (; s-- > 0; ) if (((r = n[s]), e === r.toLowerCase())) return r; + return null; + } + const O = + "undefined" != typeof globalThis + ? globalThis + : "undefined" != typeof self + ? self + : "undefined" != typeof window + ? window + : n.g, + T = (t) => !d(t) && t !== O, + A = + ((C = "undefined" != typeof Uint8Array && o(Uint8Array)), + (t) => C && t instanceof C); + var C; + const x = c("HTMLFormElement"), + R = ( + ({ hasOwnProperty: t }) => + (e, n) => + t.call(e, n) + )(Object.prototype), + L = c("RegExp"), + N = (t, e) => { + const n = Object.getOwnPropertyDescriptors(t), + r = {}; + S(n, (n, s) => { + let o; + !1 !== (o = e(n, s, t)) && (r[s] = o || n); + }), + Object.defineProperties(t, r); + }, + j = "abcdefghijklmnopqrstuvwxyz", + v = "0123456789", + U = { DIGIT: v, ALPHA: j, ALPHA_DIGIT: j + j.toUpperCase() + v }, + P = c("AsyncFunction"); + var q = { + isArray: u, + isArrayBuffer: l, + isBuffer: function (t) { + return ( + null !== t && + !d(t) && + null !== t.constructor && + !d(t.constructor) && + f(t.constructor.isBuffer) && + t.constructor.isBuffer(t) + ); + }, + isFormData: (t) => { + let e; + return ( + t && + (("function" == typeof FormData && t instanceof FormData) || + (f(t.append) && + ("formdata" === (e = i(t)) || + ("object" === e && + f(t.toString) && + "[object FormData]" === t.toString())))) + ); + }, + isArrayBufferView: function (t) { + let e; + return ( + (e = + "undefined" != typeof ArrayBuffer && ArrayBuffer.isView + ? ArrayBuffer.isView(t) + : t && t.buffer && l(t.buffer)), + e + ); + }, + isString: p, + isNumber: y, + isBoolean: (t) => !0 === t || !1 === t, + isObject: m, + isPlainObject: g, + isUndefined: d, + isDate: b, + isFile: $, + isBlob: E, + isRegExp: L, + isFunction: f, + isStream: (t) => m(t) && f(t.pipe), + isURLSearchParams: w, + isTypedArray: A, + isFileList: _, + forEach: S, + merge: function t() { + const { caseless: e } = (T(this) && this) || {}, + n = {}, + r = (r, s) => { + const o = (e && B(n, s)) || s; + g(n[o]) && g(r) + ? (n[o] = t(n[o], r)) + : g(r) + ? (n[o] = t({}, r)) + : u(r) + ? (n[o] = r.slice()) + : (n[o] = r); + }; + for (let t = 0, e = arguments.length; t < e; t++) + arguments[t] && S(arguments[t], r); + return n; + }, + extend: (t, e, n, { allOwnKeys: s } = {}) => ( + S( + e, + (e, s) => { + n && f(e) ? (t[s] = r(e, n)) : (t[s] = e); + }, + { allOwnKeys: s }, + ), + t + ), + trim: (t) => + t.trim + ? t.trim() + : t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ""), + stripBOM: (t) => (65279 === t.charCodeAt(0) && (t = t.slice(1)), t), + inherits: (t, e, n, r) => { + (t.prototype = Object.create(e.prototype, r)), + (t.prototype.constructor = t), + Object.defineProperty(t, "super", { value: e.prototype }), + n && Object.assign(t.prototype, n); + }, + toFlatObject: (t, e, n, r) => { + let s, i, a; + const c = {}; + if (((e = e || {}), null == t)) return e; + do { + for (s = Object.getOwnPropertyNames(t), i = s.length; i-- > 0; ) + (a = s[i]), + (r && !r(a, t, e)) || c[a] || ((e[a] = t[a]), (c[a] = !0)); + t = !1 !== n && o(t); + } while (t && (!n || n(t, e)) && t !== Object.prototype); + return e; + }, + kindOf: i, + kindOfTest: c, + endsWith: (t, e, n) => { + (t = String(t)), + (void 0 === n || n > t.length) && (n = t.length), + (n -= e.length); + const r = t.indexOf(e, n); + return -1 !== r && r === n; + }, + toArray: (t) => { + if (!t) return null; + if (u(t)) return t; + let e = t.length; + if (!y(e)) return null; + const n = new Array(e); + for (; e-- > 0; ) n[e] = t[e]; + return n; + }, + forEachEntry: (t, e) => { + const n = (t && t[Symbol.iterator]).call(t); + let r; + for (; (r = n.next()) && !r.done; ) { + const n = r.value; + e.call(t, n[0], n[1]); + } + }, + matchAll: (t, e) => { + let n; + const r = []; + for (; null !== (n = t.exec(e)); ) r.push(n); + return r; + }, + isHTMLForm: x, + hasOwnProperty: R, + hasOwnProp: R, + reduceDescriptors: N, + freezeMethods: (t) => { + N(t, (e, n) => { + if (f(t) && -1 !== ["arguments", "caller", "callee"].indexOf(n)) + return !1; + const r = t[n]; + f(r) && + ((e.enumerable = !1), + "writable" in e + ? (e.writable = !1) + : e.set || + (e.set = () => { + throw Error( + "Can not rewrite read-only method '" + n + "'", + ); + })); + }); + }, + toObjectSet: (t, e) => { + const n = {}, + r = (t) => { + t.forEach((t) => { + n[t] = !0; + }); + }; + return u(t) ? r(t) : r(String(t).split(e)), n; + }, + toCamelCase: (t) => + t + .toLowerCase() + .replace(/[-_\s]([a-z\d])(\w*)/g, function (t, e, n) { + return e.toUpperCase() + n; + }), + noop: () => {}, + toFiniteNumber: (t, e) => ((t = +t), Number.isFinite(t) ? t : e), + findKey: B, + global: O, + isContextDefined: T, + ALPHABET: U, + generateString: (t = 16, e = U.ALPHA_DIGIT) => { + let n = ""; + const { length: r } = e; + for (; t--; ) n += e[(Math.random() * r) | 0]; + return n; + }, + isSpecCompliantForm: function (t) { + return !!( + t && + f(t.append) && + "FormData" === t[Symbol.toStringTag] && + t[Symbol.iterator] + ); + }, + toJSONObject: (t) => { + const e = new Array(10), + n = (t, r) => { + if (m(t)) { + if (e.indexOf(t) >= 0) return; + if (!("toJSON" in t)) { + e[r] = t; + const s = u(t) ? [] : {}; + return ( + S(t, (t, e) => { + const o = n(t, r + 1); + !d(o) && (s[e] = o); + }), + (e[r] = void 0), + s + ); + } + } + return t; + }; + return n(t, 0); + }, + isAsyncFn: P, + isThenable: (t) => t && (m(t) || f(t)) && f(t.then) && f(t.catch), + }; + function z(t, e, n, r, s) { + Error.call(this), + Error.captureStackTrace + ? Error.captureStackTrace(this, this.constructor) + : (this.stack = new Error().stack), + (this.message = t), + (this.name = "AxiosError"), + e && (this.code = e), + n && (this.config = n), + r && (this.request = r), + s && (this.response = s); + } + q.inherits(z, Error, { + toJSON: function () { + return { + message: this.message, + name: this.name, + description: this.description, + number: this.number, + fileName: this.fileName, + lineNumber: this.lineNumber, + columnNumber: this.columnNumber, + stack: this.stack, + config: q.toJSONObject(this.config), + code: this.code, + status: + this.response && this.response.status + ? this.response.status + : null, + }; + }, + }); + const D = z.prototype, + F = {}; + function k(t) { + return q.isPlainObject(t) || q.isArray(t); + } + function J(t) { + return q.endsWith(t, "[]") ? t.slice(0, -2) : t; + } + function I(t, e, n) { + return t + ? t + .concat(e) + .map(function (t, e) { + return (t = J(t)), !n && e ? "[" + t + "]" : t; + }) + .join(n ? "." : "") + : e; + } + [ + "ERR_BAD_OPTION_VALUE", + "ERR_BAD_OPTION", + "ECONNABORTED", + "ETIMEDOUT", + "ERR_NETWORK", + "ERR_FR_TOO_MANY_REDIRECTS", + "ERR_DEPRECATED", + "ERR_BAD_RESPONSE", + "ERR_BAD_REQUEST", + "ERR_CANCELED", + "ERR_NOT_SUPPORT", + "ERR_INVALID_URL", + ].forEach((t) => { + F[t] = { value: t }; + }), + Object.defineProperties(z, F), + Object.defineProperty(D, "isAxiosError", { value: !0 }), + (z.from = (t, e, n, r, s, o) => { + const i = Object.create(D); + return ( + q.toFlatObject( + t, + i, + function (t) { + return t !== Error.prototype; + }, + (t) => "isAxiosError" !== t, + ), + z.call(i, t.message, e, n, r, s), + (i.cause = t), + (i.name = t.name), + o && Object.assign(i, o), + i + ); + }); + const M = q.toFlatObject(q, {}, null, function (t) { + return /^is[A-Z]/.test(t); + }); + function H(t, e, n) { + if (!q.isObject(t)) throw new TypeError("target must be an object"); + e = e || new FormData(); + const r = (n = q.toFlatObject( + n, + { metaTokens: !0, dots: !1, indexes: !1 }, + !1, + function (t, e) { + return !q.isUndefined(e[t]); + }, + )).metaTokens, + s = n.visitor || h, + o = n.dots, + i = n.indexes, + a = + (n.Blob || ("undefined" != typeof Blob && Blob)) && + q.isSpecCompliantForm(e); + if (!q.isFunction(s)) + throw new TypeError("visitor must be a function"); + function c(t) { + if (null === t) return ""; + if (q.isDate(t)) return t.toISOString(); + if (!a && q.isBlob(t)) + throw new z("Blob is not supported. Use a Buffer instead."); + return q.isArrayBuffer(t) || q.isTypedArray(t) + ? a && "function" == typeof Blob + ? new Blob([t]) + : Buffer.from(t) + : t; + } + function h(t, n, s) { + let a = t; + if (t && !s && "object" == typeof t) + if (q.endsWith(n, "{}")) + (n = r ? n : n.slice(0, -2)), (t = JSON.stringify(t)); + else if ( + (q.isArray(t) && + (function (t) { + return q.isArray(t) && !t.some(k); + })(t)) || + ((q.isFileList(t) || q.endsWith(n, "[]")) && (a = q.toArray(t))) + ) + return ( + (n = J(n)), + a.forEach(function (t, r) { + !q.isUndefined(t) && + null !== t && + e.append( + !0 === i ? I([n], r, o) : null === i ? n : n + "[]", + c(t), + ); + }), + !1 + ); + return !!k(t) || (e.append(I(s, n, o), c(t)), !1); + } + const u = [], + d = Object.assign(M, { + defaultVisitor: h, + convertValue: c, + isVisitable: k, + }); + if (!q.isObject(t)) throw new TypeError("data must be an object"); + return ( + (function t(n, r) { + if (!q.isUndefined(n)) { + if (-1 !== u.indexOf(n)) + throw Error("Circular reference detected in " + r.join(".")); + u.push(n), + q.forEach(n, function (n, o) { + !0 === + (!(q.isUndefined(n) || null === n) && + s.call(e, n, q.isString(o) ? o.trim() : o, r, d)) && + t(n, r ? r.concat(o) : [o]); + }), + u.pop(); + } + })(t), + e + ); + } + function G(t) { + const e = { + "!": "%21", + "'": "%27", + "(": "%28", + ")": "%29", + "~": "%7E", + "%20": "+", + "%00": "\0", + }; + return encodeURIComponent(t).replace( + /[!'()~]|%20|%00/g, + function (t) { + return e[t]; + }, + ); + } + function V(t, e) { + (this._pairs = []), t && H(t, this, e); + } + const W = V.prototype; + function K(t) { + return encodeURIComponent(t) + .replace(/%3A/gi, ":") + .replace(/%24/g, "$") + .replace(/%2C/gi, ",") + .replace(/%20/g, "+") + .replace(/%5B/gi, "[") + .replace(/%5D/gi, "]"); + } + function X(t, e, n) { + if (!e) return t; + const r = (n && n.encode) || K, + s = n && n.serialize; + let o; + if ( + ((o = s + ? s(e, n) + : q.isURLSearchParams(e) + ? e.toString() + : new V(e, n).toString(r)), + o) + ) { + const e = t.indexOf("#"); + -1 !== e && (t = t.slice(0, e)), + (t += (-1 === t.indexOf("?") ? "?" : "&") + o); + } + return t; + } + (W.append = function (t, e) { + this._pairs.push([t, e]); + }), + (W.toString = function (t) { + const e = t + ? function (e) { + return t.call(this, e, G); + } + : G; + return this._pairs + .map(function (t) { + return e(t[0]) + "=" + e(t[1]); + }, "") + .join("&"); + }); + var Q = class { + constructor() { + this.handlers = []; + } + use(t, e, n) { + return ( + this.handlers.push({ + fulfilled: t, + rejected: e, + synchronous: !!n && n.synchronous, + runWhen: n ? n.runWhen : null, + }), + this.handlers.length - 1 + ); + } + eject(t) { + this.handlers[t] && (this.handlers[t] = null); + } + clear() { + this.handlers && (this.handlers = []); + } + forEach(t) { + q.forEach(this.handlers, function (e) { + null !== e && t(e); + }); + } + }, + Z = { + silentJSONParsing: !0, + forcedJSONParsing: !0, + clarifyTimeoutError: !1, + }, + Y = { + isBrowser: !0, + classes: { + URLSearchParams: + "undefined" != typeof URLSearchParams ? URLSearchParams : V, + FormData: "undefined" != typeof FormData ? FormData : null, + Blob: "undefined" != typeof Blob ? Blob : null, + }, + isStandardBrowserEnv: (() => { + let t; + return ( + ("undefined" == typeof navigator || + ("ReactNative" !== (t = navigator.product) && + "NativeScript" !== t && + "NS" !== t)) && + "undefined" != typeof window && + "undefined" != typeof document + ); + })(), + isStandardBrowserWebWorkerEnv: + "undefined" != typeof WorkerGlobalScope && + self instanceof WorkerGlobalScope && + "function" == typeof self.importScripts, + protocols: ["http", "https", "file", "blob", "url", "data"], + }; + function tt(t) { + function e(t, n, r, s) { + let o = t[s++]; + const i = Number.isFinite(+o), + a = s >= t.length; + return ( + (o = !o && q.isArray(r) ? r.length : o), + a + ? (q.hasOwnProp(r, o) ? (r[o] = [r[o], n]) : (r[o] = n), !i) + : ((r[o] && q.isObject(r[o])) || (r[o] = []), + e(t, n, r[o], s) && + q.isArray(r[o]) && + (r[o] = (function (t) { + const e = {}, + n = Object.keys(t); + let r; + const s = n.length; + let o; + for (r = 0; r < s; r++) (o = n[r]), (e[o] = t[o]); + return e; + })(r[o])), + !i) + ); + } + if (q.isFormData(t) && q.isFunction(t.entries)) { + const n = {}; + return ( + q.forEachEntry(t, (t, r) => { + e( + (function (t) { + return q + .matchAll(/\w+|\[(\w*)]/g, t) + .map((t) => ("[]" === t[0] ? "" : t[1] || t[0])); + })(t), + r, + n, + 0, + ); + }), + n + ); + } + return null; + } + const et = { + transitional: Z, + adapter: ["xhr", "http"], + transformRequest: [ + function (t, e) { + const n = e.getContentType() || "", + r = n.indexOf("application/json") > -1, + s = q.isObject(t); + if ( + (s && q.isHTMLForm(t) && (t = new FormData(t)), q.isFormData(t)) + ) + return r && r ? JSON.stringify(tt(t)) : t; + if ( + q.isArrayBuffer(t) || + q.isBuffer(t) || + q.isStream(t) || + q.isFile(t) || + q.isBlob(t) + ) + return t; + if (q.isArrayBufferView(t)) return t.buffer; + if (q.isURLSearchParams(t)) + return ( + e.setContentType( + "application/x-www-form-urlencoded;charset=utf-8", + !1, + ), + t.toString() + ); + let o; + if (s) { + if (n.indexOf("application/x-www-form-urlencoded") > -1) + return (function (t, e) { + return H( + t, + new Y.classes.URLSearchParams(), + Object.assign( + { + visitor: function (t, e, n, r) { + return Y.isNode && q.isBuffer(t) + ? (this.append(e, t.toString("base64")), !1) + : r.defaultVisitor.apply(this, arguments); + }, + }, + e, + ), + ); + })(t, this.formSerializer).toString(); + if ( + (o = q.isFileList(t)) || + n.indexOf("multipart/form-data") > -1 + ) { + const e = this.env && this.env.FormData; + return H( + o ? { "files[]": t } : t, + e && new e(), + this.formSerializer, + ); + } + } + return s || r + ? (e.setContentType("application/json", !1), + (function (t, e, n) { + if (q.isString(t)) + try { + return (0, JSON.parse)(t), q.trim(t); + } catch (t) { + if ("SyntaxError" !== t.name) throw t; + } + return (0, JSON.stringify)(t); + })(t)) + : t; + }, + ], + transformResponse: [ + function (t) { + const e = this.transitional || et.transitional, + n = e && e.forcedJSONParsing, + r = "json" === this.responseType; + if (t && q.isString(t) && ((n && !this.responseType) || r)) { + const n = !(e && e.silentJSONParsing) && r; + try { + return JSON.parse(t); + } catch (t) { + if (n) { + if ("SyntaxError" === t.name) + throw z.from( + t, + z.ERR_BAD_RESPONSE, + this, + null, + this.response, + ); + throw t; + } + } + } + return t; + }, + ], + timeout: 0, + xsrfCookieName: "XSRF-TOKEN", + xsrfHeaderName: "X-XSRF-TOKEN", + maxContentLength: -1, + maxBodyLength: -1, + env: { FormData: Y.classes.FormData, Blob: Y.classes.Blob }, + validateStatus: function (t) { + return t >= 200 && t < 300; + }, + headers: { + common: { + Accept: "application/json, text/plain, */*", + "Content-Type": void 0, + }, + }, + }; + q.forEach(["delete", "get", "head", "post", "put", "patch"], (t) => { + et.headers[t] = {}; + }); + var nt = et; + const rt = q.toObjectSet([ + "age", + "authorization", + "content-length", + "content-type", + "etag", + "expires", + "from", + "host", + "if-modified-since", + "if-unmodified-since", + "last-modified", + "location", + "max-forwards", + "proxy-authorization", + "referer", + "retry-after", + "user-agent", + ]), + st = Symbol("internals"); + function ot(t) { + return t && String(t).trim().toLowerCase(); + } + function it(t) { + return !1 === t || null == t + ? t + : q.isArray(t) + ? t.map(it) + : String(t); + } + function at(t, e, n, r, s) { + return q.isFunction(r) + ? r.call(this, e, n) + : (s && (e = n), + q.isString(e) + ? q.isString(r) + ? -1 !== e.indexOf(r) + : q.isRegExp(r) + ? r.test(e) + : void 0 + : void 0); + } + class ct { + constructor(t) { + t && this.set(t); + } + set(t, e, n) { + const r = this; + function s(t, e, n) { + const s = ot(e); + if (!s) throw new Error("header name must be a non-empty string"); + const o = q.findKey(r, s); + (!o || + void 0 === r[o] || + !0 === n || + (void 0 === n && !1 !== r[o])) && + (r[o || e] = it(t)); + } + const o = (t, e) => q.forEach(t, (t, n) => s(t, n, e)); + return ( + q.isPlainObject(t) || t instanceof this.constructor + ? o(t, e) + : q.isString(t) && + (t = t.trim()) && + !/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(t.trim()) + ? o( + ((t) => { + const e = {}; + let n, r, s; + return ( + t && + t.split("\n").forEach(function (t) { + (s = t.indexOf(":")), + (n = t.substring(0, s).trim().toLowerCase()), + (r = t.substring(s + 1).trim()), + !n || + (e[n] && rt[n]) || + ("set-cookie" === n + ? e[n] + ? e[n].push(r) + : (e[n] = [r]) + : (e[n] = e[n] ? e[n] + ", " + r : r)); + }), + e + ); + })(t), + e, + ) + : null != t && s(e, t, n), + this + ); + } + get(t, e) { + if ((t = ot(t))) { + const n = q.findKey(this, t); + if (n) { + const t = this[n]; + if (!e) return t; + if (!0 === e) + return (function (t) { + const e = Object.create(null), + n = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g; + let r; + for (; (r = n.exec(t)); ) e[r[1]] = r[2]; + return e; + })(t); + if (q.isFunction(e)) return e.call(this, t, n); + if (q.isRegExp(e)) return e.exec(t); + throw new TypeError("parser must be boolean|regexp|function"); + } + } + } + has(t, e) { + if ((t = ot(t))) { + const n = q.findKey(this, t); + return !( + !n || + void 0 === this[n] || + (e && !at(0, this[n], n, e)) + ); + } + return !1; + } + delete(t, e) { + const n = this; + let r = !1; + function s(t) { + if ((t = ot(t))) { + const s = q.findKey(n, t); + !s || (e && !at(0, n[s], s, e)) || (delete n[s], (r = !0)); + } + } + return q.isArray(t) ? t.forEach(s) : s(t), r; + } + clear(t) { + const e = Object.keys(this); + let n = e.length, + r = !1; + for (; n--; ) { + const s = e[n]; + (t && !at(0, this[s], s, t, !0)) || (delete this[s], (r = !0)); + } + return r; + } + normalize(t) { + const e = this, + n = {}; + return ( + q.forEach(this, (r, s) => { + const o = q.findKey(n, s); + if (o) return (e[o] = it(r)), void delete e[s]; + const i = t + ? (function (t) { + return t + .trim() + .toLowerCase() + .replace( + /([a-z\d])(\w*)/g, + (t, e, n) => e.toUpperCase() + n, + ); + })(s) + : String(s).trim(); + i !== s && delete e[s], (e[i] = it(r)), (n[i] = !0); + }), + this + ); + } + concat(...t) { + return this.constructor.concat(this, ...t); + } + toJSON(t) { + const e = Object.create(null); + return ( + q.forEach(this, (n, r) => { + null != n && + !1 !== n && + (e[r] = t && q.isArray(n) ? n.join(", ") : n); + }), + e + ); + } + [Symbol.iterator]() { + return Object.entries(this.toJSON())[Symbol.iterator](); + } + toString() { + return Object.entries(this.toJSON()) + .map(([t, e]) => t + ": " + e) + .join("\n"); + } + get [Symbol.toStringTag]() { + return "AxiosHeaders"; + } + static from(t) { + return t instanceof this ? t : new this(t); + } + static concat(t, ...e) { + const n = new this(t); + return e.forEach((t) => n.set(t)), n; + } + static accessor(t) { + const e = (this[st] = this[st] = { accessors: {} }).accessors, + n = this.prototype; + function r(t) { + const r = ot(t); + e[r] || + ((function (t, e) { + const n = q.toCamelCase(" " + e); + ["get", "set", "has"].forEach((r) => { + Object.defineProperty(t, r + n, { + value: function (t, n, s) { + return this[r].call(this, e, t, n, s); + }, + configurable: !0, + }); + }); + })(n, t), + (e[r] = !0)); + } + return q.isArray(t) ? t.forEach(r) : r(t), this; + } + } + ct.accessor([ + "Content-Type", + "Content-Length", + "Accept", + "Accept-Encoding", + "User-Agent", + "Authorization", + ]), + q.reduceDescriptors(ct.prototype, ({ value: t }, e) => { + let n = e[0].toUpperCase() + e.slice(1); + return { + get: () => t, + set(t) { + this[n] = t; + }, + }; + }), + q.freezeMethods(ct); + var ht = ct; + function ut(t, e) { + const n = this || nt, + r = e || n, + s = ht.from(r.headers); + let o = r.data; + return ( + q.forEach(t, function (t) { + o = t.call(n, o, s.normalize(), e ? e.status : void 0); + }), + s.normalize(), + o + ); + } + function dt(t) { + return !(!t || !t.__CANCEL__); + } + function lt(t, e, n) { + z.call(this, null == t ? "canceled" : t, z.ERR_CANCELED, e, n), + (this.name = "CanceledError"); + } + q.inherits(lt, z, { __CANCEL__: !0 }); + var pt = Y.isStandardBrowserEnv + ? { + write: function (t, e, n, r, s, o) { + const i = []; + i.push(t + "=" + encodeURIComponent(e)), + q.isNumber(n) && + i.push("expires=" + new Date(n).toGMTString()), + q.isString(r) && i.push("path=" + r), + q.isString(s) && i.push("domain=" + s), + !0 === o && i.push("secure"), + (document.cookie = i.join("; ")); + }, + read: function (t) { + const e = document.cookie.match( + new RegExp("(^|;\\s*)(" + t + ")=([^;]*)"), + ); + return e ? decodeURIComponent(e[3]) : null; + }, + remove: function (t) { + this.write(t, "", Date.now() - 864e5); + }, + } + : { + write: function () {}, + read: function () { + return null; + }, + remove: function () {}, + }; + function ft(t, e) { + return t && !/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e) + ? (function (t, e) { + return e + ? t.replace(/\/+$/, "") + "/" + e.replace(/^\/+/, "") + : t; + })(t, e) + : e; + } + var yt = Y.isStandardBrowserEnv + ? (function () { + const t = /(msie|trident)/i.test(navigator.userAgent), + e = document.createElement("a"); + let n; + function r(n) { + let r = n; + return ( + t && (e.setAttribute("href", r), (r = e.href)), + e.setAttribute("href", r), + { + href: e.href, + protocol: e.protocol ? e.protocol.replace(/:$/, "") : "", + host: e.host, + search: e.search ? e.search.replace(/^\?/, "") : "", + hash: e.hash ? e.hash.replace(/^#/, "") : "", + hostname: e.hostname, + port: e.port, + pathname: + "/" === e.pathname.charAt(0) + ? e.pathname + : "/" + e.pathname, + } + ); + } + return ( + (n = r(window.location.href)), + function (t) { + const e = q.isString(t) ? r(t) : t; + return e.protocol === n.protocol && e.host === n.host; + } + ); + })() + : function () { + return !0; + }; + function mt(t, e) { + let n = 0; + const r = (function (t, e) { + t = t || 10; + const n = new Array(t), + r = new Array(t); + let s, + o = 0, + i = 0; + return ( + (e = void 0 !== e ? e : 1e3), + function (a) { + const c = Date.now(), + h = r[i]; + s || (s = c), (n[o] = a), (r[o] = c); + let u = i, + d = 0; + for (; u !== o; ) (d += n[u++]), (u %= t); + if ( + ((o = (o + 1) % t), o === i && (i = (i + 1) % t), c - s < e) + ) + return; + const l = h && c - h; + return l ? Math.round((1e3 * d) / l) : void 0; + } + ); + })(50, 250); + return (s) => { + const o = s.loaded, + i = s.lengthComputable ? s.total : void 0, + a = o - n, + c = r(a); + n = o; + const h = { + loaded: o, + total: i, + progress: i ? o / i : void 0, + bytes: a, + rate: c || void 0, + estimated: c && i && o <= i ? (i - o) / c : void 0, + event: s, + }; + (h[e ? "download" : "upload"] = !0), t(h); + }; + } + const gt = { + http: null, + xhr: + "undefined" != typeof XMLHttpRequest && + function (t) { + return new Promise(function (e, n) { + let r = t.data; + const s = ht.from(t.headers).normalize(), + o = t.responseType; + let i, a; + function c() { + t.cancelToken && t.cancelToken.unsubscribe(i), + t.signal && t.signal.removeEventListener("abort", i); + } + q.isFormData(r) && + (Y.isStandardBrowserEnv || Y.isStandardBrowserWebWorkerEnv + ? s.setContentType(!1) + : s.getContentType(/^\s*multipart\/form-data/) + ? q.isString((a = s.getContentType())) && + s.setContentType( + a.replace(/^\s*(multipart\/form-data);+/, "$1"), + ) + : s.setContentType("multipart/form-data")); + let h = new XMLHttpRequest(); + if (t.auth) { + const e = t.auth.username || "", + n = t.auth.password + ? unescape(encodeURIComponent(t.auth.password)) + : ""; + s.set("Authorization", "Basic " + btoa(e + ":" + n)); + } + const u = ft(t.baseURL, t.url); + function d() { + if (!h) return; + const r = ht.from( + "getAllResponseHeaders" in h && h.getAllResponseHeaders(), + ); + !(function (t, e, n) { + const r = n.config.validateStatus; + n.status && r && !r(n.status) + ? e( + new z( + "Request failed with status code " + n.status, + [z.ERR_BAD_REQUEST, z.ERR_BAD_RESPONSE][ + Math.floor(n.status / 100) - 4 + ], + n.config, + n.request, + n, + ), + ) + : t(n); + })( + function (t) { + e(t), c(); + }, + function (t) { + n(t), c(); + }, + { + data: + o && "text" !== o && "json" !== o + ? h.response + : h.responseText, + status: h.status, + statusText: h.statusText, + headers: r, + config: t, + request: h, + }, + ), + (h = null); + } + if ( + (h.open( + t.method.toUpperCase(), + X(u, t.params, t.paramsSerializer), + !0, + ), + (h.timeout = t.timeout), + "onloadend" in h + ? (h.onloadend = d) + : (h.onreadystatechange = function () { + h && + 4 === h.readyState && + (0 !== h.status || + (h.responseURL && + 0 === h.responseURL.indexOf("file:"))) && + setTimeout(d); + }), + (h.onabort = function () { + h && + (n(new z("Request aborted", z.ECONNABORTED, t, h)), + (h = null)); + }), + (h.onerror = function () { + n(new z("Network Error", z.ERR_NETWORK, t, h)), (h = null); + }), + (h.ontimeout = function () { + let e = t.timeout + ? "timeout of " + t.timeout + "ms exceeded" + : "timeout exceeded"; + const r = t.transitional || Z; + t.timeoutErrorMessage && (e = t.timeoutErrorMessage), + n( + new z( + e, + r.clarifyTimeoutError ? z.ETIMEDOUT : z.ECONNABORTED, + t, + h, + ), + ), + (h = null); + }), + Y.isStandardBrowserEnv) + ) { + const e = + (t.withCredentials || yt(u)) && + t.xsrfCookieName && + pt.read(t.xsrfCookieName); + e && s.set(t.xsrfHeaderName, e); + } + void 0 === r && s.setContentType(null), + "setRequestHeader" in h && + q.forEach(s.toJSON(), function (t, e) { + h.setRequestHeader(e, t); + }), + q.isUndefined(t.withCredentials) || + (h.withCredentials = !!t.withCredentials), + o && "json" !== o && (h.responseType = t.responseType), + "function" == typeof t.onDownloadProgress && + h.addEventListener( + "progress", + mt(t.onDownloadProgress, !0), + ), + "function" == typeof t.onUploadProgress && + h.upload && + h.upload.addEventListener( + "progress", + mt(t.onUploadProgress), + ), + (t.cancelToken || t.signal) && + ((i = (e) => { + h && + (n(!e || e.type ? new lt(null, t, h) : e), + h.abort(), + (h = null)); + }), + t.cancelToken && t.cancelToken.subscribe(i), + t.signal && + (t.signal.aborted + ? i() + : t.signal.addEventListener("abort", i))); + const l = (function (t) { + const e = /^([-+\w]{1,25})(:?\/\/|:)/.exec(t); + return (e && e[1]) || ""; + })(u); + l && -1 === Y.protocols.indexOf(l) + ? n( + new z( + "Unsupported protocol " + l + ":", + z.ERR_BAD_REQUEST, + t, + ), + ) + : h.send(r || null); + }); + }, + }; + q.forEach(gt, (t, e) => { + if (t) { + try { + Object.defineProperty(t, "name", { value: e }); + } catch (t) {} + Object.defineProperty(t, "adapterName", { value: e }); + } + }); + const bt = (t) => `- ${t}`, + $t = (t) => q.isFunction(t) || null === t || !1 === t; + var Et = (t) => { + t = q.isArray(t) ? t : [t]; + const { length: e } = t; + let n, r; + const s = {}; + for (let o = 0; o < e; o++) { + let e; + if ( + ((n = t[o]), + (r = n), + !$t(n) && ((r = gt[(e = String(n)).toLowerCase()]), void 0 === r)) + ) + throw new z(`Unknown adapter '${e}'`); + if (r) break; + s[e || "#" + o] = r; + } + if (!r) { + const t = Object.entries(s).map( + ([t, e]) => + `adapter ${t} ` + + (!1 === e + ? "is not supported by the environment" + : "is not available in the build"), + ); + throw new z( + "There is no suitable adapter to dispatch the request " + + (e + ? t.length > 1 + ? "since :\n" + t.map(bt).join("\n") + : " " + bt(t[0]) + : "as no adapter specified"), + "ERR_NOT_SUPPORT", + ); + } + return r; + }; + function _t(t) { + if ( + (t.cancelToken && t.cancelToken.throwIfRequested(), + t.signal && t.signal.aborted) + ) + throw new lt(null, t); + } + function wt(t) { + return ( + _t(t), + (t.headers = ht.from(t.headers)), + (t.data = ut.call(t, t.transformRequest)), + -1 !== ["post", "put", "patch"].indexOf(t.method) && + t.headers.setContentType("application/x-www-form-urlencoded", !1), + Et(t.adapter || nt.adapter)(t).then( + function (e) { + return ( + _t(t), + (e.data = ut.call(t, t.transformResponse, e)), + (e.headers = ht.from(e.headers)), + e + ); + }, + function (e) { + return ( + dt(e) || + (_t(t), + e && + e.response && + ((e.response.data = ut.call( + t, + t.transformResponse, + e.response, + )), + (e.response.headers = ht.from(e.response.headers)))), + Promise.reject(e) + ); + }, + ) + ); + } + const St = (t) => (t instanceof ht ? t.toJSON() : t); + function Bt(t, e) { + e = e || {}; + const n = {}; + function r(t, e, n) { + return q.isPlainObject(t) && q.isPlainObject(e) + ? q.merge.call({ caseless: n }, t, e) + : q.isPlainObject(e) + ? q.merge({}, e) + : q.isArray(e) + ? e.slice() + : e; + } + function s(t, e, n) { + return q.isUndefined(e) + ? q.isUndefined(t) + ? void 0 + : r(void 0, t, n) + : r(t, e, n); + } + function o(t, e) { + if (!q.isUndefined(e)) return r(void 0, e); + } + function i(t, e) { + return q.isUndefined(e) + ? q.isUndefined(t) + ? void 0 + : r(void 0, t) + : r(void 0, e); + } + function a(n, s, o) { + return o in e ? r(n, s) : o in t ? r(void 0, n) : void 0; + } + const c = { + url: o, + method: o, + data: o, + baseURL: i, + transformRequest: i, + transformResponse: i, + paramsSerializer: i, + timeout: i, + timeoutMessage: i, + withCredentials: i, + adapter: i, + responseType: i, + xsrfCookieName: i, + xsrfHeaderName: i, + onUploadProgress: i, + onDownloadProgress: i, + decompress: i, + maxContentLength: i, + maxBodyLength: i, + beforeRedirect: i, + transport: i, + httpAgent: i, + httpsAgent: i, + cancelToken: i, + socketPath: i, + responseEncoding: i, + validateStatus: a, + headers: (t, e) => s(St(t), St(e), !0), + }; + return ( + q.forEach(Object.keys(Object.assign({}, t, e)), function (r) { + const o = c[r] || s, + i = o(t[r], e[r], r); + (q.isUndefined(i) && o !== a) || (n[r] = i); + }), + n + ); + } + const Ot = {}; + ["object", "boolean", "number", "function", "string", "symbol"].forEach( + (t, e) => { + Ot[t] = function (n) { + return typeof n === t || "a" + (e < 1 ? "n " : " ") + t; + }; + }, + ); + const Tt = {}; + Ot.transitional = function (t, e, n) { + function r(t, e) { + return ( + "[Axios v1.5.1] Transitional option '" + + t + + "'" + + e + + (n ? ". " + n : "") + ); + } + return (n, s, o) => { + if (!1 === t) + throw new z( + r(s, " has been removed" + (e ? " in " + e : "")), + z.ERR_DEPRECATED, + ); + return ( + e && + !Tt[s] && + ((Tt[s] = !0), + console.warn( + r( + s, + " has been deprecated since v" + + e + + " and will be removed in the near future", + ), + )), + !t || t(n, s, o) + ); + }; + }; + var At = { + assertOptions: function (t, e, n) { + if ("object" != typeof t) + throw new z("options must be an object", z.ERR_BAD_OPTION_VALUE); + const r = Object.keys(t); + let s = r.length; + for (; s-- > 0; ) { + const o = r[s], + i = e[o]; + if (i) { + const e = t[o], + n = void 0 === e || i(e, o, t); + if (!0 !== n) + throw new z( + "option " + o + " must be " + n, + z.ERR_BAD_OPTION_VALUE, + ); + } else if (!0 !== n) + throw new z("Unknown option " + o, z.ERR_BAD_OPTION); + } + }, + validators: Ot, + }; + const Ct = At.validators; + class xt { + constructor(t) { + (this.defaults = t), + (this.interceptors = { request: new Q(), response: new Q() }); + } + request(t, e) { + "string" == typeof t ? ((e = e || {}).url = t) : (e = t || {}), + (e = Bt(this.defaults, e)); + const { transitional: n, paramsSerializer: r, headers: s } = e; + void 0 !== n && + At.assertOptions( + n, + { + silentJSONParsing: Ct.transitional(Ct.boolean), + forcedJSONParsing: Ct.transitional(Ct.boolean), + clarifyTimeoutError: Ct.transitional(Ct.boolean), + }, + !1, + ), + null != r && + (q.isFunction(r) + ? (e.paramsSerializer = { serialize: r }) + : At.assertOptions( + r, + { encode: Ct.function, serialize: Ct.function }, + !0, + )), + (e.method = ( + e.method || + this.defaults.method || + "get" + ).toLowerCase()); + let o = s && q.merge(s.common, s[e.method]); + s && + q.forEach( + ["delete", "get", "head", "post", "put", "patch", "common"], + (t) => { + delete s[t]; + }, + ), + (e.headers = ht.concat(o, s)); + const i = []; + let a = !0; + this.interceptors.request.forEach(function (t) { + ("function" == typeof t.runWhen && !1 === t.runWhen(e)) || + ((a = a && t.synchronous), i.unshift(t.fulfilled, t.rejected)); + }); + const c = []; + let h; + this.interceptors.response.forEach(function (t) { + c.push(t.fulfilled, t.rejected); + }); + let u, + d = 0; + if (!a) { + const t = [wt.bind(this), void 0]; + for ( + t.unshift.apply(t, i), + t.push.apply(t, c), + u = t.length, + h = Promise.resolve(e); + d < u; + + ) + h = h.then(t[d++], t[d++]); + return h; + } + u = i.length; + let l = e; + for (d = 0; d < u; ) { + const t = i[d++], + e = i[d++]; + try { + l = t(l); + } catch (t) { + e.call(this, t); + break; + } + } + try { + h = wt.call(this, l); + } catch (t) { + return Promise.reject(t); + } + for (d = 0, u = c.length; d < u; ) h = h.then(c[d++], c[d++]); + return h; + } + getUri(t) { + return X( + ft((t = Bt(this.defaults, t)).baseURL, t.url), + t.params, + t.paramsSerializer, + ); + } + } + q.forEach(["delete", "get", "head", "options"], function (t) { + xt.prototype[t] = function (e, n) { + return this.request( + Bt(n || {}, { method: t, url: e, data: (n || {}).data }), + ); + }; + }), + q.forEach(["post", "put", "patch"], function (t) { + function e(e) { + return function (n, r, s) { + return this.request( + Bt(s || {}, { + method: t, + headers: e ? { "Content-Type": "multipart/form-data" } : {}, + url: n, + data: r, + }), + ); + }; + } + (xt.prototype[t] = e()), (xt.prototype[t + "Form"] = e(!0)); + }); + var Rt = xt; + class Lt { + constructor(t) { + if ("function" != typeof t) + throw new TypeError("executor must be a function."); + let e; + this.promise = new Promise(function (t) { + e = t; + }); + const n = this; + this.promise.then((t) => { + if (!n._listeners) return; + let e = n._listeners.length; + for (; e-- > 0; ) n._listeners[e](t); + n._listeners = null; + }), + (this.promise.then = (t) => { + let e; + const r = new Promise((t) => { + n.subscribe(t), (e = t); + }).then(t); + return ( + (r.cancel = function () { + n.unsubscribe(e); + }), + r + ); + }), + t(function (t, r, s) { + n.reason || ((n.reason = new lt(t, r, s)), e(n.reason)); + }); + } + throwIfRequested() { + if (this.reason) throw this.reason; + } + subscribe(t) { + this.reason + ? t(this.reason) + : this._listeners + ? this._listeners.push(t) + : (this._listeners = [t]); + } + unsubscribe(t) { + if (!this._listeners) return; + const e = this._listeners.indexOf(t); + -1 !== e && this._listeners.splice(e, 1); + } + static source() { + let t; + return { + token: new Lt(function (e) { + t = e; + }), + cancel: t, + }; + } + } + var Nt = Lt; + const jt = { + Continue: 100, + SwitchingProtocols: 101, + Processing: 102, + EarlyHints: 103, + Ok: 200, + Created: 201, + Accepted: 202, + NonAuthoritativeInformation: 203, + NoContent: 204, + ResetContent: 205, + PartialContent: 206, + MultiStatus: 207, + AlreadyReported: 208, + ImUsed: 226, + MultipleChoices: 300, + MovedPermanently: 301, + Found: 302, + SeeOther: 303, + NotModified: 304, + UseProxy: 305, + Unused: 306, + TemporaryRedirect: 307, + PermanentRedirect: 308, + BadRequest: 400, + Unauthorized: 401, + PaymentRequired: 402, + Forbidden: 403, + NotFound: 404, + MethodNotAllowed: 405, + NotAcceptable: 406, + ProxyAuthenticationRequired: 407, + RequestTimeout: 408, + Conflict: 409, + Gone: 410, + LengthRequired: 411, + PreconditionFailed: 412, + PayloadTooLarge: 413, + UriTooLong: 414, + UnsupportedMediaType: 415, + RangeNotSatisfiable: 416, + ExpectationFailed: 417, + ImATeapot: 418, + MisdirectedRequest: 421, + UnprocessableEntity: 422, + Locked: 423, + FailedDependency: 424, + TooEarly: 425, + UpgradeRequired: 426, + PreconditionRequired: 428, + TooManyRequests: 429, + RequestHeaderFieldsTooLarge: 431, + UnavailableForLegalReasons: 451, + InternalServerError: 500, + NotImplemented: 501, + BadGateway: 502, + ServiceUnavailable: 503, + GatewayTimeout: 504, + HttpVersionNotSupported: 505, + VariantAlsoNegotiates: 506, + InsufficientStorage: 507, + LoopDetected: 508, + NotExtended: 510, + NetworkAuthenticationRequired: 511, + }; + Object.entries(jt).forEach(([t, e]) => { + jt[e] = t; + }); + var vt = jt; + const Ut = (function t(e) { + const n = new Rt(e), + s = r(Rt.prototype.request, n); + return ( + q.extend(s, Rt.prototype, n, { allOwnKeys: !0 }), + q.extend(s, n, null, { allOwnKeys: !0 }), + (s.create = function (n) { + return t(Bt(e, n)); + }), + s + ); + })(nt); + (Ut.Axios = Rt), + (Ut.CanceledError = lt), + (Ut.CancelToken = Nt), + (Ut.isCancel = dt), + (Ut.VERSION = "1.5.1"), + (Ut.toFormData = H), + (Ut.AxiosError = z), + (Ut.Cancel = Ut.CanceledError), + (Ut.all = function (t) { + return Promise.all(t); + }), + (Ut.spread = function (t) { + return function (e) { + return t.apply(null, e); + }; + }), + (Ut.isAxiosError = function (t) { + return q.isObject(t) && !0 === t.isAxiosError; + }), + (Ut.mergeConfig = Bt), + (Ut.AxiosHeaders = ht), + (Ut.formToJSON = (t) => tt(q.isHTMLForm(t) ? new FormData(t) : t)), + (Ut.getAdapter = Et), + (Ut.HttpStatusCode = vt), + (Ut.default = Ut), + (t.exports = Ut); + }, + }, + e = {}; + function n(r) { + var s = e[r]; + if (void 0 !== s) return s.exports; + var o = (e[r] = { exports: {} }); + return t[r](o, o.exports, n), o.exports; + } + (n.g = (function () { + if ("object" == typeof globalThis) return globalThis; + try { + return this || new Function("return this")(); + } catch (t) { + if ("object" == typeof window) return window; + } + })()), + n(138); +})(); diff --git a/package-lock.json b/package-lock.json index 18ccbe78..acb7d348 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "jest": "^29.7.0", "jest-fetch-mock": "^3.0.3", "jsdoc": "^4.0.2", + "prettier": "3.0.3", "rollup": "^4.0.2", "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-node-resolve": "^5.2.0", @@ -4209,6 +4210,21 @@ "node": ">=8" } }, + "node_modules/prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", @@ -8391,6 +8407,12 @@ "find-up": "^4.0.0" } }, + "prettier": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", + "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "dev": true + }, "pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", diff --git a/package.json b/package.json index 0137e1aa..d14c8c7e 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "jest": "^29.7.0", "jest-fetch-mock": "^3.0.3", "jsdoc": "^4.0.2", + "prettier": "3.0.3", "rollup": "^4.0.2", "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-node-resolve": "^5.2.0", diff --git a/src/examples/examples.js b/src/examples/examples.js index a6ffeb8a..aafe6fcc 100644 --- a/src/examples/examples.js +++ b/src/examples/examples.js @@ -4,14 +4,14 @@ const SDK = require("../mainflux/sdk"); const defaultUrl = "http://localhost"; const mySdk = new SDK({ - usersUrl: defaultUrl + ":9002", - groupsUrl: defaultUrl + ":9002", - thingsUrl: defaultUrl + ":9000", - channelsUrl: defaultUrl + ":9000", - httpadapterUrl: defaultUrl, - readersUrl: defaultUrl + ":9011", - certsUrl: defaultUrl + ":9019", - bootstrapsUrl: defaultUrl + ":9013", + usersUrl: defaultUrl + ":9002", + groupsUrl: defaultUrl + ":9002", + thingsUrl: defaultUrl + ":9000", + channelsUrl: defaultUrl + ":9000", + httpadapterUrl: defaultUrl, + readersUrl: defaultUrl + ":9011", + certsUrl: defaultUrl + ":9019", + bootstrapsUrl: defaultUrl + ":9013", }); //Things.js examples. diff --git a/src/index.js b/src/index.js index 2fe603b0..956b79cd 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,3 @@ -const sdk = require('./mainflux/sdk'); +const sdk = require("./mainflux/sdk"); -module.exports = sdk; \ No newline at end of file +module.exports = sdk; diff --git a/src/mainflux/bootstrap.js b/src/mainflux/bootstrap.js index 8c69a0ef..704e74c0 100644 --- a/src/mainflux/bootstrap.js +++ b/src/mainflux/bootstrap.js @@ -1,7 +1,27 @@ -const axios = require('axios'); +const axios = require("axios"); -class Bootstrap{ - //Bootstraps API Client +class Bootstrap { + //Bootstraps API Client + /** + * @class Bootstrap + * Bootstrap is used to manage bootstrap configurations. + * It is used to create, update, view and remove bootstrap configurations. + * It is also used to bootstrap a thing. + * @param {string} bootstraps_url - The url of the bootstraps service. + * @param {string} content_type - The content type of the request. + * @param {string} bootstrapsEndpoint - The endpoint of the bootstraps service which is + * configs. + * @returns {Bootstrap} - Returns a Bootstrap object. + * + */ + constructor(bootstraps_url) { + this.bootstraps_url = bootstraps_url; + this.content_type = "application/json"; + this.bootstrapsEndpoint = "configs"; + } + + Create(config, token) { + //Create a bootstrap configuration /** * @class Bootstrap * Bootstrap is used to manage bootstrap configurations. @@ -11,11 +31,25 @@ class Bootstrap{ * @returns {Bootstrap} - Returns a Bootstrap object. * */ - constructor(bootstraps_url){ - this.bootstraps_url = bootstraps_url; - this.content_type = "application/json"; - this.bootstrapsEndpoint = "configs"; - } + const options = { + method: "post", + maxBodyLength: Infinity, + url: `${this.bootstraps_url}/things/${this.bootstrapsEndpoint}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(config), + }; + return axios + .request(options) + .then((_response) => { + return "Configuration added"; + }) + .catch((error) => { + return error.response.data; + }); + } ValidateConfigAndToken(config, token){ //Validate config @@ -285,6 +319,32 @@ class Bootstrap{ }) } + Bootstrap(external_id, external_key) { + //Retrive a bootstrap configuration + /** + * @method Bootstrap - Retrieves a configuration with given external ID and encrypted external key. + * @param {string} external_id - The external ID of the configuration to be retrieved. + * @param {string} external_key - The encrypted external key of the configuration to be retrieved. + * @return {object} - Returns a config object. + */ + const options = { + method: "get", + maxBodyLength: Infinity, + url: `${this.bootstraps_url}/things/bootstrap/${external_id}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Thing ${external_key}`, + }, + }; + return axios + .request(options) + .then((response) => { + return response.data; + }) + .catch((error) => { + return error.response.data; + }); + } } module.exports = Bootstrap; diff --git a/src/mainflux/certs.js b/src/mainflux/certs.js index b7fe0c85..97acae0a 100644 --- a/src/mainflux/certs.js +++ b/src/mainflux/certs.js @@ -3,7 +3,23 @@ const axios = require("axios"); class Certs { - //Certs API Client + //Certs API Client + /** + *@class Certs - Certs is used to manage certificates. + *It is used to issue, view and revoke certificates. + * @param {string} certs_url - The url of the certs service. + * @param {string} content_type - The content type of the request. + * @param {string} certsEndpoint - The endpoint of the certs service which is certs. + * @returns {Certs} - Returns a Certs object. + */ + constructor(certs_url) { + this.certs_url = certs_url; + this.content_type = "application/json"; + this.certsEndpoint = "certs"; + } + + Issue(thing_id, valid, token) { + //Issue a certificate /** *@class Certs - Certs is used to manage certificates. *It is used to issue, view and revoke certificates. @@ -157,6 +173,32 @@ class Certs { }) } + Revoke(thing_id, token) { + //Revoke a certificate + /** + * @method Revoke - Allows a logged in user to delete a certificate once they + * provide a valid thing-id and token. + * @param {string} thing_id - The thing_id of the certificate to be revoked. + * @param {string} token - The token to be used for authentication. + */ + const options = { + method: "delete", + maxBodyLength: Infinity, + url: `${this.certs_url}/${this.certsEndpoint}/${thing_id}`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${token}`, + }, + }; + return axios + .request(options) + .then((_response) => { + return "DELETED"; + }) + .catch((error) => { + return error.response.data; + }); + } } module.exports = Certs; diff --git a/src/mainflux/channels.js b/src/mainflux/channels.js index 70b3b9aa..efcc7146 100644 --- a/src/mainflux/channels.js +++ b/src/mainflux/channels.js @@ -2,7 +2,26 @@ const axios = require("axios"); class Channels { - //Channels API client + //Channels API client + /** + * @class Channels - + * Channels API is used for managing Channels. It is used for creating new + * channels, retrieving them, updating them and disabling them + * @param {string} channels_url - URL to the Channels service + * @param {string} content_type - Content type for the requests which is an application + * json + * @param {string} channelsEndpoint - Endpoint for the channels' service. + * @returns {Object} -Channels object + * + */ + constructor(channels_url) { + this.channels_url = channels_url; + this.content_type = "application/json"; + this.channelsEndpoint = "channels"; + } + + Create(channel, token) { + //Creates a new channel /** * @class Channels - * Channels API is used for managing Channels. It is used for creating new @@ -271,6 +290,32 @@ class Channels { }) } + Disable(channel, token) { + //Disables channel with specified id. + /** + * @method Disable - Disables channel with specified id. + * @param {Object} channel - Channel object with new information. + * @param {String} token - An access token that is valid. + * @returns {Object} - Channel Object. + */ + const options = { + method: "post", + maxBodyLength: Infinity, + url: `${this.channels_url}/${this.channelsEndpoint}/${channel["id"]}/disable`, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${token}`, + }, + }; + return axios + .request(options) + .then((response) => { + return response.data; + }) + .catch((error) => { + return error.response.data; + }); + } } // export default Channels; diff --git a/src/mainflux/errors.js b/src/mainflux/errors.js index b6ae99d6..5349706d 100644 --- a/src/mainflux/errors.js +++ b/src/mainflux/errors.js @@ -1,22 +1,22 @@ class Errors { - HandleError(error_dict, status_code) { - if (error_dict.hasOwnProperty(status_code)) { - return error_dict[status_code]; - } else { - return errors[status_code]; - } + HandleError(error_dict, status_code) { + if (error_dict.hasOwnProperty(status_code)) { + return error_dict[status_code]; + } else { + return errors[status_code]; } + } - errors = { - 400: "Failed due to malformed JSON.", - 401: "Missing or invalid access token provided.", - 403: "Missing or invalid access token provided.", - 404: "A non-existent entity request.", - 409: "Entity already exists.", - 415: "Missing or invalid content type.", - 422: "Database can't process the request.", - 500: "Unexpected server-side error occurred.", - }; + errors = { + 400: "Failed due to malformed JSON.", + 401: "Missing or invalid access token provided.", + 403: "Missing or invalid access token provided.", + 404: "A non-existent entity request.", + 409: "Entity already exists.", + 415: "Missing or invalid content type.", + 422: "Database can't process the request.", + 500: "Unexpected server-side error occurred.", + }; users = { get : { diff --git a/src/mainflux/groups.js b/src/mainflux/groups.js index da5484f1..797db8fe 100644 --- a/src/mainflux/groups.js +++ b/src/mainflux/groups.js @@ -2,7 +2,25 @@ const axios = require("axios"); class Groups { - //Groups API client. + //Groups API client. + /** + * @class Groups - + * Groups API client is used for managing groups. It is used for + * creating, updating, deleting, and retrieving groups. + * @param {string} groups_url - The URL of the Groups service. + * @param {string} content_type - The content type of the request. + * @param {string} groupsEndpoint - The endpoint of the Groups service. + * @returns {Groups} - Returns a Groups object. + */ + constructor(groups_url) { + this.groups_url = groups_url; + this.content_type = "application/json"; + this.groupsEndpoint = "groups"; + } + // groupError = new Errors; + + Create(group, token) { + // Create a new group. /** * @class Groups - * Groups API client is used for managing groups. It is used for diff --git a/src/mainflux/messages.js b/src/mainflux/messages.js index 79d88f12..d198f0d0 100644 --- a/src/mainflux/messages.js +++ b/src/mainflux/messages.js @@ -1,17 +1,35 @@ -const axios = require('axios'); +const axios = require("axios"); -class Messages{ - //Messages API Client +class Messages { + //Messages API Client + /** + * @method Messages - Messages is used to manage messages. + * It provides methods for sending and reading messages. + * @param {string} readers_url - The url of the readers service. + * @param {string} httpadapter_url - The URL of the Mainflux Messages adapter. + * @param {string} content_type - The content type of the request. + * @returns {Messages} - Returns a Messages object. + */ + constructor(readers_url, httpadapter_url) { + this.readers_url = readers_url; + this.httpadapter_url = httpadapter_url; + this.content_type = "application/json"; + } + + Send(channel_id, msg, thing_key) { + //Send a message /** * @method Messages - Messages is used to manage messages. * It provides methods for sending and reading messages. * @param {string} readers_url - The url of the readers service. * @returns {Messages} - Returns a Messages object. */ - constructor(readers_url, httpadapter_url){ - this.readers_url = readers_url; - this.httpadapter_url = httpadapter_url; - this.content_type = 'application/json'; + const chan_name_parts = channel_id.split(".", 2); + const chan_id = chan_name_parts[0]; + let subtopic = ""; + + if (chan_name_parts.length == 2) { + subtopic = chan_name_parts[1].replace(".", "/", -1); } Send(channel_id, msg, thing_key){ @@ -44,9 +62,18 @@ class Messages{ const chan_id = chan_name_parts[0]; let subtopic = ""; - if (chan_name_parts.length == 2) { - subtopic = chan_name_parts[1].replace(".", "/", -1); - } + Read(channel_id, token) { + //Read messages + /** + * + * @method Read - Read messages from a given channel. Messages are read from a reader + * add-on such as timescale. Messages are read from a http port specific to the reader + * @param {string} channel_id - The channel_id of the channel to read the message from. + * @param {string} token - The token to be used for authentication. + */ + const chan_name_parts = channel_id.split(".", 2); + const chan_id = chan_name_parts[0]; + let subtopic = ""; const options = { method: "post", diff --git a/src/mainflux/sdk.js b/src/mainflux/sdk.js index 2b46b4f0..a95c59aa 100644 --- a/src/mainflux/sdk.js +++ b/src/mainflux/sdk.js @@ -31,7 +31,7 @@ class SDK { // module.exports = SDK; // Export the SDK class for use in a web browser -if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { +if (typeof module !== "undefined" && typeof module.exports !== "undefined") { module.exports = SDK; // For Node.js } else { window.SDK = SDK; // For browsers diff --git a/src/mainflux/things.js b/src/mainflux/things.js index aef6ade3..e6d94e5f 100644 --- a/src/mainflux/things.js +++ b/src/mainflux/things.js @@ -3,7 +3,7 @@ const axios = require("axios"); class Things { // Things service client. /** - * @class Things - + * @class Things - * Things API is used for creating and managing things. * It is used for creating, updating, deleting and retrieving things. * @param {string} things_url - Things service URL. @@ -35,7 +35,7 @@ class Things { Create(thing, token) { //Creates a new thing. /** - * @method Create - Creates a new thing when provided with + * @method Create - Creates a new thing when provided with * the things information and a valid token. * @param {Object} thing - Thing object. * @param {string} token - User token. @@ -71,20 +71,21 @@ class Things { }, data: JSON.stringify(thing), }; - return axios.request(options) + return axios + .request(options) .then((response) => { return response.data; }) .catch((error) => { return error.response.data; - }) + }); } CreateBulk(things, token) { //Creates multiple things. /** * @method Create_bulk - Creates multiple things when provided with a valid - * token and an array of things information such as names. + * token and an array of things information such as names. * @param {list} things - An array of things information. * @param {string} token - User token. * @returns {list} - Things list. @@ -115,13 +116,14 @@ class Things { }, data: JSON.stringify(things), }; - return axios.request(options) + return axios + .request(options) .then((response) => { return response.data; }) .catch((error) => { return error.response.data; - }) + }); } Get(thing_id, token) { @@ -134,7 +136,7 @@ class Things { * @returns {Object} - Thing object. * @example * const thing_id = "bb7edb32-2eac-4aad-aebe-ed96fe073879" - * + * */ this.ValidateThingIdThingAndToken(thing_id, {}, token); @@ -148,19 +150,20 @@ class Things { Authorization: `Bearer ${token}`, }, }; - return axios.request(options) + return axios + .request(options) .then((response) => { return response.data; }) .catch((error) => { return error.response.data; - }) + }); } GetByChannel(thing_id, query_params, token) { //Retrieves list of channels connected to specified thing with pagination metadata. /** - * @method GetByChannel - Retrieves list of channels connected to specified thing + * @method GetByChannel - Retrieves list of channels connected to specified thing * with pagination metadata. * @param {string} thing_id - Thing ID. * @param {Object} query_params - Query parameters such as offset and limit. @@ -182,19 +185,20 @@ class Things { Authorization: `Bearer ${token}`, }, }; - return axios.request(options) + return axios + .request(options) .then((response) => { return response.data; }) .catch((error) => { return error.response.data; - }) + }); } GetAll(query_params, token) { //Retrieves list of things with pagination metadata. /** - * @method GetAll - Retrieves list of things with pagination metadata when provided with a + * @method GetAll - Retrieves list of things with pagination metadata when provided with a * valid token and correct query parameters such as offset and limit. * @param {Object} query_params - Query parameters. * @param {string} token - User token. @@ -216,13 +220,14 @@ class Things { Authorization: `Bearer ${token}`, }, }; - return axios.request(options) + return axios + .request(options) .then((response) => { return response.data; }) .catch((error) => { return error.response.data; - }) + }); } Disable(thing_id, token) { @@ -231,7 +236,7 @@ class Things { * @method Disable - Deletes a thing when provided with a valid token and thing ID. * @param {string} thing_id - Thing ID. * @param {string} token - User token. - * @returns {Object} - Thing object with statys disabled. + * @returns {Object} - Thing object with statys disabled. */ this.ValidateThingIdThingAndToken(thing_id, {}, token); @@ -245,19 +250,20 @@ class Things { Authorization: `Bearer ${token}`, }, }; - return axios.request(options) + return axios + .request(options) .then((response) => { return response.data; }) .catch((error) => { return error.response.data; - }) + }); } Update(thing_id, thing, token) { //Updates thing. /** - * @method Update - Updates thing when provided with a valid token, + * @method Update - Updates thing when provided with a valid token, * thing ID and thing object. * @param {string} thing_id - Thing ID. * @param {Object} thing - Thing object. @@ -290,13 +296,14 @@ class Things { }, data: JSON.stringify(thing), }; - return axios.request(options) + return axios + .request(options) .then((response) => { return response.data; }) .catch((error) => { return error.response.data; - }) + }); } UpdateThingSecret(thing_id, thing, token) { @@ -335,13 +342,14 @@ class Things { }, data: JSON.stringify(thing), }; - return axios.request(options) + return axios + .request(options) .then((response) => { return response.data; }) .catch((error) => { return error.response.data; - }) + }); } UpdateThingTags(thing_id, thing, token) { @@ -349,7 +357,7 @@ class Things { /** * @method UpdateThingTags - Updates thing tags when provided with a valid token, * thing ID and thing object. - * + * * @param {string} thing_id - Thing ID. * @param {Object} thing - Thing object. * @param {string} token - User token. @@ -381,13 +389,14 @@ class Things { }, data: JSON.stringify(thing), }; - return axios.request(options) + return axios + .request(options) .then((response) => { return response.data; }) .catch((error) => { return error.response.data; - }) + }); } UpdateThingOwner(thing_id, thing, token) { @@ -426,26 +435,27 @@ class Things { }, data: JSON.stringify(thing), }; - return axios.request(options) + return axios + .request(options) .then((response) => { return response.data; }) .catch((error) => { return error.response.data; - }) + }); } Connect(thing_id, channel_id, action, token) { //Connects thing to channel. /** * @method Connect - Connects thing to channel when provided with a valid token, - * channel id and a thing id. The thing must have an action that it can perform over + * channel id and a thing id. The thing must have an action that it can perform over * the channel. * @param {string} thing_id - Thing ID. * @param {string} channel_id - Channel ID. * @param {list} action - Action for example: ["m_read", "m_write"]. * @param {string} token - User token. - * + * */ if (typeof channel_id !== 'string' || channel_id === null) { throw new Error('Invalid channel_id parameter. Expected a string.'); @@ -457,7 +467,7 @@ class Things { this.ValidateThingIdThingAndToken(thing_id, {}, token); - const payload = { "subject": thing_id, "object": channel_id, "action": action } + const payload = { subject: thing_id, object: channel_id, action: action }; const options = { method: "post", maxBodyLength: 2000, @@ -468,13 +478,14 @@ class Things { }, data: JSON.stringify(payload), }; - return axios.request(options) + return axios + .request(options) .then((_response) => { return "Policy created."; }) .catch((error) => { return error.response.data; - }) + }); } Connects(thing_ids, channel_ids, actions, token) { @@ -487,7 +498,7 @@ class Things { * @param {list} actions - Array of actions for example: ["m_read", "m_write"]. * @param {string} token - User token. * @returns {Object} - Policy object. - * + * */ if (!Array.isArray(thing_ids) || !Array.isArray(channel_ids) || !Array.isArray(actions)) { @@ -507,13 +518,14 @@ class Things { }, data: JSON.stringify(payload), }; - return axios.request(options) + return axios + .request(options) .then((_response) => { return "Policy created."; }) .catch((error) => { return error.response.data; - }) + }); } Disconnect(thing_id, channel_id, token) { @@ -524,7 +536,7 @@ class Things { * @param {list} thing_id - Thing ID. * @param {list} channel_id - Channel ID. * @param {string} token - User token. - * + * */ if (typeof channel_id !== 'string' || channel_id === null) { @@ -544,13 +556,14 @@ class Things { }, data: JSON.stringify(payload), }; - return axios.request(options) + return axios + .request(options) .then((_response) => { return "Policy deleted."; }) .catch((error) => { return error.response.data; - }) + }); } IdentifyThing(thing_key) { @@ -560,7 +573,7 @@ class Things { * does not require a token. * @param {string} thing_key - Thing secret. * @returns {Object} - Thing object. - * + * */ if (typeof thing_key !== 'string' || thing_key === null) { @@ -576,19 +589,20 @@ class Things { Authorization: `Thing ${thing_key}`, }, }; - return axios.request(options) + return axios + .request(options) .then((response) => { return response.data; }) .catch((error) => { return error.response.data; - }) + }); } AuthoriseThing(thing_id, channel_id, action, entity_type, token) { //Authorises thing /** - * @method AuthoriseThing - Authorises a thing to perform an action on a channel + * @method AuthoriseThing - Authorises a thing to perform an action on a channel * when provided with a valid token, thing ID, channel ID, action and entity type. * @param {string} thing_id - Thing ID. * @param {string} channel_id - Channel ID. @@ -607,11 +621,11 @@ class Things { throw new Error('Invalid parameter types. Expected strings for thing_id, channel_id, action, entity_type, and token.'); }; const access_request = { - "subject": thing_id, - "object": channel_id, - "action": action, - "entity_type": entity_type - } + subject: thing_id, + object: channel_id, + action: action, + entity_type: entity_type, + }; const options = { method: "post", maxBodyLength: 2000, @@ -622,15 +636,15 @@ class Things { }, data: JSON.stringify(access_request), }; - return axios.request(options) + return axios + .request(options) .then((_response) => { return true; }) .catch((_error) => { return false; - }) + }); } - } module.exports = Things; diff --git a/src/mainflux/users.js b/src/mainflux/users.js index ce0930cd..2e9e67a8 100644 --- a/src/mainflux/users.js +++ b/src/mainflux/users.js @@ -1,7 +1,26 @@ -const axios = require('axios'); +const axios = require("axios"); class Users { - // Users API client + // Users API client + /** + * @class Users - + * Users API is used for creating and managing users. + * It is used for creating new users, logging in, refreshing tokens, + * getting user information, updating user information, disabling + * and enabling users. + * @param {String} users_url - URL to the Users service. + * @param {String} content_type - Content type for the requests. + * @param {String} usersEndpoint - Endpoint for the users service. + * @returns {Object} - Users object. + */ + constructor(users_url) { + this.users_url = users_url; + this.content_type = "application/json"; + this.usersEndpoint = "users"; + } + + Create(user, token) { + // Creates a new user /** * @class Users - * Users API is used for creating and managing users. @@ -11,11 +30,6 @@ class Users { * @param {String} users_url - URL to the Users service. * @returns {Object} - Users object. */ - constructor(users_url) { - this.users_url = users_url; - this.content_type = "application/json"; - this.usersEndpoint = "users"; - } // Validation function ValidateUserAndToken(user, token) { @@ -66,20 +80,24 @@ class Users { }) } - Login(user) { - // Issue Access and Refresh Token used for authenticating into the system - /** - * @method Login - Issue Access and Refresh Token used for authenticating into the system. - * @param {Object} user - User object. - * @returns {Object} - Access and Refresh Token. - * @example - * const user = { - * "credentials": { - * "identity": "admin@example.com", - * "password": "12345678" - * } - * } - */ + const options = { + method: "post", + maxBodyLength: Infinity, + url: `${this.users_url}/${this.usersEndpoint}/tokens/issue`, + headers: { + "Content-Type": this.content_type, + }, + data: JSON.stringify(user), + }; + return axios + .request(options) + .then((response) => { + return response.data; + }) + .catch((error) => { + return error; + }); + } this.ValidateUserAndToken(user); @@ -253,14 +271,49 @@ class Users { data: JSON.stringify(user), }; - return axios.request(options) - .then((response) => { - return response.data; - }) - .catch((error) => { - return error.response.data; - }); - } + UpdateUserOwner(user, token) { + // Update a user's owner. + /** + * Updates owner of the user with provided ID. The owner is updated using + * authorization user_tokeN. + * @method UpdateUserOwner - Update a user's owner. + * @param {Object} user - User object. + * @param{String} token - Access token. + * @returns {Object} - User object. + * @example + * const user = { + * "name": "example", + * "id": "886b4266-77d1-4258-abae-2931fb4f16de" + * "tags": [ + * "back", + * "end" + * ] + * "metadata": { + * "foo": "bar" + * } + * "owner":"886b4266-77d1-4258-abae-2931fb4f16de" + * } + * + */ + const options = { + method: "patch", + url: `${this.users_url}/${this.usersEndpoint}/${user["id"]}/owner`, + maxBodyLength: Infinity, + headers: { + "Content-Type": this.content_type, + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(user), + }; + return axios + .request(options) + .then((response) => { + return response.data; + }) + .catch((error) => { + return error.response.data; + }); + } UpdateUserOwner(user, token) { // Update a user's owner. diff --git a/tests/bootstraps.test.js b/tests/bootstraps.test.js index ab800135..f2fddaac 100644 --- a/tests/bootstraps.test.js +++ b/tests/bootstraps.test.js @@ -1,29 +1,139 @@ -const axios = require('axios'); -const mfsdk = require('mainflux-sdk'); - -jest.mock('axios'); - -describe('Bootstraps', () => { - const bootstraps_url = 'http://localhost:9019'; - const config = { - "external_id": "012", - "external_key": "345", - "thing_id": "77cbb344-7c41-47f3-a53a-a3d435b67207", - "name": "percius" +const axios = require("axios"); +const mfsdk = require("mainflux-sdk"); + +jest.mock("axios"); + +describe("Bootstraps", () => { + const bootstraps_url = "http://localhost:9019"; + const config = { + external_id: "012", + external_key: "345", + thing_id: "77cbb344-7c41-47f3-a53a-a3d435b67207", + name: "percius", + }; + const thing_id = "77cbb344-7c41-47f3-a53a-a3d435b67207"; + const token = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9"; + const client_cert = "888888"; + const client_key = "999999"; + const external_key = "012"; + const external_id = "345"; + const ca = "777777"; + const config_id = thing_id; + + test("Create should add a config and return success", () => { + axios.request.mockResolvedValueOnce({ data: "Configuration added" }); + + const expectedUrl = `${bootstraps_url}/things/configs`; + + const sdk = new mfsdk({ bootstrapsUrl: bootstraps_url }); + return sdk.bootstrap.Create(config, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "post", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(config), + }); + expect(result).toEqual("Configuration added"); + }); + }); + + test("Whitelist should update a config and return success", () => { + axios.request.mockResolvedValueOnce({ data: "Configuration updated" }); + + const expectedUrl = `${bootstraps_url}/things/state/${config["thing_id"]}`; + + const sdk = new mfsdk({ bootstrapsUrl: bootstraps_url }); + return sdk.bootstrap.Whitelist(config, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "put", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(config), + }); + expect(result).toEqual("Configuration updated"); + }); + }); + + test("Update should update a config and return success", () => { + axios.request.mockResolvedValueOnce({ data: "Configuration updated" }); + + const expectedUrl = `${bootstraps_url}/things/configs/${config["thing_id"]}`; + + const sdk = new mfsdk({ bootstrapsUrl: bootstraps_url }); + return sdk.bootstrap.Update(config, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "put", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(config), + }); + expect(result).toEqual("Configuration updated"); + }); + }); + + test("View should get a config and return success", () => { + axios.request.mockResolvedValueOnce({ data: config }); + + const expectedUrl = `${bootstraps_url}/things/configs/${thing_id}`; + + const sdk = new mfsdk({ bootstrapsUrl: bootstraps_url }); + return sdk.bootstrap.View(thing_id, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "get", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); + expect(result).toEqual(config); + }); + }); + + test("UpdateCerts should update a config and return success", () => { + axios.request.mockResolvedValueOnce({ data: config }); + + const expectedUrl = `${bootstraps_url}/configs/certs/${config_id}`; + const payload = { + client_cert: client_cert, + client_key: client_key, + ca_cert: ca, }; - const thing_id = "77cbb344-7c41-47f3-a53a-a3d435b67207"; - const token= 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9'; - const client_cert = "888888"; - const client_key = "999999"; - const external_key = "012"; - const external_id = "345"; - const ca = "777777"; - const config_id = thing_id; + const sdk = new mfsdk({ bootstrapsUrl: bootstraps_url }); + return sdk.bootstrap + .UpdateCerts(config_id, client_cert, client_key, ca, token) + .then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "patch", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(payload), + }); + expect(result).toEqual(config); + }); + }); - test( 'Create should add a config and return success', ()=>{ - axios.request.mockResolvedValueOnce({data: 'Configuration added'}); + test("Remove should delete a config and return success", () => { + axios.request.mockResolvedValueOnce({ data: "Configuration removed" }); - const expectedUrl = `${bootstraps_url}/things/configs`; + const expectedUrl = `${bootstraps_url}/things/configs/${config_id}`; const sdk = new mfsdk({bootstrapsUrl : bootstraps_url}); return sdk.bootstrap.Create(config, token).then(result => { @@ -40,11 +150,12 @@ describe('Bootstraps', () => { expect(result).toEqual('Configuration added'); }); }); + }); - test( 'Whitelist should update a config and return success', ()=>{ - axios.request.mockResolvedValueOnce({data: 'Configuration updated'}); + test("Bootstrap should retrieve a config and return success", () => { + axios.request.mockResolvedValueOnce({ data: config }); - const expectedUrl = `${bootstraps_url}/things/state/${config["thing_id"]}`; + const expectedUrl = `${bootstraps_url}/things/bootstrap/${external_id}`; const sdk = new mfsdk({bootstrapsUrl : bootstraps_url}); return sdk.bootstrap.Whitelist(config, token).then(result => { diff --git a/tests/certs.test.js b/tests/certs.test.js index 1446ecb1..8e79cafb 100644 --- a/tests/certs.test.js +++ b/tests/certs.test.js @@ -1,24 +1,28 @@ -const axios = require('axios'); -const mfsdk = require('mainflux-sdk'); +const axios = require("axios"); +const mfsdk = require("mainflux-sdk"); -jest.mock('axios'); +jest.mock("axios"); -describe('Certs', () => { - const certs_url = 'http://localhost'; - const certs= { - "cert_serial": "22:16:df:60:c2:99:bc:c4:9b:1d:fd:71:5e:e9:07:d9:1b:3c:85:1d", - "client_cert": "-----BEGIN CERTIFICATE-----\nMIIEATCCAumgAwIBAgIUIhbfYMKZvMSbHf1xXukH2Rs8hR0wDQYJKoZIhvcNAQEL1k\n-----END CERTIFICATE-----", - "client_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEoQIBAAKCAQEAy9gF84a5s6jlX6hkAPXrLYqvdhe6uygdr6eHfd5erdcdxfgc\n-----END RSA PRIVATE KEY-----", - "expiration": "2023-09-20T10:02:48Z", - "thing_id": "3d49a42f-63fd-491b-9784-adf4b64ef347" - }; - const cert_id = "22:16:df:60:c2:99:bc:c4:9b:1d:fd:71:5e:e9:07:d9:1b:3c:85:1d"; - const thing_id = "3d49a42f-63fd-491b-9784-adf4b64ef347"; - const token = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9"; - const valid = "10h"; - const cert_serial = ["22:16:df:60:c2:99:bc:c4:9b:1d:fd:71:5e:e9:07:d9:1b:3c:85:1d"]; - test('Issue should add a cert and return success', () => { - axios.request.mockResolvedValueOnce({data: certs}); +describe("Certs", () => { + const certs_url = "http://localhost"; + const certs = { + cert_serial: "22:16:df:60:c2:99:bc:c4:9b:1d:fd:71:5e:e9:07:d9:1b:3c:85:1d", + client_cert: + "-----BEGIN CERTIFICATE-----\nMIIEATCCAumgAwIBAgIUIhbfYMKZvMSbHf1xXukH2Rs8hR0wDQYJKoZIhvcNAQEL1k\n-----END CERTIFICATE-----", + client_key: + "-----BEGIN RSA PRIVATE KEY-----\nMIIEoQIBAAKCAQEAy9gF84a5s6jlX6hkAPXrLYqvdhe6uygdr6eHfd5erdcdxfgc\n-----END RSA PRIVATE KEY-----", + expiration: "2023-09-20T10:02:48Z", + thing_id: "3d49a42f-63fd-491b-9784-adf4b64ef347", + }; + const cert_id = "22:16:df:60:c2:99:bc:c4:9b:1d:fd:71:5e:e9:07:d9:1b:3c:85:1d"; + const thing_id = "3d49a42f-63fd-491b-9784-adf4b64ef347"; + const token = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9"; + const valid = "10h"; + const cert_serial = [ + "22:16:df:60:c2:99:bc:c4:9b:1d:fd:71:5e:e9:07:d9:1b:3c:85:1d", + ]; + test("Issue should add a cert and return success", () => { + axios.request.mockResolvedValueOnce({ data: certs }); const expectedUrl = `${certs_url}/certs`; const payload = {"thing_id": thing_id, "ttl": valid} @@ -37,11 +41,12 @@ describe('Certs', () => { expect(result).toEqual(certs); }); }); + }); - test('ViewByThing should retrieve cert and return success', () => { - axios.request.mockResolvedValueOnce({data: cert_serial}); + test("ViewByThing should retrieve cert and return success", () => { + axios.request.mockResolvedValueOnce({ data: cert_serial }); - const expectedUrl = `${certs_url}/serials/${thing_id}`; + const expectedUrl = `${certs_url}/serials/${thing_id}`; const sdk = new mfsdk({certsUrl : certs_url}); return sdk.certs.ViewByThing(thing_id, token).then(result => { @@ -57,11 +62,12 @@ describe('Certs', () => { expect(result).toEqual(cert_serial); }); }); + }); - test('ViewBySerial should retrieve cert and return success', () => { - axios.request.mockResolvedValueOnce({data: certs}); + test("ViewBySerial should retrieve cert and return success", () => { + axios.request.mockResolvedValueOnce({ data: certs }); - const expectedUrl = `${certs_url}/certs/${cert_id}`; + const expectedUrl = `${certs_url}/certs/${cert_id}`; const sdk = new mfsdk({certsUrl : certs_url}); return sdk.certs.ViewBySerial(cert_id, token).then(result => { @@ -77,11 +83,12 @@ describe('Certs', () => { expect(result).toEqual(certs); }); }); + }); - test('Revoke should delete cert and return success', () => { - axios.request.mockResolvedValueOnce("DELETED"); + test("Revoke should delete cert and return success", () => { + axios.request.mockResolvedValueOnce("DELETED"); - const expectedUrl = `${certs_url}/certs/${thing_id}`; + const expectedUrl = `${certs_url}/certs/${thing_id}`; const sdk = new mfsdk({certsUrl : certs_url}); return sdk.certs.Revoke(thing_id, token).then(result => { @@ -97,5 +104,5 @@ describe('Certs', () => { expect(result).toEqual("DELETED"); }); }); - + }); }); diff --git a/tests/channels.test.js b/tests/channels.test.js index 50d34b96..6931d50a 100644 --- a/tests/channels.test.js +++ b/tests/channels.test.js @@ -1,36 +1,66 @@ -const axios = require('axios'); +const axios = require("axios"); const mfsdk = require("mainflux-sdk"); jest.mock("axios"); -describe('Channels', () => { - const channels_url = "http://localhost"; - const channel = { - "name": "channelName", - "description": "long channel description", - "parent_id": "bb7edb32-2eac-4aad-aebe-ed96fe073879", - "metadata": { - "domain": "example.com" +describe("Channels", () => { + const channels_url = "http://localhost"; + const channel = { + name: "channelName", + description: "long channel description", + parent_id: "bb7edb32-2eac-4aad-aebe-ed96fe073879", + metadata: { + domain: "example.com", + }, + status: "enabled", + owner_id: "bb7edb32-2eac-4aad-aebe-ed96fe073879", + }; + const channel_id = "290b0f49-7a57-4b8c-9e4e-fbf17c6ab7d9"; + const token = + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjU3OTMwNjksImlhdCI6"; + const query_params = { + offset: 0, + limit: 10, + }; + const channels = [ + { name: "channelA", id: "bb7edb32-2eac-4aad-aebe-ed96fe073879" }, + { name: "channelB", id: "bb7edb32-2eac-4aad-aebe-ed96fe073879" }, + ]; + const things = [ + { name: "thing1", id: "bb7edb32-2eac-4aad-aebe-ed96fe073879" }, + { name: "thing2", id: "bb7edb32-2eac-4aad-aebe-ed96fe073879" }, + ]; + + test("Create should create a channel and return success", () => { + axios.request.mockResolvedValueOnce({ data: channel }); + + const expectedUrl = `${channels_url}/channels`; + + const sdk = new mfsdk({ channelsUrl: channels_url }); + return sdk.channels.Create(channel, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + url: expectedUrl, + method: "post", + maxBodyLength: Infinity, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, }, - "status": "enabled", - "owner_id": "bb7edb32-2eac-4aad-aebe-ed96fe073879" - }; - const channel_id = "290b0f49-7a57-4b8c-9e4e-fbf17c6ab7d9"; - const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjU3OTMwNjksImlhdCI6"; - const query_params = { - "offset": 0, "limit": 10 + data: JSON.stringify(channel), + }); + expect(result).toEqual(channel); + }); + }); + + test("Create should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, }; - const channels = [ - { "name": "channelA", "id": "bb7edb32-2eac-4aad-aebe-ed96fe073879" }, - { "name": "channelB", "id": "bb7edb32-2eac-4aad-aebe-ed96fe073879" } - ]; - const things = [ - {"name": "thing1", "id": "bb7edb32-2eac-4aad-aebe-ed96fe073879"}, - {"name": "thing2", "id": "bb7edb32-2eac-4aad-aebe-ed96fe073879"} - ]; - - test('Create should create a channel and return success', () => { - axios.request.mockResolvedValueOnce({ data: channel }); + axios.request.mockRejectedValueOnce(errorResponse); + + const expectedUrl = `${channels_url}/channels`; const expectedUrl = `${channels_url}/channels`; @@ -207,13 +237,13 @@ describe('Channels', () => { }, }); console.log(result); - }); }); + }); - test('CreateBulk should create multiple channels and return success', () => { - axios.request.mockResolvedValueOnce({ data: channels }); + test("Get should retrieve a channel and return success", () => { + axios.request.mockResolvedValueOnce({ data: channel }); - const expectedUrl = `${channels_url}/channels/bulk`; + const expectedUrl = `${channels_url}/channels/${channel_id}`; const sdk = new mfsdk({ channelsUrl: channels_url }); return sdk.channels.CreateBulk(channels, token).then(result => { @@ -230,15 +260,15 @@ describe('Channels', () => { expect(result).toEqual(channels); }); }); + }); - test('CreateBulk should handle a conflict error', () => { - const errorResponse = { - response: { - status: 401, - }, - }; - axios.request.mockRejectedValueOnce(errorResponse); - const expectedUrl = `${channels_url}/channels/bulk`; + test("Get should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); const sdk = new mfsdk({ channelsUrl: channels_url }); return sdk.channels.CreateBulk(channels, token).then(result => { @@ -255,14 +285,10 @@ describe('Channels', () => { console.log(result); }); }); + }); - test('Update should handle a conflict error', () => { - const errorResponse = { - response: { - status: 401, - }, - }; - axios.request.mockRejectedValueOnce(errorResponse); + test("Get_by_thing should retrieve things a channel is connected to and return success", () => { + axios.request.mockResolvedValueOnce({ data: things }); const expectedUrl = `${channels_url}/channels/${channel_id}`; @@ -280,10 +306,17 @@ describe('Channels', () => { }); console.log(result); }); - }); - - test('Update should update a channel and return success', () => { - axios.request.mockResolvedValueOnce({ data: channel }); + expect(result).toEqual(things); + }); + }); + + test("Get by thing should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); const expectedUrl = `${channels_url}/channels/${channel_id}`; @@ -301,10 +334,39 @@ describe('Channels', () => { }); expect(result).toEqual(channel); }); + console.log(result); + }); + }); + + test("Get all should retrieve all channels and return success", () => { + axios.request.mockResolvedValueOnce({ data: channels }); + + const expectedUrl = `${channels_url}/channels?${new URLSearchParams( + query_params, + ).toString()}`; + + const sdk = new mfsdk({ channelsUrl: channels_url }); + return sdk.channels.GetAll(query_params, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + url: expectedUrl, + method: "get", + maxBodyLength: Infinity, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); + expect(result).toEqual(channels); }); + }); - test('Disable should delete a channel and return success', () => { - axios.request.mockResolvedValueOnce({ data: channel }); + test("GetAll should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); const expectedUrl = `${channels_url}/channels/${channel_id}/disable`; @@ -322,14 +384,10 @@ describe('Channels', () => { expect(result).toEqual(channel); }); }); + }); - test('Disable should handle a conflict error', () => { - const errorResponse = { - response: { - status: 401, - }, - }; - axios.request.mockRejectedValueOnce(errorResponse); + test("CreateBulk should create multiple channels and return success", () => { + axios.request.mockResolvedValueOnce({ data: channels }); const expectedUrl = `${channels_url}/channels/${channel_id}/disable`; @@ -347,5 +405,122 @@ describe('Channels', () => { console.log(result); }); }); + }); + test("CreateBulk should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); + const expectedUrl = `${channels_url}/channels/bulk`; + + const sdk = new mfsdk({ channelsUrl: channels_url }); + return sdk.channels.CreateBulk(channels, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + url: expectedUrl, + method: "post", + maxBodyLength: Infinity, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(channels), + }); + console.log(result); + }); + }); + + test("Update should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); + + const expectedUrl = `${channels_url}/channels/${channel["id"]}`; + + const sdk = new mfsdk({ channelsUrl: channels_url }); + return sdk.channels.Update(channel, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + url: expectedUrl, + method: "put", + maxBodyLength: Infinity, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(channel), + }); + console.log(result); + }); + }); + + test("Update should update a channel and return success", () => { + axios.request.mockResolvedValueOnce({ data: channel }); + + const expectedUrl = `${channels_url}/channels/${channel["id"]}`; + + const sdk = new mfsdk({ channelsUrl: channels_url }); + return sdk.channels.Update(channel, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + url: expectedUrl, + method: "put", + maxBodyLength: Infinity, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(channel), + }); + expect(result).toEqual(channel); + }); + }); + + test("Disable should delete a channel and return success", () => { + axios.request.mockResolvedValueOnce({ data: channel }); + + const expectedUrl = `${channels_url}/channels/${channel["id"]}/disable`; + + const sdk = new mfsdk({ channelsUrl: channels_url }); + return sdk.channels.Disable(channel, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + url: expectedUrl, + method: "post", + maxBodyLength: Infinity, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); + expect(result).toEqual(channel); + }); + }); + + test("Disable should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); + + const expectedUrl = `${channels_url}/channels/${channel["id"]}/disable`; + + const sdk = new mfsdk({ channelsUrl: channels_url }); + return sdk.channels.Disable(channel, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + url: expectedUrl, + method: "post", + maxBodyLength: Infinity, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); + console.log(result); + }); + }); }); diff --git a/tests/groups.test.js b/tests/groups.test.js index 30a77eb1..ffda7039 100644 --- a/tests/groups.test.js +++ b/tests/groups.test.js @@ -1,30 +1,111 @@ -const axios = require('axios'); -const mfsdk = require("mainflux-sdk") - -jest.mock('axios'); - -describe('Groups', () => { - const groups_url = "http://localhost"; - const group = { - "name": "group_test", - "id": "290b0f49-7a57-4b8c-9e4e-fbf17c6ab7d9", - "parent_id": "290b0f49-7a57-4b8c-9e4e-fbf17c6ab7d9", - "status": "enabled", - "owner_id": "bb7edb32-2eac-4aad-aebe-ed96fe073879" +const axios = require("axios"); +const mfsdk = require("mainflux-sdk"); + +jest.mock("axios"); + +describe("Groups", () => { + const groups_url = "http://localhost"; + const group = { + name: "group_test", + id: "290b0f49-7a57-4b8c-9e4e-fbf17c6ab7d9", + parent_id: "290b0f49-7a57-4b8c-9e4e-fbf17c6ab7d9", + status: "enabled", + owner_id: "bb7edb32-2eac-4aad-aebe-ed96fe073879", + }; + const group_id = "290b0f49-7a57-4b8c-9e4e-fbf17c6ab7d9"; + const token = + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjU3OTMwNjksImlhdCI6"; + const query_params = { + offset: 0, + limit: 10, + }; + const groups = [ + { name: "groupA", id: "bb7edb32-2eac-4aad-aebe-ed96fe073879" }, + { name: "groupB", id: "bb7edb32-2eac-4aad-aebe-ed96fe073879" }, + ]; + const member_id = "bb7edb32-2eac-4aad-aebe-ed96fe073879"; + const member_type = "m_read"; + const members_ids = [ + "bb7edb32-2eac-4aad-aebe-ed96fe073879", + "bb7edb32-2eac-4aad-aebe-ed96fe073879", + ]; + + test("Create should create a group and return success", () => { + axios.request.mockResolvedValueOnce({ data: group }); + + const expectedUrl = `${groups_url}/groups`; + + const sdk = new mfsdk({ groupsUrl: groups_url }); + return sdk.groups.Create(group, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + url: expectedUrl, + method: "post", + maxBodyLength: Infinity, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(group), + }); + expect(result).toEqual(group); + }); + }); + + test("Create should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, }; - const group_id = "290b0f49-7a57-4b8c-9e4e-fbf17c6ab7d9"; - const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjU3OTMwNjksImlhdCI6"; - const query_params = { - "offset": 0, "limit": 10 + axios.request.mockRejectedValueOnce(errorResponse); + + const expectedUrl = `${groups_url}/groups`; + + const sdk = new mfsdk({ groupsUrl: groups_url }); + return sdk.groups.Create(group, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + url: expectedUrl, + method: "post", + maxBodyLength: Infinity, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(group), + }); + console.log(result); + }); + }); + + test("Get should retrieve a group and return success", () => { + axios.request.mockResolvedValueOnce({ data: group }); + + const expectedUrl = `${groups_url}/groups/${group_id}`; + + const sdk = new mfsdk({ groupsUrl: groups_url }); + return sdk.groups.Get(group_id, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + url: expectedUrl, + method: "get", + maxBodyLength: Infinity, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); + expect(result).toEqual(group); + }); + }); + + test("Get should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, }; - const groups = [ - { "name": "groupA", "id": "bb7edb32-2eac-4aad-aebe-ed96fe073879" }, - { "name": "groupB", "id": "bb7edb32-2eac-4aad-aebe-ed96fe073879" } - ]; - const member_id = "bb7edb32-2eac-4aad-aebe-ed96fe073879"; - const member_type = "m_read"; - const members_ids = ["bb7edb32-2eac-4aad-aebe-ed96fe073879", "bb7edb32-2eac-4aad-aebe-ed96fe073879"]; + axios.request.mockRejectedValueOnce(errorResponse); + const expectedUrl = `${groups_url}/groups/${group_id}`; test('Create should create a group and return success', () => { axios.request.mockResolvedValueOnce({ data: group }); @@ -46,16 +127,14 @@ describe('Groups', () => { expect(result).toEqual(group); }); }); + }); - test('Create should handle a conflict error', () => { - const errorResponse = { - response: { - status: 401, - }, - }; - axios.request.mockRejectedValueOnce(errorResponse); + test("Get all should retrieve all groups and return success", () => { + axios.request.mockResolvedValueOnce({ data: groups }); - const expectedUrl = `${groups_url}/groups`; + const expectedUrl = `${groups_url}/groups?${new URLSearchParams( + query_params, + ).toString()}`; const sdk = new mfsdk({ groupsUrl: groups_url }); return sdk.groups.Create(group, token).then(result => { @@ -72,11 +151,19 @@ describe('Groups', () => { console.log(result); }); }); + }); - test('Get should retrieve a group and return success', () => { - axios.request.mockResolvedValueOnce({ data: group }); + test("Get all should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); - const expectedUrl = `${groups_url}/groups/${group_id}`; + const expectedUrl = `${groups_url}/groups?${new URLSearchParams( + query_params, + ).toString()}`; const sdk = new mfsdk({ groupsUrl: groups_url }); return sdk.groups.Get(group_id, token).then(result => { @@ -92,16 +179,12 @@ describe('Groups', () => { expect(result).toEqual(group); }); }); + }); - test('Get should handle a conflict error', () => { - const errorResponse = { - response: { - status: 401, - }, - }; - axios.request.mockRejectedValueOnce(errorResponse); + test("Update should update a group and return success", () => { + axios.request.mockResolvedValueOnce({ data: group }); - const expectedUrl = `${groups_url}/groups/${group_id}`; + const expectedUrl = `${groups_url}/groups/${group_id}`; const sdk = new mfsdk({ groupsUrl: groups_url }); return sdk.groups.Get(group_id, token).then(result => { @@ -117,10 +200,17 @@ describe('Groups', () => { console.log(result); }); }); + }); + test("Update should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); - test('Get all should retrieve all groups and return success', () => { - axios.request.mockResolvedValueOnce({ data: groups }); + const expectedUrl = `${groups_url}/groups/${group_id}`; const expectedUrl = `${groups_url}/groups?${new URLSearchParams(query_params).toString()}`; @@ -138,16 +228,14 @@ describe('Groups', () => { expect(result).toEqual(groups); }); }); + }); - test('Get all should handle a conflict error', () => { - const errorResponse = { - response: { - status: 401, - }, - }; - axios.request.mockRejectedValueOnce(errorResponse); + test("Children should retrieve all of a groups children and return success", () => { + axios.request.mockResolvedValueOnce({ data: groups }); - const expectedUrl = `${groups_url}/groups?${new URLSearchParams(query_params).toString()}`; + const expectedUrl = `${groups_url}/groups/${group_id}/children?${new URLSearchParams( + query_params, + ).toString()}`; const sdk = new mfsdk({ groupsUrl: groups_url }); return sdk.groups.GetAll(query_params, token).then(result => { @@ -163,11 +251,19 @@ describe('Groups', () => { console.log(result); }); }); + }); - test('Update should update a group and return success', () => { - axios.request.mockResolvedValueOnce({ data: group }); + test("Children should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); - const expectedUrl = `${groups_url}/groups/${group_id}`; + const expectedUrl = `${groups_url}/groups/${group_id}/children?${new URLSearchParams( + query_params, + ).toString()}`; const sdk = new mfsdk({ groupsUrl: groups_url }); return sdk.groups.Update(group_id, group, token).then(result => { @@ -184,16 +280,14 @@ describe('Groups', () => { expect(result).toEqual(group); }); }); + }); - test('Update should handle a conflict error', () => { - const errorResponse = { - response: { - status: 401, - }, - }; - axios.request.mockRejectedValueOnce(errorResponse); + test("Parents should retrieve all of a groups children and return success", () => { + axios.request.mockResolvedValueOnce({ data: groups }); - const expectedUrl = `${groups_url}/groups/${group_id}`; + const expectedUrl = `${groups_url}/groups/${ + group["id"] + }/parents?${new URLSearchParams(query_params).toString()}`; const sdk = new mfsdk({ groupsUrl: groups_url }); return sdk.groups.Update(group_id, group, token).then(result => { @@ -210,11 +304,19 @@ describe('Groups', () => { console.log(result); }); }); + }); - test('Children should retrieve all of a groups children and return success', () => { - axios.request.mockResolvedValueOnce({ data: groups }); + test("Parents should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); - const expectedUrl = `${groups_url}/groups/${group_id}/children?${new URLSearchParams(query_params).toString()}`; + const expectedUrl = `${groups_url}/groups/${ + group["id"] + }/parents?${new URLSearchParams(query_params).toString()}`; const sdk = new mfsdk({ groupsUrl: groups_url }); return sdk.groups.Children(group_id, query_params, token).then(result => { @@ -230,16 +332,17 @@ describe('Groups', () => { expect(result).toEqual(groups); }); }); + }); - test('Children should handle a conflict error', () => { - const errorResponse = { - response: { - status: 401, - }, - }; - axios.request.mockRejectedValueOnce(errorResponse); + test("Assign should assign a group and return success", () => { + axios.request.mockResolvedValueOnce("Policy created"); - const expectedUrl = `${groups_url}/groups/${group_id}/children?${new URLSearchParams(query_params).toString()}`; + const expectedUrl = `${groups_url}/policies`; + const payload = { + object: group_id, + subject: member_id, + actions: member_type, + }; const sdk = new mfsdk({ groupsUrl: groups_url }); return sdk.groups.Children(group_id, query_params, token).then(result => { @@ -254,10 +357,17 @@ describe('Groups', () => { }); console.log(result); }); - }); - - test('Parents should retrieve all of a groups children and return success', () => { - axios.request.mockResolvedValueOnce({ data: groups }); + expect(result).toEqual("Policy created"); + }); + }); + + test("Assign should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); const expectedUrl = `${groups_url}/groups/${group_id}/parents?${new URLSearchParams(query_params).toString()}`; @@ -274,15 +384,39 @@ describe('Groups', () => { }); expect(result).toEqual(groups); }); + console.log(result); + }); + }); + + test("Unassign should unassign a group and return success", () => { + axios.request.mockResolvedValueOnce("Policy deleted"); + + const expectedUrl = `${groups_url}/policies/${members_ids}/${group_id}`; + const payload = { object: group_id, subject: members_ids }; + + const sdk = new mfsdk({ groupsUrl: groups_url }); + return sdk.groups.Unassign(members_ids, group_id, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + url: expectedUrl, + method: "delete", + maxBodyLength: Infinity, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(payload), + }); + expect(result).toEqual("Policy deleted"); }); + }); - test('Parents should handle a conflict error', () => { - const errorResponse = { - response: { - status: 401, - }, - }; - axios.request.mockRejectedValueOnce(errorResponse); + test("Unassign should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); const expectedUrl = `${groups_url}/groups/${group_id}/parents?${new URLSearchParams(query_params).toString()}`; @@ -300,12 +434,12 @@ describe('Groups', () => { console.log(result); }); }); + }); - test('Assign should assign a group and return success', () => { - axios.request.mockResolvedValueOnce("Policy created"); + test("Disable should delete a group and return success", () => { + axios.request.mockResolvedValueOnce({ data: group }); - const expectedUrl = `${groups_url}/policies`; - const payload = { "object": group_id, "subject": member_id, "actions": member_type }; + const expectedUrl = `${groups_url}/groups/${group_id}/disable`; const sdk = new mfsdk({ groupsUrl: groups_url }); return sdk.groups.Assign(group_id, member_id, member_type, token).then(result => { @@ -322,17 +456,17 @@ describe('Groups', () => { expect(result).toEqual("Policy created"); }); }); + }); - test('Assign should handle a conflict error', () => { - const errorResponse = { - response: { - status: 401, - }, - }; - axios.request.mockRejectedValueOnce(errorResponse); + test("Disable should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); - const expectedUrl = `${groups_url}/policies`; - const payload = { "object": group_id, "subject": member_id, "actions": member_type }; + const expectedUrl = `${groups_url}/groups/${group_id}/disable`; const sdk = new mfsdk({ groupsUrl: groups_url }); return sdk.groups.Assign(group_id, member_id, member_type, token).then(result => { @@ -349,9 +483,10 @@ describe('Groups', () => { console.log(result); }); }); + }); - test('Unassign should unassign a group and return success', () => { - axios.request.mockResolvedValueOnce("Policy deleted"); + test("Members should provide members of a group and return success", () => { + axios.request.mockResolvedValueOnce({ data: group }); const expectedUrl = `${groups_url}/policies/${member_id}/${group_id}`; const payload = { "object": group_id, "subject": member_id }; @@ -371,14 +506,15 @@ describe('Groups', () => { expect(result).toEqual("Policy deleted"); }); }); + }); - test('Unassign should handle a conflict error', () => { - const errorResponse = { - response: { - status: 401, - }, - }; - axios.request.mockRejectedValueOnce(errorResponse); + test("Members should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, + }; + axios.request.mockRejectedValueOnce(errorResponse); const expectedUrl = `${groups_url}/policies/${member_id}/${group_id}`; const payload = { "object": group_id, "subject": member_id }; @@ -490,4 +626,5 @@ describe('Groups', () => { // expect(result.error.message).toBe('Missing or invalid access token provided.'); }); }); + }); }); diff --git a/tests/messages.test.js b/tests/messages.test.js index 33050067..e951e12c 100644 --- a/tests/messages.test.js +++ b/tests/messages.test.js @@ -1,9 +1,15 @@ -const axios = require('axios'); +const axios = require("axios"); const mfsdk = require("mainflux-sdk"); -jest.mock('axios'); +jest.mock("axios"); -describe('Messages', () => { +describe("Messages", () => { + const httpadapter_url = "http://localhost"; + const readers_url = "http://localhost"; + const channel_id = "2b86beba-83dd-4b39-8165-4dda4e6eb4ad"; + const msg = '[{"bn":"demo", "bu":"V", "n":"voltage", "u":"V", "v":5}]'; + const token = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9"; + const thing_key = "fc68b31b-d7fd-4879-b3a7-0baf4580c5b1"; const httpadapter_url = 'http://localhost'; const readers_url = 'http://localhost'; @@ -19,8 +25,7 @@ describe('Messages', () => { subtopic = chan_name_parts[1].replace(".", "/", -1); } - test('Send should send a message and return success', () => { - axios.request.mockResolvedValueOnce({ data: msg }); + const expectedUrl = `${httpadapter_url}/http/channels/${channel_id}/messages/subtopic`; const expectedUrl = `${httpadapter_url}/http/channels/${chan_id}/messages/${subtopic}`; @@ -39,9 +44,10 @@ describe('Messages', () => { expect(result).toEqual('Message Sent!'); }); }); + }); - test('Read should read a message and return success', () => { - axios.request.mockResolvedValueOnce({ data: msg }); + test("Read should read a message and return success", () => { + axios.request.mockResolvedValueOnce({ data: msg }); const expectedUrl = `${readers_url}/channels/${chan_id}/messages`; @@ -60,5 +66,5 @@ describe('Messages', () => { expect(result).toEqual(msg); }); }); - -}) + }); +}); diff --git a/tests/things.test.js b/tests/things.test.js index 56684835..7fb1824e 100644 --- a/tests/things.test.js +++ b/tests/things.test.js @@ -1,44 +1,368 @@ -const axios = require('axios'); +const axios = require("axios"); const mfsdk = require("mainflux-sdk"); -jest.mock('axios'); - -describe('Things', () => { - const things_url = "http://localhost:9000"; - const thing = { - "name": "thingName", - "tags": [ - "tag1", - "tag2" - ], - "credentials": { - "identity": "thingidentity", - "secret": "bb7edb32-2eac-4aad-aebe-ed96fe073879" +jest.mock("axios"); + +describe("Things", () => { + const things_url = "http://localhost:9000"; + const thing = { + name: "thingName", + tags: ["tag1", "tag2"], + credentials: { + identity: "thingidentity", + secret: "bb7edb32-2eac-4aad-aebe-ed96fe073879", + }, + owner: "bb7edb32-2eac-4aad-aebe-ed96fe073879", + metadata: { + domain: "example.com", + }, + status: "enabled", + }; + const thing_id = "bb7edb32-2eac-4aad-aebe-ed96fe073879"; + const channel_id = "bb7edb32-2eac-4aad-aebe-ed96fe073879"; + const thing_ids = [ + "6cba4ea5-5820-4419-b389-86984309ad35", + "2bb290ff-0cb1-4f06-9da3-aff91c1d039", + ]; + const channel_ids = [ + "2bb290ff-0cb1-4f06-9da3-aff91c1d039", + "6cba4ea5-5820-4419-b389-86984309ad35", + ]; + const actions = ["m_read", "m_write"]; + const thing_key = "12345678"; + const action = ["m_read", "m_write"]; + const channels = [ + { name: "channel1", id: "bb7edb32-2eac-4aad-aebe-ed96fe073879" }, + { name: "channel2", id: "bb7edb32-2eac-4aad-aebe-ed96fe073879" }, + ]; + const entity_type = "group"; + const token = + "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjU3OTMwNjksImlhdCI6"; + const things = [ + { name: "thing1", id: "bb7edb32-2eac-4aad-aebe-ed96fe073879" }, + { name: "thing2", id: "bb7edb32-2eac-4aad-aebe-ed96fe073879" }, + ]; + const query_params = { + offset: 0, + limit: 10, + }; + + test("Create should create a thing and return success", () => { + axios.request.mockResolvedValue({ data: thing }); + + const expectedUrl = `${things_url}/things`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things.Create(thing, token).then((result) => { + expect(result).toEqual(thing); + expect(axios.request).toHaveBeenCalledWith({ + method: "post", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, }, - "owner": "bb7edb32-2eac-4aad-aebe-ed96fe073879", - "metadata": { - "domain": "example.com" - }, - "status": "enabled" + data: JSON.stringify(thing), + }); + }); + }); + + test("Create should handle a conflict error", () => { + const errorResponse = { + response: { + status: 401, + }, }; - const thing_id = "bb7edb32-2eac-4aad-aebe-ed96fe073879"; - const channel_id = "bb7edb32-2eac-4aad-aebe-ed96fe073879"; - const thing_ids = ["6cba4ea5-5820-4419-b389-86984309ad35","2bb290ff-0cb1-4f06-9da3-aff91c1d039"]; - const channel_ids = ["2bb290ff-0cb1-4f06-9da3-aff91c1d039","6cba4ea5-5820-4419-b389-86984309ad35"]; - const actions = ["m_read", "m_write"]; - const thing_key= "12345678"; - const action = ["m_read", "m_write"]; - const channels = [{"name": "channel1", "id": "bb7edb32-2eac-4aad-aebe-ed96fe073879"}, - {"name": "channel2", "id": "bb7edb32-2eac-4aad-aebe-ed96fe073879"} - ]; - const entity_type = "group"; - const token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2NjU3OTMwNjksImlhdCI6"; - const things = [ - {"name": "thing1", "id": "bb7edb32-2eac-4aad-aebe-ed96fe073879"}, - {"name": "thing2", "id": "bb7edb32-2eac-4aad-aebe-ed96fe073879"} - ]; - const query_params = { - "offset": 0, "limit": 10 + axios.request.mockRejectedValue(errorResponse); + + const expectedUrl = `${things_url}/things`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things.Create(thing, token).catch((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "post", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(thing), + }); + console.log(result); + }); + }); + + test("CreateBulk should create multiple things and return success", () => { + axios.request.mockResolvedValue({ data: things }); + + const expectedUrl = `${things_url}/things/bulk`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things.CreateBulk(things, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "post", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(things), + }); + expect(result).toEqual(things); + }); + }); + + test("Update should update a thing and return success", () => { + axios.request.mockResolvedValue({ data: thing }); + + const expectedUrl = `${things_url}/things/${thing_id}`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things.Update(thing_id, thing, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "patch", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(thing), + }); + expect(result).toEqual(thing); + }); + }); + + test("Get should give a thing and return success", () => { + axios.request.mockResolvedValue({ data: thing }); + + const expectedUrl = `${things_url}/things/${thing_id}`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things.Get(thing_id, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "get", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); + expect(result).toEqual(thing); + }); + }); + + test("Get by channel return a channel a thing is connected and return success", () => { + axios.request.mockResolvedValue({ data: channels }); + + const expectedUrl = `${things_url}/things/${thing_id}/channels?${new URLSearchParams( + query_params, + ).toString()}`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things + .GetByChannel(thing_id, query_params, token) + .then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "get", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); + expect(result).toEqual(channels); + }); + }); + + test("GetAll should return all things and return success", () => { + axios.request.mockResolvedValue({ data: things }); + + const expectedUrl = `${things_url}/things?${new URLSearchParams( + query_params, + ).toString()}`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things.GetAll(query_params, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "get", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); + expect(result).toEqual(things); + }); + }); + + test("Disable should delete a thing and return success", () => { + axios.request.mockResolvedValue({ data: thing }); + + const expectedUrl = `${things_url}/things/${thing_id}/disable`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things.Disable(thing_id, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "post", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + }); + expect(result).toEqual(thing); + }); + }); + + test("Update should update a thing and return success", () => { + axios.request.mockResolvedValue({ data: thing }); + + const expectedUrl = `${things_url}/things/${thing_id}`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things.Update(thing_id, thing, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "patch", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(thing), + }); + expect(result).toEqual(thing); + }); + }); + + test("Update thing secret should update a thing secret and return success", () => { + axios.request.mockResolvedValue({ data: thing }); + + const expectedUrl = `${things_url}/things/${thing_id}/secret`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things + .UpdateThingSecret(thing_id, thing, token) + .then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "patch", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(thing), + }); + expect(result).toEqual(thing); + }); + }); + + test("Update thing tags should update a thing tags and return success", () => { + axios.request.mockResolvedValue({ data: thing }); + + const expectedUrl = `${things_url}/things/${thing_id}/tags`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things.UpdateThingTags(thing_id, thing, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "patch", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(thing), + }); + expect(result).toEqual(thing); + }); + }); + + test("Update thing owner should update a thing owner and return success", () => { + axios.request.mockResolvedValue({ data: thing }); + + const expectedUrl = `${things_url}/things/${thing_id}/owner`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things + .UpdateThingOwner(thing_id, thing, token) + .then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "patch", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(thing), + }); + expect(result).toEqual(thing); + }); + }); + + test("Update should update a thing and return success", () => { + axios.request.mockResolvedValue({ data: thing }); + + const expectedUrl = `${things_url}/things/${thing_id}`; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things.Update(thing_id, thing, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "patch", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(thing), + }); + expect(result).toEqual(thing); + }); + }); + + test("Connect should connect a thing and return success", () => { + axios.request.mockResolvedValue("Policy created."); + + const expectedUrl = `${things_url}/policies`; + const payload = { subject: thing_id, object: channel_id, action: action }; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things + .Connect(thing_id, channel_id, action, token) + .then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "post", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(payload), + }); + expect(result).toEqual("Policy created."); + }); + }); + + test("Connects should connect things and return success", () => { + axios.request.mockResolvedValue("Policy created."); + + const expectedUrl = `${things_url}/connect`; + const payload = { + subjects: thing_ids, + objects: channel_ids, + actions: actions, }; @@ -62,17 +386,36 @@ describe('Things', () => { data: JSON.stringify(thing), }); }); + expect(result).toEqual("Policy created."); + }); + }); + + test("Disconnect should disconnect things and return success", () => { + axios.request.mockResolvedValue("Policy deleted."); + + const expectedUrl = `${things_url}/disconnect`; + const payload = { subjects: thing_id, objects: channel_id }; + + const sdk = new mfsdk({ thingsUrl: things_url }); + return sdk.things.Disconnect(thing_id, channel_id, token).then((result) => { + expect(axios.request).toHaveBeenCalledWith({ + method: "post", + maxBodyLength: Infinity, + url: expectedUrl, + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, + }, + data: JSON.stringify(payload), + }); + expect(result).toEqual("Policy deleted."); }); + }); - test('Create should handle a conflict error', ()=>{ - const errorResponse = { - response: { - status: 401, - }, - }; - axios.request.mockRejectedValue(errorResponse); + test("Identify thing should identify a thing and return success", () => { + axios.request.mockResolvedValue({ data: thing }); - const expectedUrl = `${things_url}/things`; + const expectedUrl = `${things_url}/identify`; const sdk = new mfsdk({thingsUrl: things_url}); return sdk.things.Create(thing, token).catch(result => { diff --git a/tests/users.test.js b/tests/users.test.js index 2eafdc02..4b718266 100644 --- a/tests/users.test.js +++ b/tests/users.test.js @@ -1,56 +1,55 @@ -const axios = require('axios'); +const axios = require("axios"); const mfsdk = require("mainflux-sdk"); -jest.mock('axios'); +jest.mock("axios"); -describe('Users', () => { - const users_url = 'http://localhost'; +describe("Users", () => { + const users_url = "http://localhost"; const user = { - id: '886b4266-77d1-4258-abae-2931fb4f16de', - name: 'fkatwigs', - tags: ['holy', 'terrain'], - owner: 'natra@email.com', + id: "886b4266-77d1-4258-abae-2931fb4f16de", + name: "fkatwigs", + tags: ["holy", "terrain"], + owner: "natra@email.com", credentials: { - identity: 'fkatwigs@email.com', - secret: '12345678' + identity: "fkatwigs@email.com", + secret: "12345678", }, - created_at: '2023-09-07T13:17:27.880558Z', - updated_at: '2023-09-12T13:38:23.86436Z', - updated_by: 'a725e26d-dc1f-4452-80dc-41fc654aa38b', - status: 'enabled' + created_at: "2023-09-07T13:17:27.880558Z", + updated_at: "2023-09-12T13:38:23.86436Z", + updated_by: "a725e26d-dc1f-4452-80dc-41fc654aa38b", + status: "enabled", }; - const user_id = '886b4266-77d1-4258-abae-2931fb4f16de'; - const token = 'eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9'; - const old_secret = '12345678'; - const new_secret = '87654321'; + const user_id = "886b4266-77d1-4258-abae-2931fb4f16de"; + const token = "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9"; + const old_secret = "12345678"; + const new_secret = "87654321"; const payload = { old_secret: old_secret, - new_secret: new_secret + new_secret: new_secret, }; const access_request = { - "subject": user_id, - "object": '886b4266-77d1-4258-abae-2931fb4f16de', - "action": 'm_read', - "entity_type": 'client' - } - const group_id = '886b4266-77d1-4258-abae-2931fb4f16de'; - const action= 'm_read'; - const entity_type = 'client'; - + subject: user_id, + object: "886b4266-77d1-4258-abae-2931fb4f16de", + action: "m_read", + entity_type: "client", + }; + const group_id = "886b4266-77d1-4258-abae-2931fb4f16de"; + const action = "m_read"; + const entity_type = "client"; - test('Create should create a user and return success', () => { + test("Create should create a user and return success", () => { axios.request.mockResolvedValueOnce({ data: user }); const expectedUrl = `${users_url}/users`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.Create(user, token).then(result => { + return sdk.users.Create(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'post', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -59,7 +58,7 @@ describe('Users', () => { }); }); - test('Create should handle a conflict error', () => { + test("Create should handle a conflict error", () => { const errorResponse = { response: { status: 409, @@ -70,34 +69,36 @@ describe('Users', () => { const expectedUrl = `${users_url}/users`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.Create(user, token).catch(result => { + return sdk.users.Create(user, token).catch((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, - method: 'post', + method: "post", headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), }); expect(result.error.status).toBe(1); - expect(result.error.message).toBe('Failed due to using an existing identity.'); + expect(result.error.message).toBe( + "Failed due to using an existing identity.", + ); }); }); - test('Login should create a token for a user and return success', () => { + test("Login should create a token for a user and return success", () => { axios.request.mockResolvedValueOnce({ data: user }); const expectedUrl = `${users_url}/users/tokens/issue`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.Login(user).then(result => { + return sdk.users.Login(user).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'post', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json' + "Content-Type": "application/json", }, data: JSON.stringify(user), }); @@ -105,7 +106,7 @@ describe('Users', () => { }); }); - test('Login should handle a conflict error', () => { + test("Login should handle a conflict error", () => { const errorResponse = { response: { status: 401, @@ -116,13 +117,13 @@ describe('Users', () => { const expectedUrl = `${users_url}/users/tokens/issue`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.Login(user).then(result => { + return sdk.users.Login(user).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'post', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json' + "Content-Type": "application/json", }, data: JSON.stringify(user), }); @@ -130,19 +131,19 @@ describe('Users', () => { }); }); - test('Get should get a user and return success', () => { + test("Get should get a user and return success", () => { axios.request.mockResolvedValueOnce({ data: user }); const expectedUrl = `${users_url}/users/${user_id}`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.Get(user_id, token).then(result => { + return sdk.users.Get(user_id, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'get', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, }); @@ -150,7 +151,7 @@ describe('Users', () => { }); }); - test('Get should handle a conflict error', () => { + test("Get should handle a conflict error", () => { const errorResponse = { response: { status: 401, @@ -161,33 +162,33 @@ describe('Users', () => { const expectedUrl = `${users_url}/users/${user_id}`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.Get(user_id, token).then(result => { + return sdk.users.Get(user_id, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'get', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', - Authorization: `Bearer ${token}` + "Content-Type": "application/json", + Authorization: `Bearer ${token}`, }, }); console.log(result); }); }); - test('Update should update a user and return success', () => { + test("Update should update a user and return success", () => { axios.request.mockResolvedValueOnce({ data: user }); const expectedUrl = `${users_url}/users/${user_id}`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.Update(user, token).then(result => { + return sdk.users.Update(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'patch', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -196,7 +197,7 @@ describe('Users', () => { }); }); - test('Update should handle a conflict error', () => { + test("Update should handle a conflict error", () => { const errorResponse = { response: { status: 401, @@ -207,13 +208,13 @@ describe('Users', () => { const expectedUrl = `${users_url}/users/${user_id}`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.Update(user, token).then(result => { + return sdk.users.Update(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'patch', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -222,19 +223,19 @@ describe('Users', () => { }); }); - test('UpdateUserIdentity should update a user identity and return success', () => { + test("UpdateUserIdentity should update a user identity and return success", () => { axios.request.mockResolvedValueOnce({ data: user }); const expectedUrl = `${users_url}/users/${user_id}/identity`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.UpdateUserIdentity(user, token).then(result => { + return sdk.users.UpdateUserIdentity(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'patch', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -243,7 +244,7 @@ describe('Users', () => { }); }); - test('UpdateUserIdentity should should handle a conflict error', () => { + test("UpdateUserIdentity should should handle a conflict error", () => { const errorResponse = { response: { status: 401, @@ -254,13 +255,13 @@ describe('Users', () => { const expectedUrl = `${users_url}/users/${user_id}/identity`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.UpdateUserIdentity(user, token).then(result => { + return sdk.users.UpdateUserIdentity(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'patch', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -269,19 +270,19 @@ describe('Users', () => { }); }); - test('UpdateUserTags should update a users tags and return success', () => { + test("UpdateUserTags should update a users tags and return success", () => { axios.request.mockResolvedValueOnce({ data: user }); const expectedUrl = `${users_url}/users/${user_id}/tags`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.UpdateUserTags(user, token).then(result => { + return sdk.users.UpdateUserTags(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'patch', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -290,7 +291,7 @@ describe('Users', () => { }); }); - test('UpdateUserTags should handle a conflict error', () => { + test("UpdateUserTags should handle a conflict error", () => { const errorResponse = { response: { status: 401, @@ -301,13 +302,13 @@ describe('Users', () => { const expectedUrl = `${users_url}/users/${user_id}/tags`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.UpdateUserTags(user, token).then(result => { + return sdk.users.UpdateUserTags(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'patch', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -316,19 +317,19 @@ describe('Users', () => { }); }); - test('UpdateUserOwner should update a user owner and return success', () => { + test("UpdateUserOwner should update a user owner and return success", () => { axios.request.mockResolvedValueOnce({ data: user }); const expectedUrl = `${users_url}/users/${user_id}/owner`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.UpdateUserOwner(user, token).then(result => { + return sdk.users.UpdateUserOwner(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'patch', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -337,7 +338,7 @@ describe('Users', () => { }); }); - test('UpdateUserOwner should handle a conflict error', () => { + test("UpdateUserOwner should handle a conflict error", () => { const errorResponse = { response: { status: 401, @@ -348,13 +349,13 @@ describe('Users', () => { const expectedUrl = `${users_url}/users/${user_id}/owner`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.UpdateUserOwner(user, token).then(result => { + return sdk.users.UpdateUserOwner(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'patch', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -363,7 +364,7 @@ describe('Users', () => { }); }); - test('UpdateUserPassword should update a user password and return success', () => { + test("UpdateUserPassword should update a user password and return success", () => { axios.request.mockResolvedValueOnce({ data: user }); const expectedUrl = `${users_url}/users/secret`; @@ -371,7 +372,7 @@ describe('Users', () => { const sdk = new mfsdk({ usersUrl: users_url }); const secret = { old_secret: old_secret, - new_secret: new_secret + new_secret: new_secret, }; return sdk.users.UpdateUserPassword(old_secret, new_secret, token).then(result => { expect(axios.request).toHaveBeenCalledWith({ @@ -384,11 +385,9 @@ describe('Users', () => { }, data: JSON.stringify(secret), }); - expect(result).toEqual(user); - }); }); - test('UpdateUserPassword should handle a conflict error', () => { + test("UpdateUserPassword should handle a conflict error", () => { const errorResponse = { response: { status: 401, @@ -399,7 +398,7 @@ describe('Users', () => { const expectedUrl = `${users_url}/users/secret`; const secret = { old_secret: old_secret, - new_secret: new_secret + new_secret: new_secret, }; const sdk = new mfsdk({ usersUrl: users_url }); return sdk.users.UpdateUserPassword(old_secret, new_secret, token).then(result => { @@ -413,23 +412,21 @@ describe('Users', () => { }, data: JSON.stringify(secret), }); - console.log(user); - }); }); - test('Disable should disable user and return success', () => { + test("Disable should disable user and return success", () => { axios.request.mockResolvedValueOnce({ data: user }); const expectedUrl = `${users_url}/users/${user_id}/disable`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.Disable(user, token).then(result => { + return sdk.users.Disable(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'post', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -438,7 +435,7 @@ describe('Users', () => { }); }); - test('Disable should handle a conflict error', () => { + test("Disable should handle a conflict error", () => { const errorResponse = { response: { status: 401, @@ -449,13 +446,13 @@ describe('Users', () => { const expectedUrl = `${users_url}/users/${user_id}/disable`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.Disable(user, token).then(result => { + return sdk.users.Disable(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'post', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -464,19 +461,19 @@ describe('Users', () => { }); }); - test('Enable should enable user and return success', () => { + test("Enable should enable user and return success", () => { axios.request.mockResolvedValueOnce({ data: user }); const expectedUrl = `${users_url}/users/${user_id}/enable`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.Enable(user, token).then(result => { + return sdk.users.Enable(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'post', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -485,7 +482,7 @@ describe('Users', () => { }); }); - test('Enable should handle a conflict error', () => { + test("Enable should handle a conflict error", () => { const errorResponse = { response: { status: 401, @@ -496,13 +493,13 @@ describe('Users', () => { const expectedUrl = `${users_url}/users/${user_id}/enable`; const sdk = new mfsdk({ usersUrl: users_url }); - return sdk.users.Enable(user, token).then(result => { + return sdk.users.Enable(user, token).then((result) => { expect(axios.request).toHaveBeenCalledWith({ url: expectedUrl, method: 'post', maxBodyLength: 2000, headers: { - 'Content-Type': 'application/json', + "Content-Type": "application/json", Authorization: `Bearer ${token}`, }, data: JSON.stringify(user), @@ -511,7 +508,7 @@ describe('Users', () => { }); }); - test('Authorise User should authorise a user and return success', () => { + test("Authorise User should authorise a user and return success", () => { axios.request.mockResolvedValueOnce({ data: true }); const expectedUrl = `${users_url}/authorize`; @@ -534,11 +531,9 @@ describe('Users', () => { }, data: JSON.stringify(access_request), }); - expect(result).toEqual(true); - }); }); - test('Authorise User should handle a conflict error', () => { + test("Authorise User should handle a conflict error", () => { const errorResponse = { response: { status: 401, @@ -548,11 +543,11 @@ describe('Users', () => { const expectedUrl = `${users_url}/authorize`; const access_request = { - "subject": user_id, - "object": group_id, - "action": action, - "entity_type": entity_type - } + subject: user_id, + object: group_id, + action: action, + entity_type: entity_type, + }; const sdk = new mfsdk({ usersUrl: users_url }); return sdk.users.AuthoriseUser(user_id, group_id, action, entity_type, token).then(result => { expect(axios.request).toHaveBeenCalledWith({ @@ -565,8 +560,5 @@ describe('Users', () => { }, data: JSON.stringify(access_request), }); - console.log(result); - }); }); - });