Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

JSSDK-97 - Update clients to match new access control #103

Merged
merged 12 commits into from
Nov 25, 2024
5 changes: 5 additions & 0 deletions .changeset/shy-goats-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@absmach/magistrala-sdk": patch
---

Update clients service to match new auth
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ user_token = ""
certs_url = "http://localhost:9019"
http_adapter_url = "http://localhost/http:9016"
reader_url = "http://localhost:9011"
things_url = "http://localhost:9000"
clients_url = "http://localhost:9006"
tls_verification = false
users_url = "http://localhost:9002"
channels_url = "http://localhost:9005"
7 changes: 2 additions & 5 deletions examples/channels.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Import the SDK class from the mainflux-sdk package
import SDK from "../src/sdk";

const defaultUrl = "http://localhost";
Expand All @@ -7,8 +6,6 @@ const mySdk = new SDK({
channelsUrl: `${defaultUrl}:9005`,
});

// Channels.ts examples.

const token = "<token>";
const domainId = "<domainId>";

Expand Down Expand Up @@ -152,15 +149,15 @@ mySdk.channels
console.error(error);
});

mySdk.channels.ChannelParents(domainId, "<channelId>", "<groupParentId>", token)
mySdk.channels.SetChannelParentGroup(domainId, "<channelId>", "<parentGroupId>", token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.channels.DeleteChannelParents(domainId, "<channelId>", token)
mySdk.channels.DeleteChannelParentGroup(domainId, "<channelId>", token)
.then((response: any) => {
console.log("response: ", response);
})
Expand Down
35 changes: 0 additions & 35 deletions examples/client/listThings.html

This file was deleted.

290 changes: 290 additions & 0 deletions examples/clients.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,290 @@
import SDK from "../src/sdk";

const defaultUrl = "http://localhost";

const mySdk = new SDK({
clientsUrl: `${defaultUrl}:9006`,
});

const token = "<token>";
const domainId = "<domainId>";

mySdk.clients
.CreateClient({ name: "<clientName>" }, domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.Disable("<clientId>", domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.Enable("<clientId>", domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.UpdateClient({ id: "<clientId>", name: "<clientName>" }, domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.UpdateClientSecret({ id: "<clientId>", credentials: { secret: "newSecret" } }, domainId, token)
.then((response: any) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.UpdateClientTags(
{ id: "<clientId>", tags: ["<tag1>", "<tag2>"] },
domainId,
token,
)
.then((response: any) => {
console.log(response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.Clients({ offset: 0, limit: 10 }, domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.Client("<clientId>", domainId, token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.DeleteClient("<clientId>", domainId, token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.ListUserClients(
"<userId>",
{ offset: 0, limit: 10 },
domainId,
token,
)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.log(error);
});

mySdk.clients.setClientParentGroup(domainId, "<clientId>", "<parentGroupId>", token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients.DeleteClientParentGroup(domainId, "<clientId>", token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.CreateClients([{ name: "<clientName1>" }, { name: "<clientName2>" }], domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.ListClientActions(domainId, token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.CreateClientRole("<clientId>", "<roleName>", domainId, token)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.ListClientRoles("<clientId>", domainId, { offset: 0, limit: 10 }, token)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.ViewClientRole("<clientId>", domainId, "<roleName>", token)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.UpdateClientRole(
"<clientId>",
domainId,
"<roleName>",
{ name: "<updatedRoleName>" },
token
)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.DeleteClientRole("<clientId>", domainId, "<roleName>", token)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.AddClientRoleActions(
"<clientId>",
domainId,
"<roleName>",
["<action>", "<action>"],
token
)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.ListClientRoleActions("<clientId>", domainId, "<roleName>", token)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.DeleteClientRoleActions(
"<clientId>",
domainId,
"<roleName>",
["<action>", "<action>"],
token
)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.DeleteAllClientRoleActions("<clientId>", domainId, "<roleName>", token)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.AddClientRoleMembers("<clientId>", domainId, "<roleName>", ["<userId>", "<userId>"], token)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.ListClientRoleMembers(
"<clientId>",
domainId,
"<roleName>",
{ offset: 0, limit: 10 },
token
)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.DeleteClientRoleMembers(
"<clientId>",
domainId,
"<roleName>",
["<userId>", "<userId>"],
token,
)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

mySdk.clients
.DeleteAllClientRoleMembers("<clientId>", domainId, "<roleName>", token)
.then((response) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});
6 changes: 3 additions & 3 deletions examples/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const defaultUrl = "http://localhost";

const mySdk = new SDK({
usersUrl: `${defaultUrl}:9002`,
thingsUrl: `${defaultUrl}:9000`,
clientsUrl: `${defaultUrl}:9006`,
channelsUrl: `${defaultUrl}:9005`,
invitationsUrl: `${defaultUrl}:9020`,
journalUrl: `${defaultUrl}:9021`,
Expand All @@ -15,8 +15,8 @@ const mySdk = new SDK({
bootstrapUrl: `${defaultUrl}:9013`,
});

// Things service Health
mySdk.Health.Health("things")
// Clients service Health
mySdk.Health.Health("clients")
.then((response: any) => {
console.log("response: ", response);
})
Expand Down
Loading
Loading