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-95 - Update channels service to match new access control #100

Merged
merged 9 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nine-lizards-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@absmach/magistrala-sdk": patch
---

update channels to match new access control
1 change: 1 addition & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ user_token = ""
things_url = "http://localhost:9000"
tls_verification = false
users_url = "http://localhost:9002"
channels_url = "http://localhost:9005"
168 changes: 46 additions & 122 deletions examples/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import SDK from "../src/sdk";
const defaultUrl = "http://localhost";

const mySdk = new SDK({
thingsUrl: `${defaultUrl}:9000`,
usersUrl: `${defaultUrl}:9002`,
channelsUrl: `${defaultUrl}:9005`,
});

// Channels.ts examples.
Expand All @@ -19,229 +18,154 @@ mySdk.channels
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

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

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

mySdk.channels
.UpdateChannel(
{ id: "<channelId>", name: "<channelName>" },
domainId,
token,
)
.CreateChannels([{ name: "<channelName1>" }, { name: "<channelName2>" }], domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.Disable("<channelId>", domainId, token)
.Channels({ offset: 0, limit: 10 }, domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

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

mySdk.channels
.ChannelsByThing(
"<thingId>",
{ offset: 0, limit: 5 },
.UpdateChannelNameAndMetadata(
{ id: "<channelId>", name: "<channelName>", metadata: { key: "value" } },
domainId,
token,
token
)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.ConnectThing(
"<thingId>",
"<channelId>",
.UpdateChannelTags(
{ id: "<channelId>", tags: ["tag1", "tag2"] },
domainId,
token,
token
)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
});

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

mySdk.channels
.Connect(
"<thingId>",
"<channelId>",
domainId,
token,
)
.DisableChannel("<channelId>", domainId, token)
.then((response: any) => {
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.Disconnect(
"<thingId>",
"<channelId>",
domainId,
token,
)
.EnableChannel("<channelId>", domainId, token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.ListChannelUsers(
.ConnectClient(
["<clientId1>", "<clientId2>"],
"<channelId>",
{ offset: 0, limit: 5 },
["publish"],
domainId,
token,
)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error: any) => {
console.log(error);
.catch((error) => {
console.error(error);
});

mySdk.channels
.ListChannelUserGroups(
.DisconnectClient(
["<clientId1>", "<clientId2>"],
"<channelId>",
{ offset: 0, limit: 5 },
["publish"],
domainId,
token,
)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error: any) => {
console.log(error);
});

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

mySdk.channels
.AddUserToChannel(
"<channelId>",
[
"<userId1>", "<userId2>",
],
"administrator",
.Connect(
["<clientId1>", "<clientId2>"],
["<channelId1>", "<channelId1>"],
["publish"],
domainId,
token,
)
.then((response: any) => {
console.log("response: ", response);
console.log("response:", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.RemoveUserFromChannel(
"<channelId>",
[
"<userId1>", "<userId2>",
],
"administrator",
.Disconnect(
["<clientId1>", "<clientId2>"],
["<channelId1>", "<channelId1>"],
["publish"],
domainId,
token,
)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.AddUserGroupToChannel(
"<channelId>",
[
"<UserGroupId1>", "<UserGroupId2>",
],
domainId,
token,
)
mySdk.channels.ChannelParents(domainId, "<channelId>", "<groupParentId>", token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
.RemoveUserGroupFromChannel(
"<channelId>",
[
"<UserGroupId1>", "<UserGroupId2>",
],
domainId,
token,
)
mySdk.channels.DeleteChannelParents(domainId, "<channelId>", token)
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

mySdk.channels
Expand All @@ -254,5 +178,5 @@ mySdk.channels
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});
26 changes: 18 additions & 8 deletions examples/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const defaultUrl = "http://localhost";
const mySdk = new SDK({
usersUrl: `${defaultUrl}:9002`,
thingsUrl: `${defaultUrl}:9000`,
channelsUrl: `${defaultUrl}:9005`,
invitationsUrl: `${defaultUrl}:9020`,
journalUrl: `${defaultUrl}:9021`,
httpAdapterUrl: `${defaultUrl}:8008`,
Expand All @@ -20,7 +21,7 @@ mySdk.Health.Health("things")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Users service Health
Expand All @@ -29,7 +30,16 @@ mySdk.Health.Health("users")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Channels service Health
mySdk.Health.Health("channels")
.then((response: any) => {
console.log("response: ", response);
})
.catch((error) => {
console.error(error);
});

// Bootstrap service Health
Expand All @@ -38,7 +48,7 @@ mySdk.Health.Health("bootstrap")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Certs service Health
Expand All @@ -47,7 +57,7 @@ mySdk.Health.Health("certs")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Reader service Health
Expand All @@ -56,7 +66,7 @@ mySdk.Health.Health("reader")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Http Adapter service Health
Expand All @@ -65,7 +75,7 @@ mySdk.Health.Health("http-adapter")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Journal service Health
Expand All @@ -74,7 +84,7 @@ mySdk.Health.Health("journal")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});

// Invitations service Health
Expand All @@ -83,5 +93,5 @@ mySdk.Health.Health("invitations")
console.log("response: ", response);
})
.catch((error) => {
console.log(error);
console.error(error);
});
Loading
Loading