Skip to content
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
2 changes: 1 addition & 1 deletion npmDepsHash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sha256-pckkN6xZ+tj+srTB5iHCwuHb3EFv0KiTPvFIGTTy1nQ=
sha256-z97XzEPI3Dwl+Ld26FdKVzkstLbTWRgLiKVT8Dh1uZY=
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"nexpect": "^0.6.0",
"node-gyp-build": "^4.4.0",
"nodemon": "^3.0.1",
"polykey": "^1.2.3",
"polykey": "^1.4.0",
"prettier": "^3.0.0",
"shelljs": "^0.8.5",
"shx": "^0.3.4",
Expand Down
8 changes: 4 additions & 4 deletions src/notifications/CommandNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import CommandClear from './CommandClear';
import CommandRead from './CommandRead';
import CommandInbox from './inbox';
import CommandOutbox from './outbox';
import CommandSend from './CommandSend';
import CommandPolykey from '../CommandPolykey';

Expand All @@ -8,8 +8,8 @@ class CommandNotifications extends CommandPolykey {
super(...args);
this.name('notifications');
this.description('Notifications Operations');
this.addCommand(new CommandClear(...args));
this.addCommand(new CommandRead(...args));
this.addCommand(new CommandInbox(...args));
this.addCommand(new CommandOutbox(...args));
this.addCommand(new CommandSend(...args));
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/notifications/CommandSend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class CommandSend extends CommandPolykey {
binParsers.parseNodeId,
);
this.argument('<message>', 'Message to send');
this.option(
'-r, --retries [number]',
'(optional) Number of retries that should be attempted before giving up',
);
this.addOption(binOptions.nodeId);
this.addOption(binOptions.clientHost);
this.addOption(binOptions.clientPort);
Expand Down Expand Up @@ -52,12 +56,14 @@ class CommandSend extends CommandPolykey {
},
logger: this.logger.getChild(PolykeyClient.name),
});
const retries = parseInt(options.retries);
await binUtils.retryAuthentication(
(auth) =>
pkClient.rpcClient.methods.notificationsSend({
metadata: auth,
nodeIdEncoded: nodesUtils.encodeNodeId(nodeId),
message: message,
retries: Number.isNaN(retries) ? undefined : retries,
}),
auth,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type PolykeyClient from 'polykey/dist/PolykeyClient';
import CommandPolykey from '../CommandPolykey';
import * as binUtils from '../utils';
import * as binOptions from '../utils/options';
import * as binProcessors from '../utils/processors';
import CommandPolykey from '../../CommandPolykey';
import * as binUtils from '../../utils';
import * as binOptions from '../../utils/options';
import * as binProcessors from '../../utils/processors';

class CommandClear extends CommandPolykey {
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
super(...args);
this.name('clear');
this.description('Clear all Notifications');
this.description('Clear Inbox Notifications');
this.addOption(binOptions.nodeId);
this.addOption(binOptions.clientHost);
this.addOption(binOptions.clientPort);
Expand Down Expand Up @@ -45,7 +45,7 @@ class CommandClear extends CommandPolykey {
});
await binUtils.retryAuthentication(
(auth) =>
pkClient.rpcClient.methods.notificationsClear({
pkClient.rpcClient.methods.notificationsInboxClear({
metadata: auth,
}),
auth,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import type { Notification } from 'polykey/dist/notifications/types';
import type PolykeyClient from 'polykey/dist/PolykeyClient';
import CommandPolykey from '../CommandPolykey';
import * as binUtils from '../utils';
import * as binOptions from '../utils/options';
import * as binProcessors from '../utils/processors';
import CommandPolykey from '../../CommandPolykey';
import * as binUtils from '../../utils';
import * as binOptions from '../../utils/options';
import * as binProcessors from '../../utils/processors';

class CommandRead extends CommandPolykey {
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
super(...args);
this.name('read');
this.description('Display Notifications');
this.description('Display Inbox Notifications');
this.option(
'-u, --unread',
'(optional) Flag to only display unread notifications',
);
this.option(
'-n, --number [number]',
'-l, --limit [number]',
'(optional) Number of notifications to read',
'all',
);
this.option(
'-o, --order [order]',
Expand Down Expand Up @@ -63,14 +62,13 @@ class CommandRead extends CommandPolykey {
});
const notificationReadMessages = await binUtils.retryAuthentication(
async (auth) => {
const response = await pkClient.rpcClient.methods.notificationsRead(
{
const response =
await pkClient.rpcClient.methods.notificationsInboxRead({
metadata: auth,
unread: options.unread,
number: options.number,
order: options.order,
},
);
limit: parseInt(options.limit),
order: options.order === 'newest' ? 'desc' : 'asc',
});
const notificationReadMessages: Array<{
notification: Notification;
}> = [];
Expand Down
69 changes: 69 additions & 0 deletions src/notifications/inbox/CommandRemove.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import type PolykeyClient from 'polykey/dist/PolykeyClient';
import * as notificationsUtils from 'polykey/dist/notifications/utils';
import CommandPolykey from '../../CommandPolykey';
import * as binUtils from '../../utils';
import * as binOptions from '../../utils/options';
import * as binProcessors from '../../utils/processors';
import * as binParsers from '../../utils/parsers';

class CommandRemove extends CommandPolykey {
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
super(...args);
this.name('remove');
this.description('Remove a Notification in the Inbox');
this.argument(
'<notificationId>',
'Id of the notification to remove',
binParsers.parseNotificationId,
);
this.addOption(binOptions.nodeId);
this.addOption(binOptions.clientHost);
this.addOption(binOptions.clientPort);
this.action(async (notificationId, options) => {
const { default: PolykeyClient } = await import(
'polykey/dist/PolykeyClient'
);
const clientOptions = await binProcessors.processClientOptions(
options.nodePath,
options.nodeId,
options.clientHost,
options.clientPort,
this.fs,
this.logger.getChild(binProcessors.processClientOptions.name),
);
const auth = await binProcessors.processAuthentication(
options.passwordFile,
this.fs,
);

let pkClient: PolykeyClient;
this.exitHandlers.handlers.push(async () => {
if (pkClient != null) await pkClient.stop();
});
try {
pkClient = await PolykeyClient.createPolykeyClient({
nodeId: clientOptions.nodeId,
host: clientOptions.clientHost,
port: clientOptions.clientPort,
options: {
nodePath: options.nodePath,
},
logger: this.logger.getChild(PolykeyClient.name),
});
await binUtils.retryAuthentication(
(auth) =>
pkClient.rpcClient.methods.notificationsInboxRemove({
notificationIdEncoded:
notificationsUtils.encodeNotificationId(notificationId),
metadata: auth,
}),
auth,
);
} finally {
if (pkClient! != null) await pkClient.stop();
}
});
}
}

export default CommandRemove;
17 changes: 17 additions & 0 deletions src/notifications/inbox/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import CommandClear from './CommandClear';
import CommandRead from './CommandRead';
import CommandRemove from './CommandRemove';
import CommandPolykey from '../../CommandPolykey';

class CommandInbox extends CommandPolykey {
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
super(...args);
this.name('inbox');
this.description('Notifications Inbox Operations');
this.addCommand(new CommandClear(...args));
this.addCommand(new CommandRead(...args));
this.addCommand(new CommandRemove(...args));
}
}

export default CommandInbox;
60 changes: 60 additions & 0 deletions src/notifications/outbox/CommandClear.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type PolykeyClient from 'polykey/dist/PolykeyClient';
import CommandPolykey from '../../CommandPolykey';
import * as binUtils from '../../utils';
import * as binOptions from '../../utils/options';
import * as binProcessors from '../../utils/processors';

class CommandClear extends CommandPolykey {
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
super(...args);
this.name('clear');
this.description('Clear Outbox Notifications');
this.addOption(binOptions.nodeId);
this.addOption(binOptions.clientHost);
this.addOption(binOptions.clientPort);
this.action(async (options) => {
const { default: PolykeyClient } = await import(
'polykey/dist/PolykeyClient'
);
const clientOptions = await binProcessors.processClientOptions(
options.nodePath,
options.nodeId,
options.clientHost,
options.clientPort,
this.fs,
this.logger.getChild(binProcessors.processClientOptions.name),
);
const auth = await binProcessors.processAuthentication(
options.passwordFile,
this.fs,
);

let pkClient: PolykeyClient;
this.exitHandlers.handlers.push(async () => {
if (pkClient != null) await pkClient.stop();
});
try {
pkClient = await PolykeyClient.createPolykeyClient({
nodeId: clientOptions.nodeId,
host: clientOptions.clientHost,
port: clientOptions.clientPort,
options: {
nodePath: options.nodePath,
},
logger: this.logger.getChild(PolykeyClient.name),
});
await binUtils.retryAuthentication(
(auth) =>
pkClient.rpcClient.methods.notificationsOutboxClear({
metadata: auth,
}),
auth,
);
} finally {
if (pkClient! != null) await pkClient.stop();
}
});
}
}

export default CommandClear;
Loading